Concat multiple video and audio files with ffmpeg

I have an array of audio and video clips, where each audio clip has a 1: 1 correlation with this video clip. The encoding of each video and each audio clip is the same. How can I concatenate all audio clips and all video clips, and then combine them together to output the video. At the moment, I just figured out how to combine 1 audio clip with 1 video clip:

$ ffmpeg -i video_1.webm -i audio_1.wav -acodec copy -vcodec copy output.mkv 

Update I just stumbled upon mkvmerge , maybe this is the best option?

+4
source share
2 answers

You can find your answer here in this old question:

Merge two mp4 files with ffmpeg

This answer is not limited to MP4. But it will depend on the file format you want to combine!

Once you have a new VIDEO file and an AUDIO file, merge them together:

ffmpeg -i AUDIO -i VIDEO -acodec copy -vcodec copy OUTPUT

+3
source

If all files are encoded with the same codecs, then this is easy to do. First combine the audio and video files, as you have already done, each pair of files is contained in one mkv. You can then combine them using concat demuxer as follows:

 ffmpeg -f concat -i <(printf "file '%s'\n" ./file1.mkv ./file2.mkv ./file3.mkv) -c copy merged.mkv 

or

 ffmpeg -f concat -i <(printf "file '%s'\n" ./*.mkv) -c copy merged.mkv 

You can also list one file per line in a text file called mergelist.txt (or whatever you call it), that is:

 file './file1.mkv' file './file2.mkv' file './file3.mkv' 

Then use this as input, a la:

 ffmpeg -f concat -i mergelist.txt -c copy merged.mkv 

This is the easiest and fastest way to do what you need, since it will not transcode files, just build them one by one.

+7
source

Source: https://habr.com/ru/post/1501405/


All Articles