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.
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.
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.
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
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.