ffmpeg: extract frames and get their exact timestamps

5

2

I'm trying to extract frames from a variable framerate video every 5 seconds and get the exact timestamps of each frame extracted. This is what I have so so far:

-i inputfile -vstats_file vstats.log  -vsync 2 -vcodec png -r 0.2 -f image2pipe -

And this is what I get:

frame=     1 q= 0.0 f_size= 136261 s_size=      133kB **time= 5.000** br=   218.0kbits/s avg_br=   218.0kbits/s type= I
frame=     2 q= 0.0 f_size= 139382 s_size=      269kB **time= 10.000** br=   223.0kbits/s avg_br=   220.5kbits/s type= I
frame=     3 q= 0.0 f_size= 141631 s_size=      407kB **time= 15.000** br=   226.6kbits/s avg_br=   222.5kbits/s type= I

I need the exact timestamp of the frame that was used for extraction, so I can later accurately cut the video based on thumbnails generated.

Also, is there a way to print vstats to stdout rather than a file?

Mango

Posted 2012-06-07T15:00:52.547

Reputation: 115

non-ffmpeg solutions are fine too, as long as it's a command-line tool. – Mango – 2012-06-07T15:10:38.150

Answers

2

i'm not sure what you tried to do, but if it works for you then it's ok...

Anyway, for skipping frames I would have use SELECT video filter (make sure you have libavfilter enable). For frames infoI would have used SHOWINFO video filter.

Your command should be something like the following:

ffmpeg -i inputfile -vf '[in]select=not(mod(n\,150))[s1];[s1]showinfo[out]' -vcodec mpeg2video outputfile

(where 150 frames are 5sec * 30fps)

E.G.

Posted 2012-06-07T15:00:52.547

Reputation: 310

@Mango 'isnan(prev_selected_t)+gte(t-prev_selected_t,5)' this filter does not work for me, is it still valid? – bendaf – 2018-08-02T07:24:22.167

2showinfo is exactly what I needed, thanks. By the way, for a variable framerate video I used select='isnan(prev_selected_t)+gte(t-prev_selected_t,5)' to get a frame every 5 seconds. – Mango – 2012-06-12T17:32:06.627