How to Trim a Video using a Start and Stop Time with FFmpeg

3 October 2022 | 3 min read
Casper Kloppenburg

Prerequisites

FFmpeg is a free and open-source video editing tool capable of trimming, cropping, concatenating, muxing, and transcoding almost any type of media file you throw at it.

It's also a very robust solution for implementing video automation, as we use it extensively in our own video editing API. For this tutorial we'll use FFmpeg 5.1.2, but any recent version will do.

Using start and end points

Use the following command to trim a video from 01:10 to 02:10 (written as minutes : seconds). This will result in a video of 1 minute:

$ ffmpeg -i input.mp4 -ss 01:10 -to 02:10 output.mp4

The -ss 01:10 argument instructs FFmpeg to begin at the 1 minute and 10 second mark. Alternatively, you can specify the time in seconds using -ss 70.

The -to 02:10 argument instructs FFmpeg to stop at the 2 minute and 10 second mark. Alternatively, you can use -to 130 in seconds.

Using a start point and duration

Use the following command to trim a video from 01:10 up to 1 minute (written as minutes : seconds). This basically does the same thing as the previous command, but by specifying a duration instead of a stop time.

$ ffmpeg -i input.mp4 -ss 01:10 -t 01:00 output.mp4

The -ss 01:10 argument instructs FFmpeg to begin at the 1 minute and 10 second mark. Alternatively, you can specify the time in seconds using -ss 70.

The -t 01:00 argument instructs FFmpeg to cut out a portion of 1 minute. Alternatively, you can use -to 60 in seconds.

Lossless trimming

Trimming a video at the exact second requires re-encoding the video stream, and every time that happens, it impacts the quality of the video. If precise trimming is not a requirement, there's another way to trim videos without having to re-encode the video stream. This involves cutting at the nearest I-frame.

Think of I-frames as points in a video file at which the video can be safely cut without corrupting the stream. The problem is, these I-frames don't necessarily line up with where you want the video to cut, so your video might have a different length than what you specified. Therefore, the points you specify are merely approximate cutting points.

$ ffmpeg -ss 01:10 -i input.mp4 -to 02:10 -codec copy output.mp4
  • It is important to place the -ss 01:10 before the -i input.mp4 argument. The difference is in how FFmpeg handles input and output seeking. If you place it after the input argument, the video may stutter at the beginning.
  • The argument -codec copy tells FFmpeg not to re-encode the video, but simply copy its video stream.

In my experience, this method works well with large video files, but it can also make the video unplayable in some video players. My recommendation would be to use it only if you can verify that it works with all the video players you intend to target.

Start automating today

Start with a full-featured trial with 50 credits, no credit card required.
Get started for free