86.16 Video Trim and Cut

20201113 This section deals with the extraction of time extents of the video, that is, trim or cut the video. If you are wanting to crop the video image itself throughout a video see Section 86.8. To cut a section out of a video, cut the video into two sections, pre and post the part to be cut, then concat the two parts together as explained in Section 86.3.

Using ffmpeg we can extract a segment from a video.

$ ffmpeg -i input.mp4 -ss 00:00:00 -t 00:00:11 -async 1 -c copy cut.mp4

In this example the input file is identified with the -i parameter. The video is trimmed from the beginning using -ss to discard anything before the provided timestamp, which is 00:00:00 in this case and so nothing is trimmed from the beginning. Using -t with the argument 00:00:11 will stop writing to the output file after the specified duration of 11 seconds of output video. The audio stream is synchronised at the beginning of the output stream to match the timestamp (using -async 1). The -c copy ensures that the video is simply copied rather than re-encoding the video. With a copy the process should be very quick. The command produces a video of length 11 seconds.

By replacing -t with -to in the above command then the processing will end at the specified time. For example, the following will crop the video starting 7 minutes and 41 seconds in to 53 minutes in:

$ ffmpeg -i input.mp4 -ss 00:07:41 -to 00:53:00 -async 1 -c copy cut.mp4

If -t is specified prior to -i (the input) then the duration refers to the input video rather than the output video. That is, it specifies the duration from the beginning of the input video. For the above example it would make no difference since we are not cropping the beginnig of the video.

Using avisplit we can also extract a particular section of an avi file (specified as the -input file) and using -t to specifiy the starting point and the end point (starting at 7 minutes and 20 seconds into the video and stopping at 8 minutes and 20 seconds in, respectively):

$ avisplit -i a.avi -t 0:7:20.0-0:8:20.0

Other Options

A graphical interface to trim a video is Video Trimmer which is installable as a FlatPack.



Your donation will support ongoing availability and give you access to the PDF version of the book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2021 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0.