Use FFMPEG to combine MP4 and MP3 file?

6

2

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

XantiuM

Posted 2018-02-25T09:07:14.237

Reputation: 63

Answers

9

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)

Gyan

Posted 2018-02-25T09:07:14.237

Reputation: 21 016

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 – 2019-01-25T13:05:57.090