scripts:ffmpeg:split_video_to_multiple_parts

Split a video file to multiple parts

If you need to either upload a video in multiple parts, or run a command in parallel (see above), it can be useful to split a video of audio file.

This can be done with ffmpeg using the 'segment' feature.

ffmpeg -i input.mkv -f segment -segment_time 30 -c:v copy -c:a copy -reset_timestamps 1 -map 0 output-%2d.mkv

This will losslessly split the video into 30 second chunks. Since we are just copying the audio and video without re-encoding, we don't need to worry about reducing the quality, or gapless playback when you merge back. (You really shouldn't split and re-encode audio, it will be noticable with noise or pop when going between segments when you merge it back).

In this command, -segment_time is the length to split at in seconds. -reset_timestamps 1 is needed so that the resulting video starts at 0:00 with the proper timecode information.

The main benefit of using segment instead of splitting directly, is that segment is smart when deciding where to split. Even it you request chunks at 30 seconds, the actual chunk lengths will vary. This is because it will make sure that the split falls on a keyframe, so there is no corruption when you merge and play the video back.

  • scripts/ffmpeg/split_video_to_multiple_parts.txt
  • Last modified: 2022-04-06 21:47
  • by Tony