如何捕捉所有关键帧并缩小到320像素宽?

huangapple go评论131阅读模式
英文:

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

问题

我正在尝试使用ffmpeg从视频文件中输出所有关键帧,并将它们缩小到320像素宽,同时保持宽高比。

我知道我可以使用两个单独的命令来实现这一目标,但我正在尝试找到一种在一个命令中干净地完成的方法。

我已经成功地使用以下命令分别执行了每个步骤。

输出关键帧:

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

缩放图像:

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

我不会分享我尝试过的所有内容,但这里有三个组合它们失败的示例。

//失败,不仅仅是关键帧,还有缩放
.\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

//失败,无法找到适合缩放命令的输出格式,无效参数
.\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

//失败
.\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'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

得分: 1

以下是翻译好的部分:

选择和缩放滤镜使得一系列滤镜呈线性序列,因此它们需要依次指定。请参阅 http://ffmpeg.org/ffmpeg-filters.html#Filtering-Introduction

因此,您可以使用以下命令:

ffmpeg -i 输入文件 -vf "select='eq(pict_type,PICT_TYPE_I)',scale=320:-1" -vsync 0 -q:v 2 输出文件%07d.png

但下面的命令会更快,因为它在解码阶段删除了非关键帧。

ffmpeg -skip_frame nokey -i 输入文件 -vf "scale=320:-1" -vsync 0 -q:v 2 输出文件%07d.png
英文:

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

huangapple
  • 本文由 发表于 2020年1月6日 19:27:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/59611299.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定