How do I capture all keyframes and scale down to 320px wide?

三世轮回 提交于 2021-02-05 06:50:13

问题


I'm trying to use ffmpeg to output all key-frames from a video file and scale them down to 320px wide while maintaining aspect ratio. I know I could do this with two separate commands but I am trying to find a way to do it tidily in one.

I've already succeeded in each of the steps individually using the following commands.

Output the keyframes:

.\ffmpeg -i input.mp4 -q:v 2 -vf select="eq(pict_type\,PICT_TYPE_I)" -vsync 0 thumb%07d.png

Scale images:

.\ffmpeg -i input.mp4 -vf scale=320:-1 thumb%07d.png

I won't share everything i've tried, but here's three failures at combining them.

//fail, not just keyframes, scaled .\ffmpeg -i input.mp4 -q:v 2 -vf select="eq(pict_type\,PICT_TYPE_I)" -vsync 0 -vf scale=320:-1 thumb%07d.png -hide_banner

//fail, can't find suitable output format for scale command, invalid argument .\ffmpeg -i input.mp4 -q:v 2 -vf select="eq(pict_type\,PICT_TYPE_I)" -vsync 0, scale=320:-1 thumb%07d.png -hide_banner

//fail .\ffmpeg -i input.mp4 -q:v 2 -vf scale=320:-1, -vf select="eq(pict_type\,PICT_TYPE_I)" -vsync 0 thumb%07d.png -hide_banner

I've tried many different things, moving commands, combining using commas etc... But I have not had any success at combining the get key-frames and scale commands. So how would I go about combining the get key-frames and scale commands so that it works?

thanks.


回答1:


The select and scale filters here make for a linear sequence of filters, so the are to be specified one after the other. See http://ffmpeg.org/ffmpeg-filters.html#Filtering-Introduction

So, you can use

ffmpeg -i in -vf "select='eq(pict_type\,PICT_TYPE_I)',scale=320:-1" -vsync 0 -q:v 2 out%07d.png

but the below command will be quicker, as it drops non-keyframes at the decoding stage.

ffmpeg -skip_frame nokey -i in -vf "scale=320:-1" -vsync 0 -q:v 2 out%07d.png


来源:https://stackoverflow.com/questions/59611299/how-do-i-capture-all-keyframes-and-scale-down-to-320px-wide

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!