Extract Last 10 Seconds of a Video using FFmpeg

This short tutorial will demonstrate how to extract the last N seconds from a video (like extracting the last 10 seconds of a video using FFmpeg). To do this we will make use of the -sseof option by FFmpeg. This is useful in video editing, where you might want to remove the credits section or slates that have been burned into the video.

The -sseof option is used to trim the video with its input parameter referencing to the video playback position relative to the end of the file. Now that you’re acquainted, let’s head into the sample commands. Note: if you are interested in learning how to trim/cut/extract portions of a video from anywhere within the video, please check out our detailed tutorial on trimming/extracting/cutting a video using FFmpeg.

We will explore the command with two alternatives, one using stream copy, and one without. 

Extract Last 10 seconds With Stream Copy Enabled

The command to get the last N seconds of a video with stream copy enabled is as follows –

ffmpeg -sseof -$n -i input.mp4 -c copy output.mp4

This command will cut the video at the nearest keyframe at the desired pointer. The resulting video may have a few seconds extra that is the buffer between the pointer and the nearest keyframe. The advantage of this method is that it skips the decoding and encoding of the input and directly moves to the muxing and demuxing of the video.

Related:  Resize/Scale/Change Resolution of a Video using FFmpeg Easily

If you don’t know what a Keyframe (I, IDR) is, then check out our simple tutorial on I, P, and B-frames.

Extract Last 10 seconds Without Stream Copy Enabled

The command to get the last N seconds of a video without stream copy enabled is as follows –

 ffmpeg -sseof -$n -i input.mp4 output.mp4

This command will ensure that the cut occurs at the timeframe that corresponds to the nth second from the end.

This is a slower method as compared to the first method as the video is re-encoded but precision is retained in this method.

Akshay Rajeev
Akshay Rajeev

Akshay is a student at the NYU Tandon School of Engineering, completing his M.S. in Computer Engineering. His area of interest includes software system design, machine learning, and cybersecurity.

Akshay also serves as a Contributing Author on OTTVerse.com

Leave a Comment

Your email address will not be published. Required fields are marked *

Enjoying this article? Subscribe to OTTVerse and receive exclusive news and information from the OTT Industry.