Extract Video Frames – How to Use VLC or FFmpeg to Extract Every 10th Frame

extractffmpegframevideovlc-media-player

I am trying to extract "exactly 1 frame of every 10" frames of a video (i.e. extract 1 , leave 9 then repeat) for scientific purposes. The video is 105 frames, 3.5 seconds, 29.97fps (h.264, .mov, produced by Nikon D3100).

I have uploaded it here.

VLC

Below command should produce 10 frames, but it only produces 6 images. I tried different scene ratios and neither of them produce correct number of frames (not even near to correct).

vlc 1.mov --video-filter=scene --vout=dummy --scene-ratio=10 --scene-prefix=img- --scene-path=. vlc://quit

Would someone please tell me what is the problem?

FFmpeg

FFmpeg does not seem to have a command exactly for my purpose. Below command extracts 3 frames out of every second, but since the FPS is not exactly 30 (rather 2.97), that will not produce correct results for me.

In addition even FFmpeg does not give out correct number of frames with even this command. For 3.5 seconds of video I expect at most 10 frames, but what I get is 12 frames!

ffmpeg -i 1.mov -y -an -sameq  -r 3 -f image2 -vcodec mjpeg %03d.jpg 

How can I achieve what I want?

Best Answer

Select 1 frame out of every 10 frames

You can use the select video filter in ffmpeg to do this:

ffmpeg -i input.mov -vf "select=not(mod(n\,10))" -vsync vfr -q:v 2 img_%03d.jpg
  • For JPG output you can vary quality with -q:v. Effective range is 2 (best quality) to 31 (worst quality). You don't need this option if you want to output to PNG instead.

  • This will output img_001.jpg, img_002.jpg, img_003.jpg, etc.