|Version 5 (modified by rogerdpack, 8 months ago) (diff)|
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.
(-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.
(-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"
There is no general rule how to correctly set both time points for -ss options, because those depend on the keyframe interval used when the input was encoded. But, just for the purpose of some orientation, the x264 encoder uses the gop size of 250 (which means 1 keyframe each 10 seconds if the input frame rate is 25 fps).
Cutting small section
For instance to extract only a small segment in the middle of a movie, it can be used in combination with "-t" which specifies the duration, like -ss 60 -t 10 to capture from second 60 to 70.
Note that you can use timestamp inputs like 00:02:30 or 150 (mean the same thing). Also if you use a fraction, like 02:30.05 this is interpreted at "5 100ths of a second" not as frame 5 (for instance 02:30.5 would be 2 minutes, 30 seconds, and a half a second).