diff --git a/internal/worker/command_ffmpeg.go b/internal/worker/command_ffmpeg.go index e62249eb..88c25197 100644 --- a/internal/worker/command_ffmpeg.go +++ b/internal/worker/command_ffmpeg.go @@ -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 } diff --git a/internal/worker/command_ffmpeg_test.go b/internal/worker/command_ffmpeg_test.go index 1805df95..bf3a6bd0 100644 --- a/internal/worker/command_ffmpeg_test.go +++ b/internal/worker/command_ffmpeg_test.go @@ -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") } diff --git a/internal/worker/command_ffmpeg_test_files/frame-1.png b/internal/worker/command_ffmpeg_test_files/frame-1.png new file mode 100644 index 00000000..c3331a45 Binary files /dev/null and b/internal/worker/command_ffmpeg_test_files/frame-1.png differ diff --git a/internal/worker/command_ffmpeg_test_files/frame-2.png b/internal/worker/command_ffmpeg_test_files/frame-2.png new file mode 100644 index 00000000..39bb415e Binary files /dev/null and b/internal/worker/command_ffmpeg_test_files/frame-2.png differ diff --git a/internal/worker/command_ffmpeg_test_files/frame-3.png b/internal/worker/command_ffmpeg_test_files/frame-3.png new file mode 100644 index 00000000..d4f58bfb Binary files /dev/null and b/internal/worker/command_ffmpeg_test_files/frame-3.png differ