Merge all videos in a directory with FFmpeg using concat demuxer

If you have a large number of videos in a directory, it might be easier to write a command that will create a file with the list of videos for you before concatenating them. To determine the order that the videos will be listed, you can name them alphabetically or numerically.

for f in *.mp4; do echo "file '$f'" >> videos.txt; done

The above will create a file videos.txt with a list of files with the extension .mp4. After the file is generated, you can then stitch the listed video with the command we used earlier:

ffmpeg -f concat -i videos.txt -c copy output.mp4

Merge videos with the concat protocol You can also join videos with the concat protocol. The following code stitches four videos without re-encoding them.

ffmpeg -i "concat:input1.mp4|input2.mp4|input3.mp4|input4.mp4" -c copy output.mp4