简体   繁体   English

如何用ffmpeg提取固定数量的帧?

[英]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). 我试图从一堆视频中统一提取固定数量的帧(比如每个视频50帧,总共10,000个视频)。

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. 由于持续时间不同,我计算了每个视频的理想输出fps,并将其作为ffmpeg提取的参数,但未能获得所需的帧数。

Does anyone know how to extract a fixed number of frames with ffmpeg, or other tools? 有谁知道如何使用ffmpeg或其他工具提取固定数量的帧? Thanks! 谢谢!

You could use the thumbnail filter. 您可以使用缩略图过滤器。 It picks one representative frame from every set of n frames (default is 100) 它从每组n帧中挑选一个代表性帧(默认为100)

So, if your source video is 10 minutes long and at 25 fps, then it has 15000 frames in total. 因此,如果您的源视频长达10分钟且速度为25 fps,那么它总共有15000帧。 So, to select 50 frames, you would use 因此,要选择50帧,您将使用

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. 这将从每组300帧中选择一个代表性帧,因此从15000帧中选择50帧。尽管名称,缩略图只是选择帧,但它不会缩小它们以供缩略图使用。 The setpts and r are set in conjunction to avoid duplicate or dropped frames. setptsr一起设置以避免重复或丢帧。 The vframes is set so no more than 50 images are output. 设置了vframes ,因此输出的图像不超过50张。

If you need to select strictly every nth frame, use 如果您需要严格选择每nth帧,请使用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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