Skip to content

Commit

Permalink
ffmpeg: Error out with 0x0 transcoding profiles
Browse files Browse the repository at this point in the history
One side can still be nonzero since we will take the larger.
  • Loading branch information
j0sh committed Aug 14, 2024
1 parent 721d867 commit 250f00f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ffmpeg/ffmpeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,10 @@ func createCOutputParams(input *TranscodeOptionsIn, ps []TranscodeOptions) ([]C.
return params, finalizer, err
}
}
if w <= 0 && h <= 0 {
// fail if both <= 0. if one is nonzero, we will take the larger
return params, finalizer, ErrTranscoderRes
}
br := strings.Replace(param.Bitrate, "k", "000", 1)
bitrate, err := strconv.Atoi(br)
if err != nil {
Expand Down
13 changes: 11 additions & 2 deletions ffmpeg/ffmpeg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ func runResolutionTests_H264(t *testing.T, accel Acceleration) {
target string
// expected width and height
expected string
// expected error
err error
}{{
name: "h > w",
input: "150x200",
Expand Down Expand Up @@ -236,6 +238,11 @@ func runResolutionTests_H264(t *testing.T, accel Acceleration) {
input: "123x123",
target: "426x0",
expected: "426x426",
}, {
name: "zero",
input: "300x200",
target: "0x0",
err: ErrTranscoderRes,
}}

for i, tt := range tests {
Expand All @@ -254,11 +261,13 @@ func runResolutionTests_H264(t *testing.T, accel Acceleration) {
Profile: VideoProfile{Resolution: tt.target, Bitrate: "50k"},
Accel: accel,
}})
assert.Nil(t, err)
assert.Equal(t, tt.err, err)
cmd = fmt.Sprintf(`
echo '%s'
ffprobe -hide_banner -show_entries stream=width,height -of csv=p=0:s=x out-test-%d.mp4 | grep %s`, tt.name, i, tt.expected)
run(cmd)
if tt.err == nil {
run(cmd)
}
})
}
// TODO set / check sar/dar values?
Expand Down

0 comments on commit 250f00f

Please sign in to comment.