How to Trim and Cut Videos using FFmpeg in Linux

by Dorcas Rodriguez
10 minutes read

How to Trim and Cut Videos using FFmpeg in Linux

A pic of a desktop computer running a video clip editing as well as reinforcing prospectus.

FFmpeg is a efficient command-jabber multimedia editor for Linux. It allows you to record as well as manipulate cogent, concoct screencasts, as well as also edit as well as inscribe high-bitrate video clip records. Listed beneath we illustrate you how to immediately trim as well as implement simple incisions to your video clip records using FFmpeg.

Content
  • Trimming the Prelude as well as End of a Video Record
  • Trimming a Brief Segment Inside a Video Record
  • Trimming a Video Record right into Uniform Segments

Pointer: learn added around video clip codecs as well as bitrate by administering faultless utilise of your video clip documents size grossing utilise of FFmpeg.

Trimming the Prelude as well as End of a Video Record

One of the the majority of efficient amenities of FFmpeg is its aptitude to trim segments from cogent as well as video clip records immediately. This allows you to recover rid of any too high fabrics from your video clip as well as also automate it using capsule scripts.

Before you start trimming, guarantee that you have a backup of your initial video clip documents. This is thieving into contemplation that, opposite visual editors, FFmpeg doesn’t transaction any reverse amenity for any of its purposes:

cp ~/my-video.mp4 ~/my-video-backup.mp4

To trim the initially 30 secs of a 5 minutes video clip documents, sprinted the obeying command:

ffmpeg -ss 00:00:30 -to 00:05:00 -i my-video.mp4 -c copy my-video-trim.mp4

You can in enlargement review this phrase structure to trim at the end instead of the start of your video clip documents. Earning utilise of unmodified video clip documents, running the obeying will not surprisingly recover rid of the last 30 secs instead:

ffmpeg -ss 00:00:00 -to 00:04:30 -i my-video.mp4 -c copy my-video-trim.mp4

Aside from that, this phrase structure in enlargement maintains trimming on both expires of the video clip. For instance, bring rid of the initially as well as last 30 secs of a 5 minutes video clip will not surprisingly gander something favor this:

ffmpeg -ss 00:00:30 -to 00:04:30 -i my-video.mp4 -c copy my-video-trim.mp4

When done, review whether FFmpeg entirely trimmed your video clip by comparing it to your initial documents.

A screenshot of the VLC media gamer reflecting a comparison in between the initial video clip as well as its trimmed photocopy.

Pointer: here is a checklist of the the majority of convenient FFmpeg commands for you to supervise your video clip.

Trimming a Brief Segment Inside a Video Record

FFmpeg can in enlargement uniquely trim segments inside a video clip documents. On visual editors, doing this commonly needs you to concoct two unalike incisions as well as by hand join them in the video clip timeline.

A screenshot of the Kdenlive timeline reflecting a two-way trim.

Prelude by grossing a backup of your initial video clip documents:

cp ~/my-video.mp4 ~/my-video-backup.mp4

Open your video clip on a media gamer as well as calculate the exact timestamps for your trim times. In my skin, I pine to concoct a video clip documents grossing utilise of lone the video from 2:30 to 4:00 as well as 7:45 to 8:30 of the initial.

Convert your timestamps from minutes to secs:

echo "00:02:30" | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }'

Navigate to the catalog of your video clip documents, then paste the obeying command:

ffmpeg -i my-video.mp4  -vf "select='between(t,FIRST-START-VALUE,FIRST-END-VALUE)+between(t,SECOND-START-VALUE,SECOND-END-VALUE)', setpts=N/FRAME_RATE/TB"  -af "aselect='between(t,FIRST-START-VALUE,FIRST-END-VALUE)+between(t,SECOND-START-VALUE,SECOND-END-VALUE)', asetpts=N/SR/TB"  my-video-cut.mp4

Replace the “FIRST-START-VALUE” as well as “FIRST-END-VALUE” for both -vf as well as -af flags using the worth for your initially trim. In my video clip, my initially trim starts at 150 secs as well as expires at 240.

A incurable accentuating the varied initially trim time for the FFmpeg command.

Replace the “SECOND-START-VALUE” as well as “SECOND-END-VALUE” using the worth for your second trim, then press Go into to sprinted your command.

A incurable accentuating the varied second trim time for the FFmpeg command.

Note: You can incorporate secondary incisions by xeroxing the “+in between()” purpose on both -vf as well as -af flags along using a comma-separated checklist of your modern trim times.

Attest that your modern video clip is entirely trim by comparing it to your initial documents.

A screenshot of the VLC media gamer reflecting the inconsistency in between the initial video clip as well as the trim one.

Nice to establish: FFmpeg can in enlargement endure tunes. Learn how you can match as well as maintain your tunes records using FFmpeg.

Trimming a Video Record right into Uniform Segments

Aside from mowing as well as joining clips, you can in enlargement utilise FFmpeg to trim as well as trim an entire video clip right into short segments. This can be convenient if you have a long video clip that you pothole right into smaller sized clips.

To start, responsive a incurable session then browse to the catalog of your long video clip.

Duplicate the obeying jabber of code to your incurable incite:

ffmpeg -i my-video.mp4 -c copy -map 0 -segment_time 00:10:00 -f segment -reset_timestamps 1 my-video-%03d.mp4

Replace the worth for “segment_time” using your target clip length. For instance, you can scheme this worth to “00:05:00” to pothole your long video clip right into 5 minutes segments.

A screenshot of the VLC media gamer reflecting the uniform incisions on a single video clip documents.

Note: This command will not surprisingly effort to pothole your video clip documents based on the closest keyframe to your target segment time. As such, this command may not repeatedly upshot in diligently uniform segments.

Learning how to implement simple video clip manipulation in FFmpeg is just one of the fashionable points that you can implement in Linux. Study added of this operating mechanism’s inconsonant ecosystem by purification at some of the faultless software feat for Linux.

Image credit score: Sanjeev Nagaraj using Unsplash as well as Wikimedia Commons. Unanimously amendments as well as screenshots by Ramces Red.

Related Posts