wiki:

Seeking


Version 2 (modified by burek, 5 years ago) (diff)

--

Introduction

If you need to extract only a specific part of your input, you'll need to use the seeking option to get to that specific part in the input first. The parameter -ss is used to seek into the input and it can be used in several ways.

Fast seeking

(-ss parameter before -i)

ffmpeg -ss 00:03:00 -i Underworld.Awakening.avi -vframes 1 out1.jpg

This example will produce 1 image frame (out1.jpg) somewhere around 3rd minute from the beginning of the movie. The input will be parsed using keyframes, which is very fast. The drawback is that it will also finish the seeking at some keyframe, not necessarily located at specified time (00:03:00), so the seeking will not be as accurate as expected.

Accurate seeking

(-ss parameter after -i)

ffmpeg -i Underworld.Awakening.avi -ss 00:03:00 -vframes 1 out2.jpg

This example will also produce 1 image frame (out2.jpg) precisely at 3rd minute from the beginning of the movie.

Note the time difference on the clocks between the images out1.jpg and out2.jpg. The first one shows "00:02:05:05" and the second shows "00:02:05:06".

The input is parsed very slowly, frame by frame. The advantage is that you'll get the frame at exactly 3rd minute, but the drawback is that it will take a lot of time until it finally reaches that time point. The bigger the seeking time is, the longer you will have to wait.

Fast and accurate seeking

(-ss parameter before and after -i)

ffmpeg -ss 00:02:30 -i Underworld.Awakening.avi -ss 00:00:30 -vframes 1 out3.jpg

This approach is combining the best characteristics of both fast and accurate ways of seeking in FFmpeg. Shortly, we first seek very fast somewhere before the 3rd minute and then we slow down and seek frame by frame to the 3rd minute. This works because FFmpeg will first seek by keyframes, until it reaches at 00:02:30, when it will stop at the last keyframe found (somewhat before 00:02:30, depending on the gop size/keyframes interval of the input) and then it will slowly seek the next 00:00:30 seconds to the desired time point. The result should be the same as in "Accurate seeking" section, only a lot faster.

Note that both out2.jpg and out3.jpg show the same time on the clock "00:02:05:06"

Attachments (4)

Download all attachments as: .zip