使用ffmpeg输出具有正确宽高比的图像 [英] Output image with correct aspect with ffmpeg

查看:416
本文介绍了使用ffmpeg输出具有正确宽高比的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下属性的mkv视频(通过mediainfo获得):

I have a mkv video with the following properties (obtained with mediainfo):

Width                                    : 718 pixels
Height                                   : 432 pixels
Display aspect ratio                     : 2.35:1
Original display aspect ratio            : 2.35:1

我想在特定时间对其进行截图:

I'd like to take screenshots of it at certain times:

ffmpeg -ss 4212 -i filename.mkv -frames:v 1 -q:v 2 out.jpg

这将产生718x432 jpg图像,但是长宽比不正确(图像水平"压缩). AFAIK,输出图像应为1015 * 432(宽度=高度* DAR).这个计算正确吗?

This will produce a 718x432 jpg image, but the aspect ratio is wrong (the image is "squeezed" horizontally). AFAIK, the output image should be 1015*432 (with width=height * DAR). Is this calculation correct?

是否有一种方法可以使ffmpeg输出的所有视频的尺寸/AR正确(即没有硬编码"值)?我尝试使用setdar/setsar过滤器没有成功.

Is there a way to have ffmpeg output images with the correct size/AR for all videos (i.e. no "hardcoded" values)? I tried playing with the setdar/setsar filters without success.

出于好奇,尝试使用ffmpeg获取SAR和DAR会产生:

Also, out of curiosity, trying to obtain SAR and DAR with ffmpeg produces:

Stream #0:0(eng): Video: h264 (High), yuv420p(tv, smpte170m/smpte170m/bt709, progressive),
718x432 [SAR 64:45 DAR 2872:1215], SAR 155:109 DAR 55645:23544, 24.99 fps, 24.99 tbr, 1k tbn, 49.98 tbc (default)

2872/1215是2.363,因此该值与mediainfo报告的值略有不同.有人知道为什么吗?

2872/1215 is 2.363, so a slightly different value than what mediainfo reported. Anyone knows why?

推荐答案

不查看文件,无法诊断读数不同的原因,但是获得平方像素结果的通用方法是

Without looking at the file, can't diagnose the reason for the distinct readings, but the generic method to get a square pixel result is

ffmpeg -ss 4212 -i filename.mkv -vf scale=iw*sar:ih -frames:v 1 -q:v 2 out.jpg

这篇关于使用ffmpeg输出具有正确宽高比的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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