Trim video files using FFmpeg

This is a note to self, and hopefully to others, about how to easily and quickly trim videos without recompressing the file.

I often have long video recordings that I want to split or trim (side note: sometimes people call this “cropping”, but in my world cropping is to cut out parts of the image, that is, a spatial transformation. Splitting and trimming are temporal transformations).

You can split and trim files in most video editing software, but these will typically also recompress the file on export. This reduces the quality of the video, and it also takes a long time. A much better solution is to perform “lossless” trimming, and fortunately there is a way to do this with the wonder-tool FFmpeg. Being a command line utility (available on most platforms) it has a ton of different options, and I never remember these. So here it goes, this is what I use (on Ubuntu) to trim out parts of a long video file:

ffmpeg -i input.mp4 -ss 01:19:27 -to 02:18:51 -c:v copy -c:a copy output.mp4

This will cut out the section from about 1h19min to 2h18min, and will only take a few seconds to run. If you instead want to specify a fixed duration, you can use:

ffmpeg -i input.mp4 -ss 00:01:10 -t 00:01:05 -c:v copy -c:a copy output.mp4

This will extract 1min5sec starting from 1min10sec in the file.

Published by

alexarje

Alexander Refsum Jensenius is a music researcher and research musician living in Oslo, Norway.