使用ffmpeg生成视频缩略图而不会出现任何失真 [英] Use ffmpeg to generate video thumbnail without any distortion
问题描述
要从视频中获取 200x100
缩略图,我会 ffmpeg -ss 100 -i /tmp/video.mp4 -frames:v 1 -s 200x100 image.jpg
。但如果源视频与 200x100
的宽高比不同,则缩略图会变形(拉伸或压扁,水平或垂直)并且看起来很糟糕。
To get a 200x100
thumbnail from a video, I do ffmpeg -ss 100 -i /tmp/video.mp4 -frames:v 1 -s 200x100 image.jpg
. But if the source video isn't in the same aspect ratio as 200x100
, the thumbnail gets distorted (either stretched or squished, horizontally or vertically) and it looks bad.
有没有办法 ffmpeg
可以找出例如 500x200
视频 100px
太宽,从右边删除 50px
, 50px
从左边开始制作视频 400x200
?因为 400x200
与 200x100
具有相同的宽高比,缩略图将没有失真。
Is there a way that ffmpeg
can figure out for example that a 500x200
video is 100px
too wide, and remove 50px
from the right and 50px
from the left, making the video 400x200
? And because 400x200
is the same aspect ratio as 200x100
, the thumbnail would have no distortion.
我知道还有其他工具可以对 ffmpeg
生成的缩略图执行此操作,但我更喜欢在<$ c内执行此操作$ c> ffmpeg 并且不必再次处理缩略图。
I know there are other tools that can do this to the thumbnails generated by ffmpeg
, but I'd prefer doing it within ffmpeg
and not having to process the thumbnails again.
推荐答案
你可以使用< 规模过滤器中的code> force_original_aspect_ratio 选项。
You can use the force_original_aspect_ratio
option in the scale filter.
ffmpeg -ss 100 -i /tmp/video.mp4 -frames:v 1 -q:v 2 -vf "scale=200:100:force_original_aspect_ratio=increase,crop=200:100" image.jpg
这篇关于使用ffmpeg生成视频缩略图而不会出现任何失真的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!