Fix x264 build trash (#282)

* Check x264 lib version with some conditional hacks for versions < 159
This commit is contained in:
sergystepanov 2021-02-21 21:41:10 +03:00 committed by Sergey Stepanov
parent 98ca6e7ace
commit 4c883cf8e4
No known key found for this signature in database
GPG key ID: A56B4929BAA8556B
3 changed files with 49 additions and 8 deletions

View file

@ -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(&param, 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