Reputation: 318
I've been using FFmpeg to extract single frames into an image. Though some Googling, it turns out that running:
ffmpeg.exe -i video.avi -ss 00:30:00 -y -an -vframes 1 test.png
...runs SIGNIFICANTLY slower than the following, which is nearly identical, but instantaneous:
ffmpeg.exe -ss 00:30:00 -i video.avi -y -an -vframes 1 test.png
The only difference is the order of -i and -ss. Is this an intentional 'feature'? Is there some sort of technical reason for the difference here?
Upvotes: 13
Views: 7356
Reputation: 1530
When -ss occurs before the -i, it goes to the closest key frame (which is every 10 seconds in H.264 files for 25 fps, since H.264 will use a GOP of 250). This makes seeking really fast, so you can add another -ss after the -i to go to a fractional location after the first -ss.
Having -ss after -i will seek to the exact location, but it is very slow.
See https://trac.ffmpeg.org/wiki/Seeking for examples and more information
Upvotes: 2
Reputation: 21
I have also just finished an app that generates thumbnails from video content.
You should check this out, http://ffmpeg.org/trac/ffmpeg/wiki/Seeking%20with%20FFmpeg
It describes a method of combining the -ss
flag (from both locations) into a unified command that provides frame time
accuracy, with a quicker frame selection.
ffmpeg -ss 00:02:30 -i Underworld.Awakening.avi -ss 00:00:30 -vframes 1 out3.jpg
and also includes links to other possible tricks, like multiple thumbs from a single video.
Upvotes: 2
Reputation: 8794
wberry's answer is indeed a very educated one. Reading the documentation can help even further:
‘-ss position (input/output)’
When used as an input option (before -i), seeks in this input file to position. When used as an output option (before an output filename), decodes but discards input until the timestamps reach position. This is slower, but more accurate.
(position may be either in seconds or in hh:mm:ss[.xxx] form.)
(as found in http://ffmpeg.org/ffmpeg.html#Main-options)
I'm currently writing an audio grabber application, and, as such, I'm using the slower but more accurate method. It is up to you to choose the best approach.
Upvotes: 13
Reputation: 19347
This is an educated guess. When -ss
occurs before -i
, it is treated as instructions for the input, so the first frame of the video stream is the one at 30 seconds. When -ss
occurs after -i
, it is treated as an effect, and the first 30 seconds of frames are read and dropped, leading to a performance difference.
Upvotes: 13