Tutorial

How to Cut a Video with FFmpeg Based on Start and End Time

Install FFmpeg (if not already installed):

Determine the Start and End Time of the Clip

You need to know the exact start and end time of the clip you want to cut from the original video. You can use any video player that shows the timecode or use FFmpeg itself to get information about the video file. For example, this command will show you the duration of the video:

ffmpeg -i input.mp4

The output will look something like this:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.29.100
  Duration: 00:05:00.02, start: 0.000000, bitrate: 1408 kb/s

The duration is shown as hh:mm:ss.ms format. In this case, it is 5 minutes and 0.02 seconds.

Cut the Video with FFmpeg

To cut based on start and end time from the source video and avoid having to do math, specify the end time as the input option and the start time as the output option. For example, this command will cut a 15 second clip from 0:45 to 1:00:

ffmpeg -t 1:00 -i input.mp4 -ss 45 output.mp4

The options mean:

  • -t specifies the end time of the clip (same format as duration).
  • -i specifies the input file name.
  • -ss specifies the start time of the clip (same format as duration).
  • output.mp4 specifies the output file name.

You can also use -to instead of -t to specify the end time directly. For example:

ffmpeg -ss 45 -i input.mp4 -to 1:00 output.mp4

This will produce the same result as above.

Note that using -ss before -i will make FFmpeg seek faster but may be less accurate than using it after -i. You can experiment with both methods and see which one works better for your case.

Check the Resulting Clip

You can use any video player or FFmpeg itself to check if your clip was cut correctly. For example, this command will show you information about your output file:

ffmpeg -i output.mp4

The output should look something like this:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'output.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.29.100  
Duration: 00:00:15.02 , start: -0.023220 , bitrate :   N/A 
Stream #0 :0(und): Video : h264 (High) (avc1 /   N/A , yuv420p ,   N/A , SAR   N/A DAR   N/A ,   N/A fps ,   N/A tbr ,   N/A tbn ,   N/A tbc (default)
Metadata:
      handler_name    : VideoHandler

The duration should match your desired clip length (15 seconds)

Enjoy Your Clip

You have successfully cut a video with FFmpeg based on start and end time. You can now use your clip for any purpose you want. You can also repeat the process with different start and end times to cut more clips from the same or different videos.

Other Sources: