9

I have two files, video.mp4 and genaudio.mp3 (both same length). How can I merge the MP3 file with the MP4 using FFMPEG (or any command line program)?

This is what I have so far, but it doesn't replace the audio after spitting it out:

ffmpeg -i video.mp4 -i genaudio.mp3 -c:v copy -c:a mp3 output.mp4 -y

1 Answer 1

14

You'll have to map the input streams:

ffmpeg -i video.mp4 -i genaudio.mp3 -map 0:v -map 1:a -c:v copy -c:a copy output.mp4 -y

When the inputs have multiple streams of a type among them, ffmpeg picks the 'best' one. For audio, that's the one with most number of channels. If those are the same, then it picks a stream from the earliest input.

(No need to re-encode the audio, so I've switched to copy)

3
  • I would totally re encode the mp3 file with an AAC codec See this answer, otherwise some players won't read the sound of your video.
    – PaulCo
    Jan 25, 2019 at 13:05
  • What does the -y option do? May 11, 2020 at 15:00
  • If the output file already exists, ffmpeg will prompt the user to check if it should be overwritten. -y forces the overwrite. -n forces exit and existing file is left untouched.
    – Gyan
    May 11, 2020 at 15:49

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.