Skip to content

Commit cc0d223

Browse files
author
Francisco Souza
committed
Add support for specifying TwoPass on presets
Providers are not required to implement the feature, but it can be used in some cases.
1 parent b7fe798 commit cc0d223

File tree

6 files changed

+170
-112
lines changed

6 files changed

+170
-112
lines changed

db/redis/localpreset_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ func TestCreateLocalPreset(t *testing.T) {
3737
t.Fatal(err)
3838
}
3939
expectedItems := map[string]string{
40-
"preset_name": "test",
40+
"preset_name": "test",
41+
"preset_twopass": "false",
4142
}
4243
if !reflect.DeepEqual(items, expectedItems) {
4344
t.Errorf("Wrong preset hash returned from Redis. Want %#v. Got %#v", expectedItems, items)
@@ -102,7 +103,8 @@ func TestUpdateLocalPreset(t *testing.T) {
102103
t.Fatal(err)
103104
}
104105
expectedItems := map[string]string{
105-
"preset_name": "test-different",
106+
"preset_name": "test-different",
107+
"preset_twopass": "false",
106108
}
107109
if !reflect.DeepEqual(items, expectedItems) {
108110
t.Errorf("Wrong presetmap hash returned from Redis. Want %#v. Got %#v", expectedItems, items)

db/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ type Preset struct {
103103
Description string `json:"description,omitempty" redis-hash:"description,omitempty"`
104104
Container string `json:"container,omitempty" redis-hash:"container,omitempty"`
105105
RateControl string `json:"rateControl,omitempty" redis-hash:"ratecontrol,omitempty"`
106+
TwoPass bool `json:"twoPass" redis-hash:"twopass"`
106107
Video VideoPreset `json:"video" redis-hash:"video,expand"`
107108
Audio AudioPreset `json:"audio" redis-hash:"audio,expand"`
108109
}

provider/encodingcom/encodingcom.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func (e *encodingComProvider) presetToFormat(preset db.Preset) encodingcom.Forma
9494
format := encodingcom.Format{
9595
Output: []string{preset.Container},
9696
Destination: []string{"ftp://username:password@yourftphost.com/video/encoded/test.flv"},
97+
TwoPass: encodingcom.YesNoBoolean(preset.TwoPass),
9798
}
9899
if preset.Container == "m3u8" {
99100
format.Output = []string{hlsOutput}

provider/encodingcom/encodingcom_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,56 @@ func TestCreatePresetHLS(t *testing.T) {
10581058
}
10591059
}
10601060

1061+
func TestCreatePresetTwoPass(t *testing.T) {
1062+
server := newEncodingComFakeServer()
1063+
defer server.Close()
1064+
client, _ := encodingcom.NewClient(server.URL, "myuser", "secret")
1065+
prov := encodingComProvider{client: client}
1066+
presetName, err := prov.CreatePreset(db.Preset{
1067+
Audio: db.AudioPreset{
1068+
Bitrate: "128000",
1069+
Codec: "aac",
1070+
},
1071+
Container: "mp4",
1072+
Description: "my nice preset",
1073+
Name: "mp4_1080p",
1074+
RateControl: "VBR",
1075+
TwoPass: true,
1076+
Video: db.VideoPreset{
1077+
Profile: "main",
1078+
ProfileLevel: "3.1",
1079+
Bitrate: "3500000",
1080+
Codec: "h264",
1081+
GopMode: "fixed",
1082+
GopSize: "90",
1083+
Height: "1080",
1084+
},
1085+
})
1086+
if err != nil {
1087+
t.Fatal(err)
1088+
}
1089+
fakePreset := server.presets[presetName]
1090+
expectedFormat := encodingcom.Format{
1091+
AudioCodec: "dolby_aac",
1092+
AudioBitrate: "128k",
1093+
AudioVolume: 100,
1094+
Output: []string{"mp4"},
1095+
Profile: "main",
1096+
TwoPass: true,
1097+
VideoCodec: "libx264",
1098+
Bitrate: "3500k",
1099+
Gop: "cgop",
1100+
Keyframe: []string{"90"},
1101+
Size: "0x1080",
1102+
Destination: []string{"ftp://username:password@yourftphost.com/video/encoded/test.flv"},
1103+
}
1104+
if !reflect.DeepEqual(fakePreset.Request.Format[0], expectedFormat) {
1105+
pretty.Fdiff(os.Stderr, fakePreset.Request.Format[0], expectedFormat)
1106+
t.Errorf("wrong format provided\nWant %#v\nGot %#v", expectedFormat, fakePreset.Request.Format[0])
1107+
1108+
}
1109+
}
1110+
10611111
func TestPresetToFormat(t *testing.T) {
10621112
falseYesNoBoolean := encodingcom.YesNoBoolean(false)
10631113
var tests = []struct {

provider/zencoder/zencoder.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ func (z *zencoderProvider) buildOutput(job *db.Job, preset db.Preset, filename s
209209
AudioCodec: preset.Audio.Codec,
210210
Filename: filename,
211211
MakePublic: true,
212+
OnePass: !preset.TwoPass,
212213
}
213214
zencoderOutput.Width, zencoderOutput.Height = z.getResolution(preset)
214215
videoBitrate, err := strconv.ParseInt(preset.Video.Bitrate, 10, 32)

0 commit comments

Comments
 (0)