FFmpeg splitting large files

Use the segment muxer to break the input into segments:

ffmpeg -i testfile.mp4 -c copy -f segment -segment_time 1200 testfile_piece_%02d.mp4

This will split the source at keyframes, so segments may not be exactly 1200 seconds long. And the timestamps aren’t reset, so some players will fail to play the 2nd and latter segments. If playability is needed, insert -reset_timestamps 1.

After the parallel encoding, you can stitch the generated segments by first creating a text file seg.txt like this

file 'encoded_testfile_piece_00.mp4'
file 'encoded_testfile_piece_01.mp4'
file 'encoded_testfile_piece_02.mp4'
file 'encoded_testfile_piece_03.mp4'

And then running

ffmpeg -f concat -i seg.txt -c copy -fflags +genpts encoded_full.mp4

Leave a Comment