FFMPEG: How to combine multiple video files into one and replace audio with new audio file

audioffmpegvideo

I have a question about ffmpeg
I have many shot mp4 video file and one mp3 audio (example: 1 hour long )
I want to combine random mp4 video file to one output file (length match mp3 length) and replace audio with that mp3 file to one output mp4 file.

Best Answer

Short answer is yes. Yes you can.

See https://stackoverflow.com/questions/11779490/how-to-add-a-new-audio-not-mixing-into-a-video-using-ffmpeg

Specifically The section "To manually choose specific streams"

Once you combine the video (mp4) files in the order and length you want, you then combine the video (mp4) and audio (mp3) files together and use the -map option to choose the video stream and audio stream you want in the final output. This will then give you the video you want, and the audio from the mp3 file you have

EDIT

To answer your comment, you can use the concat command in ffmpeg to combine video's together

  1. Put this in a text file (we will call it list.txt) file 'path/to/file1.mp4' file 'path/to/file2.mp4' file 'path/to/file3.mp4'

  2. then ffmpeg -f concat -i list.txt -c copy output.mp4