Extract I-frames to images quickly

3

I've used FFmpeg to extract all the I-frames from a MKV/MP4 file but FFmpeg seems to decode all frames to do it, so it takes a very long time if the video file is 1080p and longer than 10 minutes. I only want it to jump from I-frame to I-frame and dump them out to JPG/PNG files. Also, I need to know the timestamp of the I-frame.

The other option was to use FFprobe to get timestamps for all the I-frames, but that also decodes the whole file.

I'm trying to do something similar to Avidemux. In Avidemux you can step to each I-frame very fast by just pressing the up or down arrow keys, but it does so without decode all the B/P frames.

Hind-D

Posted 2019-04-04T00:20:24.277

Reputation: 227

Answers

4

Use

ffmpeg -skip_frame nokey -i file -vsync 0 -frame_pts true out%d.png

skip_frame tells the decoder to process only keyframes. -vsync 0 (in this command) preserves timestamps. -frame_pts sets the numeral portion of the output image filename to represent the timestamp. The interpretation of the number requires you to know the framerate e.g. if the framerate is 30 then an image name of out75 corresponds to a timestamp of 75/30 = 2.50 seconds. You can add -r 1000 if you want numbers to represent milliseconds.

Gyan

Posted 2019-04-04T00:20:24.277

Reputation: 21 016