Changes between Version 12 and Version 13 of Seeking
- Timestamp:
- May 26, 2014, 3:36:50 PM (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Seeking
v12 v13 10 10 11 11 {{{ 12 ffmpeg -ss 00: 03:00 -i Underworld.Awakening.avi-frames:v 1 out1.jpg12 ffmpeg -ss 00:23:00 -i Mononoke.Hime.mkv -frames:v 1 out1.jpg 13 13 }}} 14 14 15 [[Image(out 1.jpg)]]15 [[Image(out.jpg)]] 16 16 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.17 This 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. 18 18 19 = Accurateseeking =19 = Slow seeking = 20 20 21 21 The `-ss` parameter needs to be specified after `-i`: 22 22 23 23 {{{ 24 ffmpeg -i Underworld.Awakening.avi -ss 00:03:00 -frames:v 1 out2.jpg24 ffmpeg -i Mononoke.Hime.mkv -ss 00:23:00 -frames:v 1 out2.jpg 25 25 }}} 26 26 27 [[Image(out 2.jpg)]]27 [[Image(out.jpg)]] 28 28 29 29 This example will also produce one image frame (out2.jpg) precisely at the third minute from the beginning of the movie. 30 30 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".'' 31 Here, 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. 32 32 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 = 36 34 37 35 For this we specify the `-ss` parameter before and after `-i`: 38 36 39 37 {{{ 40 ffmpeg -ss 00: 02:30 -i Underworld.Awakening.avi-ss 00:00:30 -frames:v 1 out3.jpg38 ffmpeg -ss 00:22:30 -i Mononoke.Hime.mkv -ss 00:00:30 -frames:v 1 out3.jpg 41 39 }}} 42 40 43 [[Image(out 3.jpg)]]41 [[Image(out.jpg)]] 44 42 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.43 As 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. 46 44 47 ''Note that both out2.jpg and out3.jpg show the same time on the clock "00:02:05:06"'' 45 This 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.'' 48 48 49 49 There 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).
