Skip to content

Commit

Permalink
ffmpeg: remove input even if conversion fails
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Aug 19, 2024
1 parent 9fa841e commit 7396ccc
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions ffmpeg/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ func SetPath(path string) {
// Returns: the path to the converted file.
func ConvertPath(ctx context.Context, inputFile string, outputExtension string, inputArgs []string, outputArgs []string, removeInput bool) (string, error) {
outputFilename := strings.TrimSuffix(strings.TrimSuffix(inputFile, filepath.Ext(inputFile)), "*") + outputExtension
if removeInput {
defer func() {
_ = os.Remove(inputFile)
}()
}

args := make([]string, 0, len(ffmpegDefaultParams)+len(inputArgs)+2+len(outputArgs)+1)
args = append(args, ffmpegDefaultParams...)
Expand All @@ -71,10 +76,6 @@ func ConvertPath(ctx context.Context, inputFile string, outputExtension string,
return "", fmt.Errorf("ffmpeg error: %w", err)
}

if removeInput {
_ = os.Remove(inputFile)
}

return outputFilename, nil
}

Expand Down

0 comments on commit 7396ccc

Please sign in to comment.