(FFmpeg) How to Stitch Segments to One Video?

Stitching videos generated by the segment filter is accomplished using the concat filter. See Question, “How to Splice a Video into Segments?”, for more details on segmenting video output.

Imagine you’ve generated a bunch of segments for a stream and now you need to combine them back together as the packages arrive at the client. First a list of videos to stitch together must be created. The file (file.txt) might look like the following:

file 'output_00.mp4' 
file 'output_01.mp4' 
file 'output_02.mp4' 
file 'output_03.mp4' 
file 'output_04.mp4'

Then run the following command to create a single file again:

  $ ffmpeg -f concat -i file.txt -c copy -fflags +genpts output.mp4   

Streaming with concat is not covered in this book but more information can be found by visiting: https://ffmpeg.org/ffmpeg-formats.html#concat-1

fflags
	Indicates the specific flag that is used

+genpts
	Indicates the need to generate missing presentation timestamps (PTS) if needed. A common requirement when a video is segmented by duration instead of timestamp

Challenge: How would you do this with an audio file instead?

Related Posts