From d9e70b942f97df013c20e739cd2441f39cdcb484 Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Fri, 26 Jul 2024 15:30:24 +0000 Subject: [PATCH] ensure ffmpeg muxer gets set correctly by setting input file extension before clean (#3142) --- internal/media/ffmpeg.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/internal/media/ffmpeg.go b/internal/media/ffmpeg.go index ce90028af..41727b3d9 100644 --- a/internal/media/ffmpeg.go +++ b/internal/media/ffmpeg.go @@ -41,15 +41,23 @@ func ffmpegClearMetadata(ctx context.Context, filepath string, ext string) error // Get directory from filepath. dirpath := path.Dir(filepath) - // Generate output file path with ext. + // Update filepath to add extension. + filepathExt := filepath + "." + ext + + // First we need to rename filepath to have extension. + if err := os.Rename(filepath, filepathExt); err != nil { + return gtserror.Newf("error renaming to %s - >%s: %w", filepath, filepathExt, err) + } + + // Generate cleaned output path with ext. outpath := filepath + "_cleaned." + ext // Clear metadata with ffmpeg. if err := ffmpeg(ctx, dirpath, "-loglevel", "error", - // Input file. - "-i", filepath, + // Input file path. + "-i", filepathExt, // Drop all metadata. "-map_metadata", "-1", @@ -69,7 +77,7 @@ func ffmpegClearMetadata(ctx context.Context, filepath string, ext string) error // Move the new output file path to original location. if err := os.Rename(outpath, filepath); err != nil { - return gtserror.Newf("error renaming %s: %w", outpath, err) + return gtserror.Newf("error renaming %s -> %s: %w", outpath, filepath, err) } return nil