Skip to content
systemcoding.dev
Media

Seek fast by placing -ss before -i

Put -ss before -i so FFmpeg 7.1 jumps straight to the nearest keyframe instead of decoding and discarding every frame up to the start time.

1 min read
Summarize in AI

The position of -ss on the command line changes how it works, not just where it sits. Before -i it is an input option: FFmpeg seeks in the container and starts reading near the requested time. After -i it is an output option: FFmpeg decodes from the very beginning and throws frames away until it reaches the time. On an hour-long file the second form can take minutes to reach a point near the end.

Shell
ffmpeg -ss 00:45:00 -i long.mp4 -t 10 -c:v libx264 -crf 23 -c:a aac out.mp4
Text
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))

An input seek is also frame accurate when the video is being re-encoded, because FFmpeg decodes from the preceding keyframe and drops frames up to the target. That is why the example re-encodes. With -c copy the cut snaps to a keyframe instead, as covered in the trim row.

Seeking by byte offset into the index is a feature of the container, so a few formats such as raw .h264 streams without an index cannot seek quickly at all. The FFmpeg seeking guide lists the exceptions. For short files the difference is not worth thinking about.

Taggedffmpeg
Share

More snippets

Media

List ALSA devices with aplay -l

List the playback cards and devices ALSA sees with aplay -l from alsa-utils 1.2, and turn the output into a hw:card,device name.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.