Concatenate Multimedia Files with FFmpeg02 Mar 2018 #FFmpeg
FFmpeg is an extremely powerful command line tool, able to accomplish a variety of operations on multimedia files. Although capable, FFmpeg can also be unwieldy to those that are unfamiliar with it. This blog post goes into a simple FFmpeg command to concatenate multiple multimedia files.
ffmpeg -f concat -safe 0 -i <(for f in ./*.mp4; do echo "file '$PWD/$f'"; done) -c copy output.mp4
The above command concatenates all
.mp4 files (as long as they use the same codecs) within the current directory, ordered alphabetically, to an output file named
To do this with any other filetype (such as
.wav ), simply replace all instances of
Note: The above command will only work in a shell that supports process substitution, such as bash or zsh. If you are using a different shell, you might have to first append the list of files to a text file, then invoke the concat demuxer with the text file. See below:
for f in ./*.mp4; do echo "file '$PWD/$f'" >> list.txt; done ffmpeg -f concat -safe 0 -i list.txt -c copy output.mp4
For more information, checkout the FFmpeg Concatenate docs.