Ffmpeg is an excellent and flexible tool for chopping up video - superuser.com ![]()
In order to cut videos without re-encoding the video (which can take a very long time) use the:
-c copy
The following command copies a clip from 5.5 seconds to 11.5 seconds:
ffmpeg -i input.mp4 -ss 5.5 -t 6 -c copy output.mp4
-i: This specifies the input file -ss: Seeks in input file to position 00:01:00 -to: Time your trimmed video will end with -c copy: Trim via stream copy. (NB: Very fast)
# Time unit syntax Time units in ffmpeg are tricky. It is important to use microseconds and not frames, in the fourth item of HH:MM:SS:FF where "FF" refers to frames of video. Ffmpeg uses microseconds for the fourth parameter, and to convert between frames and microseconds yo need to know the framerate of the video.
# Careful how you seek
It is faster to supply -ss BEFORE the input file (before -i), because that way ffmpeg will skip directly to the location.
However, that will result in inaccurate seeking and therefore cutting, it will also set the time "zero" to that location, meaning that -to will point to the wrong time - ffmpeg.org ![]()
# Splitting large video files
To split a large file into segments respecting existing keyframes you can use the segment muxer to break the input into segments - stackoverflow ![]()
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.
# Rejoining split files
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