Concatenate videos (stitching together several video files)
This is a wiki page. Be bold and improve it!
If you have any questions about the content on this page, don't hesitate to open a new ticket and we'll do our best to assist you.
ffmpeg does not currently have a way to automatically concatenate files. The best way is to convert the videos and audio to raw video and audio files and use the command cat to add them together, then reprocess the total video.
.mpg files or raw video files
This is the simplest scenario.
If your input files are raw videos or .mpg files, you can simply
cat them together:
cat video1.mpg video2.mpg >> total.mpg
This works only with certain containers or video codecs.
.flv and other formats
Many video codecs like .flv cannot directly be concatenated together. The solution is simply to convert them to .mpg files and then proceed like above.
ffmpeg -i video1.flv -sameq intermediate1.mpg
ffmpeg -i video2.flv -sameq intermediate2.mpg
cat intermediate*.mpg >> intermediate_all.mpg
ffmpeg -i intermediate_all.mpg -sameq video.flv
The official ffmpeg documentation offers a more elaborate solution using named pipes in their FAQ:
ffmpeg FAQ 3.15 How can I join video files?