Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add bframe setting in preset #293

Merged
merged 3 commits into from
Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion internal/provider/encodingcom/encodingcom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ func TestPresetToFormat(t *testing.T) {
}
var p encodingComProvider
for _, test := range tests {
resultingFormat := p.presetToFormat(test.givenPreset)
resultingFormat, _ := p.presetToFormat(test.givenPreset)
adamthesax marked this conversation as resolved.
Show resolved Hide resolved
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