mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-20 16:54:25 +00:00
Fix x264 build trash (#282)
* Check x264 lib version with some conditional hacks for versions < 159
This commit is contained in:
parent
98ca6e7ace
commit
4c883cf8e4
3 changed files with 49 additions and 8 deletions
|
|
@ -5,6 +5,7 @@ import "C"
|
|||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
|
||||
x264 "github.com/sergystepanov/x264-go/v2/x264c/external"
|
||||
)
|
||||
|
|
@ -25,6 +26,12 @@ type H264 struct {
|
|||
}
|
||||
|
||||
func NewH264Encoder(w io.Writer, width, height int, options ...Option) (encoder *H264, err error) {
|
||||
libVersion := int(x264.Build)
|
||||
|
||||
if libVersion < 150 {
|
||||
return nil, fmt.Errorf("x264: the library version should be newer than v150, you have got version %v", libVersion)
|
||||
}
|
||||
|
||||
opts := &Options{
|
||||
Crf: 12,
|
||||
Tune: "zerolatency",
|
||||
|
|
@ -36,6 +43,10 @@ func NewH264Encoder(w io.Writer, width, height int, options ...Option) (encoder
|
|||
opt(opts)
|
||||
}
|
||||
|
||||
if opts.LogLevel > 0 {
|
||||
log.Printf("x264: build v%v", x264.Build)
|
||||
}
|
||||
|
||||
param := x264.Param{}
|
||||
if opts.Preset != "" && opts.Tune != "" {
|
||||
if x264.ParamDefaultPreset(¶m, opts.Preset, opts.Tune) < 0 {
|
||||
|
|
@ -53,7 +64,12 @@ func NewH264Encoder(w io.Writer, width, height int, options ...Option) (encoder
|
|||
|
||||
// legacy encoder lacks of this param
|
||||
param.IBitdepth = 8
|
||||
param.ICsp = x264.CspI420
|
||||
|
||||
if libVersion > 155 {
|
||||
param.ICsp = x264.CspI420
|
||||
} else {
|
||||
param.ICsp = 1
|
||||
}
|
||||
param.IWidth = int32(width)
|
||||
param.IHeight = int32(height)
|
||||
param.ILogLevel = opts.LogLevel
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue