85.13 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 85.6.
Using ffmpeg we can extract a segment from a video.
$ ffmpeg -i input.mp4 -ss 00:00:00 -t 00:00:11 -async 1 cut.mp4
In this example the input file is identified with the
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
00:00:11 will stop writing to the output file after the
specified duration of 11 seconds of output video. whilst the audio
stream is synchronised at the beginning of the output stream to match
the timestamp (using
1). The following command produces a
video of length 11 seconds.
Note that if
-t is specified prior to
-i (the input) then the
duration refers to the input video rather than the output video. For
the above example it would make no difference since we are not
cropping the beginnig of the video.
-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 71 seconds in to 53 minutes in:
$ ffmpeg -i input.mp4 -ss 00:07:41 -to 00:53:00 -async 1 cut.mp4
Using avisplit we can also extract a particular section
of an avi file (specified as the
-input file) and using
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
$ avisplit -i a.avi -t 0:7:20.0-0:8:20.0
Your donation will support ongoing development and give you access to the PDF version of this 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.