简体   繁体   中英

How to extract a fixed number of frames with ffmpeg?

I am trying to extract a fixed number of frames uniformly from a bunch of videos(say 50 frames from each video, 10,000 videos in total).

Since the duration varies, I calculated the ideal output fps for each video and take it as a parameter for ffmpeg extraction, but failed to get the required number of frames.

Does anyone know how to extract a fixed number of frames with ffmpeg, or other tools? Thanks!

You could use the thumbnail filter. It picks one representative frame from every set of n frames (default is 100)

So, if your source video is 10 minutes long and at 25 fps, then it has 15000 frames in total. So, to select 50 frames, you would use

ffmpeg -i input.mp4 -vf thumbnail=300,setpts=N/TB -r 1 -vframes 50 inputframes%03d.png

This selects one representative frame from each set of 300 frames, so 50 frames from 15000. Despite the name, thumbnail simply selects frames, it does not downsize them for thumbnail use. The setpts and r are set in conjunction to avoid duplicate or dropped frames. The vframes is set so no more than 50 images are output.

If you need to select strictly every nth frame, use

ffmpeg -i input.mp4 -vf select='not(mod(n\,300))',setpts=N/TB -r 1 -vframes 50 inputframes%03d.png

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM