-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ffmpeg: Reuse transcode session for GPU encoding.
- Loading branch information
Showing
7 changed files
with
1,119 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package ffmpeg | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestTranscoderAPI_InvalidFile(t *testing.T) { | ||
// Test the following file open results on input: fail, success, fail, success | ||
|
||
tc := NewTranscoder() | ||
defer tc.StopTranscoder() | ||
in := &TranscodeOptionsIn{} | ||
out := []TranscodeOptions{TranscodeOptions{ | ||
Oname: "-", | ||
AudioEncoder: ComponentOptions{Name: "copy"}, | ||
VideoEncoder: ComponentOptions{Name: "drop"}, | ||
Muxer: ComponentOptions{Name: "null"}, | ||
}} | ||
|
||
// fail # 1 | ||
in.Fname = "none" | ||
_, err := tc.Transcode(in, out) | ||
if err == nil || err.Error() != "No such file or directory" { | ||
t.Error("Expected 'No such file or directory', got ", err) | ||
} | ||
|
||
// success # 1 | ||
in.Fname = "../transcoder/test.ts" | ||
_, err = tc.Transcode(in, out) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
// fail # 2 | ||
in.Fname = "none" | ||
_, err = tc.Transcode(in, out) | ||
if err == nil || err.Error() != "No such file or directory" { | ||
t.Error("Expected 'No such file or directory', got ", err) | ||
} | ||
|
||
// success # 2 | ||
in.Fname = "../transcoder/test.ts" | ||
_, err = tc.Transcode(in, out) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
// Now check invalid output filename | ||
out[0].Muxer = ComponentOptions{Name: "md5"} | ||
out[0].Oname = "/not/really/anywhere" | ||
_, err = tc.Transcode(in, out) | ||
if err == nil { | ||
t.Error(err) | ||
} | ||
|
||
} | ||
|
||
func TestTranscoderAPI_Stopped(t *testing.T) { | ||
|
||
// Test stopped transcoder | ||
tc := NewTranscoder() | ||
tc.StopTranscoder() | ||
in := &TranscodeOptionsIn{} | ||
_, err := tc.Transcode(in, nil) | ||
if err != ErrTranscoderStp { | ||
t.Errorf("Unexpected error; wanted %v but got %v", ErrTranscoderStp, err) | ||
} | ||
|
||
// test somehow munged transcoder handle | ||
tc2 := NewTranscoder() | ||
tc2.handle = nil // technically this leaks memory ... OK for test | ||
_, err = tc2.Transcode(in, nil) | ||
if err != ErrTranscoderStp { | ||
t.Errorf("Unexpected error; wanted %v but got %v", ErrTranscoderStp, err) | ||
} | ||
} | ||
|
||
func TestTranscoderAPI_TooManyOutputs(t *testing.T) { | ||
|
||
out := make([]TranscodeOptions, 11) | ||
for i, _ := range out { | ||
out[i].VideoEncoder = ComponentOptions{Name: "drop"} | ||
} | ||
in := &TranscodeOptionsIn{} | ||
tc := NewTranscoder() | ||
_, err := tc.Transcode(in, out) | ||
if err == nil || err.Error() != "Too many outputs" { | ||
t.Error("Expected 'Too many outputs', got ", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.