10

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

16

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)

4
  • 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
    Commented Jan 25, 2019 at 13:05
  • What does the -y option do? Commented 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
    Commented May 11, 2020 at 15:49
  • @Gyan what if my input is ffmpeg -i video.mp4 -i genaudio.mp3 -i image.png , how do i copy ? beacuse while copying with "-map 0:v -map 1:a -c:v copy -c:a copy output.mp4 -y" image does not appear
    – bipin
    Commented May 13, 2023 at 23:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .