Ffmpeg -ss weird behavior

I used FFmpeg to extract individual frames in an image. Although some google seems to work:

ffmpeg.exe -i video.avi -ss 00:30:00 -y -an -vframes 1 test.png 

... works MUCH slower than the following, which is almost identical, but instantly:

 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 any technical reason for the difference here?

+6
source share
4 answers

This is a reasonable assumption. When -ss occurs before -i , it is treated as input instructions, so the first frame of the video stream is one in 30 seconds. When -ss occurs after -i , it is treated as an effect, and the first 30 seconds of frames are read and deleted, resulting in a difference in performance.

+6
source

the answer to the "worm" is really very educated. Reading the documentation can help further:

'- position ss (input / output)

When used as an input option (before -i), searches for the position in this input file. When used as an output option (up to the name of the output file), it decodes, but discards the input until the timestamp reaches the position. This is slower, but more accurate.

(The position can be either in seconds or in the form hh: mm: ss [.xxx].)

(as found at http://ffmpeg.org/ffmpeg.html#Main-options )

I am currently writing an application for sound capture, and thus I am using a slower but more accurate method. It is up to you to choose the best approach.

+6
source

When -ss occurs before -i, it jumps to the nearest keyframe (every 10 seconds in H.264 files for 25 frames per second, since H.264 will use the GOP 250). This makes the search very fast, so you can add another -ss after -i to jump to the fractional location after the first -ss.

After -ss, after -i will look for the exact location, but it is very slow.

See https://trac.ffmpeg.org/wiki/Seeking for more details.

+1
source

I also just finished an application that generates thumbnails from video content.

You should check it out, http://ffmpeg.org/trac/ffmpeg/wiki/Seeking%20with%20FFmpeg

It describes a method for combining the -ss flag (from both places) into a single command, which ensures the accuracy of the time frame, with faster frame selection.

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

as well as links to other possible tricks, such as several thumbs from one video.

+1
source

Source: https://habr.com/ru/post/894557/


All Articles