使用ffmpeg生成视频缩略图而不会出现任何失真 [英] Use ffmpeg to generate video thumbnail without any distortion

查看:1965
本文介绍了使用ffmpeg生成视频缩略图而不会出现任何失真的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要从视频中获取 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