Skip to content

Commit

Permalink
Add support for specifying TwoPass on presets
Browse files Browse the repository at this point in the history
Providers are not required to implement the feature, but it can be used
in some cases.
  • Loading branch information
Francisco Souza committed Mar 8, 2018
1 parent b7fe798 commit cc0d223
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 112 deletions.
6 changes: 4 additions & 2 deletions db/redis/localpreset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ func TestCreateLocalPreset(t *testing.T) {
t.Fatal(err)
}
expectedItems := map[string]string{
"preset_name": "test",
"preset_name": "test",
"preset_twopass": "false",
}
if !reflect.DeepEqual(items, expectedItems) {
t.Errorf("Wrong preset hash returned from Redis. Want %#v. Got %#v", expectedItems, items)
Expand Down Expand Up @@ -102,7 +103,8 @@ func TestUpdateLocalPreset(t *testing.T) {
t.Fatal(err)
}
expectedItems := map[string]string{
"preset_name": "test-different",
"preset_name": "test-different",
"preset_twopass": "false",
}
if !reflect.DeepEqual(items, expectedItems) {
t.Errorf("Wrong presetmap hash returned from Redis. Want %#v. Got %#v", expectedItems, items)
Expand Down
1 change: 1 addition & 0 deletions db/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ type Preset struct {
Description string `json:"description,omitempty" redis-hash:"description,omitempty"`
Container string `json:"container,omitempty" redis-hash:"container,omitempty"`
RateControl string `json:"rateControl,omitempty" redis-hash:"ratecontrol,omitempty"`
TwoPass bool `json:"twoPass" redis-hash:"twopass"`
Video VideoPreset `json:"video" redis-hash:"video,expand"`
Audio AudioPreset `json:"audio" redis-hash:"audio,expand"`
}
Expand Down
1 change: 1 addition & 0 deletions provider/encodingcom/encodingcom.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func (e *encodingComProvider) presetToFormat(preset db.Preset) encodingcom.Forma
format := encodingcom.Format{
Output: []string{preset.Container},
Destination: []string{"ftp://username:password@yourftphost.com/video/encoded/test.flv"},
TwoPass: encodingcom.YesNoBoolean(preset.TwoPass),
}
if preset.Container == "m3u8" {
format.Output = []string{hlsOutput}
Expand Down
50 changes: 50 additions & 0 deletions provider/encodingcom/encodingcom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,56 @@ func TestCreatePresetHLS(t *testing.T) {
}
}

func TestCreatePresetTwoPass(t *testing.T) {
server := newEncodingComFakeServer()
defer server.Close()
client, _ := encodingcom.NewClient(server.URL, "myuser", "secret")
prov := encodingComProvider{client: client}
presetName, err := prov.CreatePreset(db.Preset{
Audio: db.AudioPreset{
Bitrate: "128000",
Codec: "aac",
},
Container: "mp4",
Description: "my nice preset",
Name: "mp4_1080p",
RateControl: "VBR",
TwoPass: true,
Video: db.VideoPreset{
Profile: "main",
ProfileLevel: "3.1",
Bitrate: "3500000",
Codec: "h264",
GopMode: "fixed",
GopSize: "90",
Height: "1080",
},
})
if err != nil {
t.Fatal(err)
}
fakePreset := server.presets[presetName]
expectedFormat := encodingcom.Format{
AudioCodec: "dolby_aac",
AudioBitrate: "128k",
AudioVolume: 100,
Output: []string{"mp4"},
Profile: "main",
TwoPass: true,
VideoCodec: "libx264",
Bitrate: "3500k",
Gop: "cgop",
Keyframe: []string{"90"},
Size: "0x1080",
Destination: []string{"ftp://username:password@yourftphost.com/video/encoded/test.flv"},
}
if !reflect.DeepEqual(fakePreset.Request.Format[0], expectedFormat) {
pretty.Fdiff(os.Stderr, fakePreset.Request.Format[0], expectedFormat)
t.Errorf("wrong format provided\nWant %#v\nGot %#v", expectedFormat, fakePreset.Request.Format[0])

}
}

func TestPresetToFormat(t *testing.T) {
falseYesNoBoolean := encodingcom.YesNoBoolean(false)
var tests = []struct {
Expand Down
1 change: 1 addition & 0 deletions provider/zencoder/zencoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ func (z *zencoderProvider) buildOutput(job *db.Job, preset db.Preset, filename s
AudioCodec: preset.Audio.Codec,
Filename: filename,
MakePublic: true,
OnePass: !preset.TwoPass,
}
zencoderOutput.Width, zencoderOutput.Height = z.getResolution(preset)
videoBitrate, err := strconv.ParseInt(preset.Video.Bitrate, 10, 32)
Expand Down
Loading

0 comments on commit cc0d223

Please sign in to comment.