Worker: fix FFmpeg issues on Windows
Fix the FFmpeg unit test on Windows, by: - Having actual input files (otherwise the input-glob-creation-function errors out), and - ensuring the cleanup function is always run, and - testing for the right CLI arguments.
This commit is contained in:
parent
f4299018ef
commit
dbd32e56cd
@ -116,7 +116,17 @@ func (ce *CommandExecutor) cmdFramesToVideoExeCommand(
|
||||
}
|
||||
|
||||
inputGlobArgs, cleanup, err := parameters.getInputGlob()
|
||||
|
||||
// runCleanup should be used if the cleanup function is *not* going to be
|
||||
// returned (i.e. in case of error).
|
||||
runCleanup := func() {
|
||||
if cleanup != nil {
|
||||
cleanup()
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
runCleanup()
|
||||
return nil, nil, fmt.Errorf("creating input for FFmpeg: %w", err)
|
||||
}
|
||||
|
||||
@ -128,6 +138,7 @@ func (ce *CommandExecutor) cmdFramesToVideoExeCommand(
|
||||
|
||||
execCmd := ce.cli.CommandContext(ctx, parameters.exe, cliArgs...)
|
||||
if execCmd == nil {
|
||||
runCleanup()
|
||||
logger.Error().Msg("unable to create command executor")
|
||||
return nil, nil, ErrNoExecCmd
|
||||
}
|
||||
@ -136,6 +147,7 @@ func (ce *CommandExecutor) cmdFramesToVideoExeCommand(
|
||||
Msg("going to execute FFmpeg")
|
||||
|
||||
if err := ce.listener.LogProduced(ctx, taskID, fmt.Sprintf("going to run: %s %q", parameters.exe, cliArgs)); err != nil {
|
||||
runCleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
|
@ -70,8 +70,9 @@ func TestCmdFramesToVideoSimpleWindows(t *testing.T) {
|
||||
Parameters: map[string]interface{}{
|
||||
"exe": "/path/to/ffmpeg -v quiet",
|
||||
"argsBefore": []string{"-report"},
|
||||
"inputGlob": "path/to/renders/*.png",
|
||||
"fps": 10.0,
|
||||
// NOTE: these files MUST exist, otherwise the glob index file creation will fail.
|
||||
"inputGlob": "command_ffmpeg_test_files/*.png",
|
||||
"fps": 10.0,
|
||||
"args": []string{
|
||||
"-c:v", "hevc",
|
||||
"-crf", "31",
|
||||
@ -83,8 +84,8 @@ func TestCmdFramesToVideoSimpleWindows(t *testing.T) {
|
||||
|
||||
cliArgs := []string{
|
||||
"-v", "quiet", // exe
|
||||
"-report", // argsBefore
|
||||
"-f", "concat", "-i", "this-is-random.txt", // input glob
|
||||
"-report", // argsBefore
|
||||
"-f", "concat", "-safe", "0", "-i", "command_ffmpeg_test_files\\ffmpeg-file-index.txt", // input glob
|
||||
"-c:v", "hevc", "-crf", "31", "-vf", "pad=ceil(iw/2)*2:ceil(ih/2)*2", // args
|
||||
"-r", "10", // fps
|
||||
"path/to/renders/preview.mkv", // outputFile
|
||||
@ -92,12 +93,13 @@ func TestCmdFramesToVideoSimpleWindows(t *testing.T) {
|
||||
mocks.cli.EXPECT().
|
||||
CommandContext(gomock.Any(), "/path/to/ffmpeg", gomock.Any()).
|
||||
DoAndReturn(func(ctx context.Context, name string, arg ...string) error {
|
||||
// Test all but the random filename.
|
||||
assert.EqualValues(t, cliArgs[:6], arg[:6])
|
||||
assert.EqualValues(t, cliArgs[7:], arg[7:])
|
||||
return nil
|
||||
assert.EqualValues(t, cliArgs, arg)
|
||||
return nil // this is the nil *exec.Cmd referenced below
|
||||
})
|
||||
|
||||
err := ce.cmdFramesToVideo(context.Background(), zerolog.Nop(), taskID, cmd)
|
||||
assert.Equal(t, ErrNoExecCmd, err, "nil *exec.Cmd should result in ErrNoExecCmd")
|
||||
|
||||
assert.NoFileExists(t, "command_ffmpeg_test_files/ffmpeg-file-index.txt",
|
||||
"the glob index file should have been removed")
|
||||
}
|
||||
|
BIN
internal/worker/command_ffmpeg_test_files/frame-1.png
Normal file
BIN
internal/worker/command_ffmpeg_test_files/frame-1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
BIN
internal/worker/command_ffmpeg_test_files/frame-2.png
Normal file
BIN
internal/worker/command_ffmpeg_test_files/frame-2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
BIN
internal/worker/command_ffmpeg_test_files/frame-3.png
Normal file
BIN
internal/worker/command_ffmpeg_test_files/frame-3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
Loading…
x
Reference in New Issue
Block a user