Changes between Version 12 and Version 13 of Seeking


Ignore:
Timestamp:
May 26, 2014, 6:36:50 PM (5 years ago)
Author:
c-14
Comment:

As of FFmpeg 2.1, when transcoding with ffmpeg (i.e. not streamcopying), -ss is now accurate even when used as an input option.

Legend:

Unmodified
Added
Removed
Modified
  • Seeking

    v12 v13  
    1010
    1111{{{
    12 ffmpeg -ss 00:03:00 -i Underworld.Awakening.avi -frames:v 1 out1.jpg
     12ffmpeg -ss 00:23:00 -i Mononoke.Hime.mkv -frames:v 1 out1.jpg
    1313}}}
    1414
    15 [[Image(out1.jpg)]]
     15[[Image(out.jpg)]]
    1616
    17 This example will produce one image frame (out1.jpg) somewhere around the third 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.
     17This example will produce one image frame (out1.jpg) at the third minute from the beginning of the movie. The input will be parsed '''using keyframes''', which is '''very fast'''. As of FFmpeg 2.1, when transcoding with ffmpeg (i.e. not streamcopying), -ss is now accurate even when used as an input option. Previous behavior can be restored with the -noaccurate_seek option.
    1818
    19 = Accurate seeking =
     19= Slow seeking =
    2020
    2121The `-ss` parameter needs to be specified after `-i`:
    2222
    2323{{{
    24 ffmpeg -i Underworld.Awakening.avi -ss 00:03:00 -frames:v 1 out2.jpg
     24ffmpeg -i Mononoke.Hime.mkv -ss 00:23:00 -frames:v 1 out2.jpg
    2525}}}
    2626
    27 [[Image(out2.jpg)]]
     27[[Image(out.jpg)]]
    2828
    2929This example will also produce one image frame (out2.jpg) precisely at the third minute from the beginning of the movie.
    3030
    31 ''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".''
     31Here, the input will be decoded until it reaches the position given by `-ss`. This will be done  '''very slowly''', frame by frame. As of FFmpeg 2.1, the main advantage is that when applying filters to the output stream, the timestamps aren't reset prior to filtering (i.e. when [https://trac.ffmpeg.org/wiki/HowToBurnSubtitlesIntoVideo burning subtitles into a video], you don't need to modify the subtitle timestamps), 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.
    3232
    33 Here, the input will be decoded until it reaches the position given by `-ss`. This will be done  '''very slowly''', frame by frame. The advantage is that you'll get the frame at the third 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.
    34 
    35 = Fast and accurate seeking =
     33= Combined seeking =
    3634
    3735For this we specify the `-ss` parameter before and after `-i`:
    3836
    3937{{{
    40 ffmpeg -ss 00:02:30 -i Underworld.Awakening.avi -ss 00:00:30 -frames:v 1 out3.jpg
     38ffmpeg -ss 00:22:30 -i Mononoke.Hime.mkv -ss 00:00:30 -frames:v 1 out3.jpg
    4139}}}
    4240
    43 [[Image(out3.jpg)]]
     41[[Image(out.jpg)]]
    4442
    45 This approach is combining the best characteristics of both fast and accurate ways of seeking in ffmpeg. We first seek very fast somewhere before the third minute. Then we slow down and seek frame by frame to the third minute. This works because ffmpeg will first seek by keyframes, until it reaches 00:02:30. This is where it stops at the last keyframe found (somewhere before 00:02:30, depending on the [http://en.wikipedia.org/wiki/Group_of_pictures GOP size]/keyframe 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.
     43As of FFmpeg 2.1, combined seeking is still possible but I have yet to find a valid use case for it since -ss as an input option is now both fast and accurate.
    4644
    47 ''Note that both out2.jpg and out3.jpg show the same time on the clock "00:02:05:06"''
     45This approach uses keyframes to seek until 00:02:30, and then seeks frame-by-frame until it reaches 00:03:00 (00:02:30 + 00:00:30)
     46
     47''Note that both all images created by the previous commands should be identical.''
    4848
    4949There is no general rule on how to correctly set both time points for `-ss` options, because those depend on the keyframe interval used when the input was encoded. To give some orientation, the x264 encoder by default uses a GOP size of 250 (which means 1 keyframe each 10 seconds if the input frame rate is 25 fps).