Skip to content

Commit

Permalink
add bframe setting in preset (#293)
Browse files Browse the repository at this point in the history
* add bframe setting in preset
  • Loading branch information
adamthesax authored Dec 4, 2019
1 parent cc943f9 commit af92630
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 19 deletions.
1 change: 1 addition & 0 deletions db/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ type VideoPreset struct {
GopSize string `json:"gopSize,omitempty" redis-hash:"gopsize,omitempty"`
GopMode string `json:"gopMode,omitempty" redis-hash:"gopmode,omitempty"`
InterlaceMode string `json:"interlaceMode,omitempty" redis-hash:"interlacemode,omitempty"`
BFrames string `json:"bframes,omitempty" redis-hash:"bframes,omitempty"`
}

// AudioPreset defines the set of parameters for audio on a given preset
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/onsi/gomega v1.5.0 // indirect
github.com/pkg/errors v0.8.1
github.com/sirupsen/logrus v1.4.2
github.com/video-dev/go-elementalconductor v1.0.0
github.com/video-dev/go-elementalconductor v1.1.0
github.com/video-dev/go-encodingcom v1.0.0
github.com/video-dev/zencoder v0.0.0-20161215190743-745874544382
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ github.com/tinylib/msgp v1.1.0 h1:9fQd+ICuRIu/ue4vxJZu6/LzxN0HwMds2nq/0cFvxHU=
github.com/tinylib/msgp v1.1.0/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE=
github.com/video-dev/go-elementalconductor v1.0.0 h1:vnWf1sAXgdTKhsHhAWOwKMBCPA+p0Rr8+ZotVUEes/4=
github.com/video-dev/go-elementalconductor v1.0.0/go.mod h1:DwQxx5JUDRY0+/6OcAROOaOEUW6/FnOCDBkTVnWuJTM=
github.com/video-dev/go-elementalconductor v1.1.0 h1:T+voFHpYQKrjH+72KywQO7v+qnzcFYD+YZFpRCLQYUU=
github.com/video-dev/go-elementalconductor v1.1.0/go.mod h1:DwQxx5JUDRY0+/6OcAROOaOEUW6/FnOCDBkTVnWuJTM=
github.com/video-dev/go-encodingcom v1.0.0 h1:OiVfdy9qUrKGfOID5TYwoBzvObNx9EQNI041ZA0kZ38=
github.com/video-dev/go-encodingcom v1.0.0/go.mod h1:7O86jGr922w65EzPw83u2w36Mm+S90zdy4stfYFxelg=
github.com/video-dev/zencoder v0.0.0-20161215190743-745874544382 h1:n83HJM7e1ECRGC6Q9Wb28Jmh/GwT973/r7x71QGyJrc=
Expand Down
7 changes: 7 additions & 0 deletions internal/provider/bitmovin/bitmovin.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,13 @@ func (p *bitmovinProvider) createH264VideoPreset(preset db.Preset, customData ma
}
h264.MaxGOP = intToPtr(int64(gopSize))
}
if preset.Video.BFrames != "" {
bFrames, err := strconv.Atoi(preset.Video.BFrames)
if err != nil {
return nil, err
}
h264.BFrames = intToPtr(int64(bFrames))
}

