ori silberberg
ori silberberg

Reputation: 91

extract frames using ffmpeg and find out their offset (milliseconds)

I wish to extract 10 consecutive frames every 2 seconds. (this is because I wish to choose "best one" from the "nearby offset"). I know how to extract a frame each x seconds:

ffmpeg -i /tmp/V.MP4 -vf fps=1 %02d.jpg

I know how to extract 10 frames from some starting offset:

ffmpeg -ss 20.0 -i /tmp/V.MP4 -vframes 10 %02d.jpg

I have 2 issues:

  1. How do I find the offset for each output image? I can try and calculate it (using the video fps, which is 29.97 in my case) but it sounds like a bad idea - the data is right there in the video for ffmpeg to grab..
  2. Is there an efficient way to "merge" the two commands into one, therefore getting 10 consecutive frames each x seconds?

Upvotes: 2

Views: 1718

Answers (1)

Gyan
Gyan

Reputation: 92928

Use

ffmpeg -i source -vf select='eq(n,0)+if(mod(trunc(t)+1,2)*(trunc(t)-trunc(prev_t)),st(1,n),lt(n,ld(1)+10))' -vsync 0 -frame_pts 1 %d.jpg

How do I find the offset for each output image?

See what frame_pts values mean, at ffmpeg output images filename with time position

this is because I wish to choose "best one" from the "nearby offset"

the thumbnail filter can sort of do this.

Upvotes: 1

Related Questions