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. On a 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. I have another blog post on cropping video files using FFmpeg.
You can split and trim files in most graphical video editing software, but these will typically also recompress the export file. This reduces the quality of the video, and it also takes a long time. A much better solution is to perform “lossless” trimming. Fortunately, there is a way to do this with the beautiful command-line utility FFmpeg. It is available for most platforms and has a ton of different options. So to remember how it is done, here is a simple one-liner:
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 (after the -ss command) to 2h18min (after the -to command). The copy parts of the command are meant to copy both the original audio and video content without recompressing. This means that the above command only takes a few seconds to run.
You may instead want to specify a fixed duration to extract, in which case 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 (using the -t flag) starting from 1min10sec (the -ss flag) in the file. Happy trimming!