return h264, nil
}
Expand Down
4 changes: 4 additions & 0 deletions internal/provider/elementalconductor/elementalconductor.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ func (p *elementalConductorProvider) CreatePreset(preset db.Preset) (string, err
elementalConductorPreset.AudioCodec = preset.Audio.Codec
elementalConductorPreset.AudioBitrate = preset.Audio.Bitrate

if preset.Video.BFrames != "" {
elementalConductorPreset.GopNumBFrames = preset.Video.BFrames
}

result, err := p.client.CreatePreset(&elementalConductorPreset)
if err != nil {
return "", err
Expand Down
21 changes: 18 additions & 3 deletions internal/provider/encodingcom/encodingcom.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ func (e *encodingComProvider) Transcode(job *db.Job) (*provider.JobStatus, error
}

func (e *encodingComProvider) CreatePreset(preset db.Preset) (string, error) {
resp, err := e.client.SavePreset(preset.Name, e.presetToFormat(preset))
format, err := e.presetToFormat(preset)
if err != nil {
return "", err
}

resp, err := e.client.SavePreset(preset.Name, format)
if err != nil {
return "", err
}
Expand All @@ -91,7 +96,7 @@ func (e *encodingComProvider) sourceMedia(original string) string {
return original
}

func (e *encodingComProvider) presetToFormat(preset db.Preset) encodingcom.Format {
func (e *encodingComProvider) presetToFormat(preset db.Preset) (encodingcom.Format, error) {
falseYesNoBoolean := encodingcom.YesNoBoolean(false)
format := encodingcom.Format{
Output: []string{preset.Container},
Expand All @@ -112,8 +117,18 @@ func (e *encodingComProvider) presetToFormat(preset db.Preset) encodingcom.Forma
format.AudioCodec = e.getNormalizedCodec(preset.Audio.Codec)
format.VideoCodec = e.getNormalizedCodec(preset.Video.Codec)
format.Size = e.getSize(preset.Video.Width, preset.Video.Height)

if preset.Video.BFrames != "" {
bframes, err := strconv.Atoi(preset.Video.BFrames)
if err != nil {
return format, err
}

format.Bframes = bframes
}
}
return format

return format, nil
}

func (e *encodingComProvider) buildStream(preset db.Preset) []encodingcom.Stream {
Expand Down
7 changes: 6 additions & 1 deletion internal/provider/encodingcom/encodingcom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,12 @@ func TestPresetToFormat(t *testing.T) {
}
var p encodingComProvider
for _, test := range tests {
resultingFormat := p.presetToFormat(test.givenPreset)
resultingFormat, err := p.presetToFormat(test.givenPreset)

if err != nil {
t.Fatalf("Failed to convert preset to format: %#v", test.givenPreset)
}

if !reflect.DeepEqual(resultingFormat, test.expectedFormat) {
t.Errorf("%s: presetToFormat: wrong value. Want %#v. Got %#v", test.givenTestCase, test.expectedFormat, resultingFormat)
pretty.Fdiff(os.Stderr, resultingFormat, test.expectedFormat)
Expand Down
16 changes: 9 additions & 7 deletions internal/provider/mediaconvert/mediaconvert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var (
Bitrate: "400000",
GopSize: "120",
InterlaceMode: "progressive",
BFrames: "3",
},
Audio: db.AudioPreset{
Codec: "aac",
Expand Down Expand Up @@ -92,13 +93,14 @@ func Test_mcProvider_CreatePreset(t *testing.T) {
CodecSettings: &mediaconvert.VideoCodecSettings{
Codec: mediaconvert.VideoCodecH264,
H264Settings: &mediaconvert.H264Settings{
Bitrate: aws.Int64(400000),
CodecLevel: mediaconvert.H264CodecLevelLevel41,
CodecProfile: mediaconvert.H264CodecProfileHigh,
InterlaceMode: mediaconvert.H264InterlaceModeProgressive,
QualityTuningLevel: mediaconvert.H264QualityTuningLevelMultiPassHq,
RateControlMode: mediaconvert.H264RateControlModeVbr,
GopSize: aws.Float64(120),
Bitrate: aws.Int64(400000),
CodecLevel: mediaconvert.H264CodecLevelLevel41,
CodecProfile: mediaconvert.H264CodecProfileHigh,
InterlaceMode: mediaconvert.H264InterlaceModeProgressive,
QualityTuningLevel: mediaconvert.H264QualityTuningLevelMultiPassHq,
RateControlMode: mediaconvert.H264RateControlModeVbr,
GopSize: aws.Float64(120),
NumberBFramesBetweenReferenceFrames: aws.Int64(3),
},
},
},
Expand Down
25 changes: 18 additions & 7 deletions internal/provider/mediaconvert/preset_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,27 @@ func videoPresetFrom(preset db.Preset) (*mediaconvert.VideoDescription, error) {
tuning = mediaconvert.H264QualityTuningLevelMultiPassHq
}

var bframes *int64
if preset.Video.BFrames != "" {
b, err := strconv.ParseInt(preset.Video.BFrames, 10, 64)

if err != nil {
return nil, errors.Wrapf(err, "parsing bframes %q to int64", preset.Video.BFrames)
}
bframes = &b
}

videoPreset.CodecSettings = &mediaconvert.VideoCodecSettings{
Codec: mediaconvert.VideoCodecH264,
H264Settings: &mediaconvert.H264Settings{
Bitrate: aws.Int64(bitrate),
GopSize: aws.Float64(gopSize),
RateControlMode: rateControl,
CodecProfile: profile,
CodecLevel: level,
InterlaceMode: interlaceMode,
QualityTuningLevel: tuning,
Bitrate: aws.Int64(bitrate),
GopSize: aws.Float64(gopSize),
RateControlMode: rateControl,
CodecProfile: profile,
CodecLevel: level,
InterlaceMode: interlaceMode,
QualityTuningLevel: tuning,
NumberBFramesBetweenReferenceFrames: bframes,
},
}
default:
Expand Down
8 changes: 8 additions & 0 deletions internal/provider/zencoder/zencoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,14 @@ func (z *zencoderProvider) buildOutput(job *db.Job, preset db.Preset, filename s
if preset.Video.Codec == "h264" {
zencoderOutput.H264Profile = strings.ToLower(preset.Video.Profile)
zencoderOutput.H264Level = strings.ToLower(preset.Video.ProfileLevel)

if preset.Video.BFrames != "" {
bframes, err := strconv.ParseInt(preset.Video.BFrames, 10, 32)
if err != nil {
return zencoder.OutputSettings{}, fmt.Errorf("error converting preset bframes (%q): %s ", preset.Video.BFrames, err)
}
zencoderOutput.H264Bframes = int32(bframes)
}
}
if preset.RateControl == "CBR" {
zencoderOutput.ConstantBitrate = true
Expand Down
2 changes: 2 additions & 0 deletions internal/provider/zencoder/zencoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func TestGetPreset(t *testing.T) {
GopMode: "fixed",
GopSize: "90",
Height: "1080",
BFrames: "4",
},
Audio: db.AudioPreset{
Bitrate: "128000",
Expand Down Expand Up @@ -163,6 +164,7 @@ func TestZencoderDeletePreset(t *testing.T) {
GopMode: "fixed",
GopSize: "90",
Height: "1080",
BFrames: "3",
},
Audio: db.AudioPreset{
Bitrate: "128000",
Expand Down

0 comments on commit af92630

Please sign in to comment.