Concat multiple video and audio files with ffmpeg

随声附和 提交于 2020-01-14 10:34:07

问题


I have an array of audio and video clips, where each audio clip has a 1:1 correlation with it's video clip. The encoding of each video and each audio clip are the same. How can I concat all of the audio clips, and all the video clips, then merge them together to output a video. As of now I only figured out how to merge 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 came across mkvmerge would this possibly be a better option?


回答1:


You can find your answer here in this old question:

Concatenate two mp4 files using ffmpeg

This answer is not restricted to MP4. But it will depend on the file format you wanna concatenate!

Once you have your new VIDEO file and AUDIO file, to merge them together:

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




回答2:


If all the files are encoded with the same codecs then it's easy to do. First merge the audio and video files as you have already done so each pair of files is contained in one mkv. Then you can concatenate them with the concat demuxer like this:

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 could also list one file per line in a text file called mergelist.txt (or whatever you want to call it), i.e.:

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

Then use that as the input, a la:

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

This is by far the easiest and fastest way to do what you want since it won't re-encode the files, just line them up one after another.



来源:https://stackoverflow.com/questions/18711117/concat-multiple-video-and-audio-files-with-ffmpeg

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!