1

I have a bunch of MP4s and Wav files in a folder with the same filenames, different file extension.

I want to replace the audio in the video files with the wav.

i.e. something like this:

for i in *.MP4; 
 do ffmpeg -i "$i" -i "${i%.*}.wav" -c:v copy -map 0:v:0 -map 1:a:0 
 "${i%.*}_merged.mp4"; done

Is this the right way to merge all the files?

  • 1
    Looks good except for the newline after 1:a:0: your shell may interpret "${i%.*}_merged.mp4"; done as a separate command. Consider adding -movflags +faststart if the videos are intended for progressive playback (such as on a web site hosted by you). – llogan Jul 29 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.