1

I am trying to use the select filter to choose frames to be included in the output file, but the resulting output file actually has more frames than the input file, which is completely baffling.

Following the example in the documentation to keep every 16th frame, I am using the following command:

ffmpeg -i input.MOV -filter:v "select=not(mod(n\,16))" output.MOV

output.MOV has more frames than input.MOV and nothing has been removed.

Interestingly, when I use the command:

ffmpeg -i input.MOV -filter:v "select=not(mod(n\,16))",showinfo output.MOV

it lists the frames that should be in the output (i.e. the ones that should be selected by the expression), but the actual output file contains more frames than that and seems to completely ignore the select filter (it seems to be the same no matter what select command I use, unless I use select=0).

Am I doing something incorrectly? I basically just want an example command that works the way I expect it to, so I can better learn how ffmpeg works.

Thanks.

Edit: select is not the only filter that ffmpeg seems to ignore when producing the output file, but if this problem is solved, the fix will probably work for other filters as well.

1 Answer 1

2

In your command,

-filter:v "select=not(mod(n\,16))"

does select only each 16th frame, as you have discovered. However, your output format is MOV, which is configured as constant frame rate. So, ffmpeg will duplicate frames if the timestamp gaps between frames from the filter output are greater than 1/fps where fps is the nominal frame rate of the stream, and drop frames if they are closer.

Add -vsync 0 to tell ffmpeg to not duplicate or drop frames.

2
  • Thank you for your answer. That does seem to work, but now I have the problem of fixing the timestamps so that the frames are displayed one after the other at the original framerate. I would have thought the -r option would do this, but the modified video is the same length timewise, even though it has fewer frames. Is there a fix for this? Thanks. Nov 29, 2020 at 16:25
  • 1
    I think I need to use setpts=STARTPTS+N/(FR*TB) after the select and then it seems I don't even need the -vsync 0 option. The odd thing is it seems to have trouble with the frame rate so I just put the number instead. Nov 29, 2020 at 17:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.