Skip to content

Instantly share code, notes, and snippets.

@allyunion
Created November 1, 2023 19:20
Show Gist options
  • Save allyunion/89c4b74bde9133c297e7386004671650 to your computer and use it in GitHub Desktop.
Save allyunion/89c4b74bde9133c297e7386004671650 to your computer and use it in GitHub Desktop.
Split up video into 15 second segments
ffmpeg -i input.mp4 -force_key_frames 'expr:gte(t,n_forced)' -f segment -segment_time 15 -reset_timestamps 1 -map 0 -segment_format_options movflags=+faststart output_%03d.mp4
# From:
# Original command:
ffmpeg -i input.mp4 -force_key_frames expr:gte(t,n_forced*600) -f segment -segment_time 600 -reset_timestamps 1 -map 0 -segment_format_options movflags=+faststart output_%03d.mp4
# https://unix.stackexchange.com/questions/1670/how-can-i-use-ffmpeg-to-split-mpeg-video-into-10-minute-chunks
# To split the video more accurately, you can use the -force_key_frames option to specify keyframes at the desired split points.
#
## -f segment -segment_time 600 sets the segment length
## gte(t, n_forced*600): This is the expression itself, where:
## t represents the current time of the video frame being processed.
## n_forced represents the number of keyframes that have been forced so far.
## *600 multiplies n_forced by 600, which is the time interval in seconds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment