ffmpeg – Replicate the behavior of -r option before applying filters

When converting the framerate of a video, ffmpeg offers multiple options

one options is -r:

ffmpeg -i myvideo.mp4 -r 10 my10fpsvideo.mp4

another option is using filters:

ffmpeg -i myvideo.mp4 -filter_complex [0]fps=fps=10[s0] -map [s0] my10fpsvideo.mp4

Using the second option I can apply further filters on the changed fps stream, like selecting a start frame number for exemple select=gte(n,42)

Both these solutions don’t return the same frames from the original video:

-r 10 return the frame indexes  0,1,2,4,7,9,12...
-filter_complex returns indexes     1,3,6,8,11...

As you can see -r somehow shift the output video by 2 frames and doesn’t return the same frames as -complex_filter

My problem is I need to apply that start frame number filters, but I also need to extract the exact frames from the original video as -r would do

For exemple: If I convert to 10 fps and want to start at frame index 3 I should receive frames 4,7,9,12..., the frame I would have gotten if had changed framerate using -r and skipped the result’s first 2 frame

I am constrained to the exact frames returned by -r by legacy data that relies on these specific frames to be returned. I am also constrained by the fact that input can be VFR and I can’t precompute what frames I need to extract for a given framerate.

Right now the only solution I’ve found is to read the entire video and discard all frame up to that frame number, which is long and cost a lot of resources.

Is there any way to do what I’m trying to do ?

Read more here: Source link