简体   繁体   English

使用FFMPEG裁剪视频时出错

[英]Error when cropping video using FFMPEG

Question : Is there a single FFMPEG crop filter that will work for all videos, including (but not limited to): 856x480, 640x480, and 1280x720? 问题 :是否有一个适用于所有视频的FFMPEG裁剪过滤器,包括(但不限于)856x480、640x480和1280x720?

We have a video processing system (uses DirectShow), and all videos fed into this system must be 16:9 using the MJPEG codec. 我们有一个视频处理系统(使用DirectShow),并且使用MJPEG编解码器输入到该系统的所有视频必须为16:9。 We use the following ffmpeg command to convert the source videos into MJPEG, scale the pixels to make them square, and then crop them to a 16:9 aspect ratio. 我们使用以下ffmpeg命令将源视频转换为MJPEG,缩放像素以使其变为正方形,然后将其裁剪为16:9的宽高比。 This works great for most input videos, and the output is exactly what we want. 这对于大多数输入视频都非常有用,而输出正是我们想要的。

ffmpeg -i "1280x720input.mp4" -filter:v "scale=iw*sar:ih,crop=iw:iw/16*9" -codec:v mjpeg -q:v 2 -codec:a pcm_s16le -r 30 -y "output.avi"

However, when we use an input video with a resolution of 856x480, we get the following error: 但是,当我们使用分辨率为856x480的输入视频时,会出现以下错误:

[Parsed_crop_1 @ 0000000004615720] Invalid too big or non positive size for width '852' or height '480' [Parsed_crop_1 @ 0000000004615720]宽度'852'或高度'480'的尺寸太大或非正数无效

I tried a different crop filter that uses the input height in the calculation instead of input width, and it works with 856x480 我尝试了另一种作物过滤器,该作物过滤器在计算中使用输入高度而不是输入宽度,并且它适用于856x480

ffmpeg -i "856x480input.mp4" -filter:v "scale=iw*sar:ih,crop=ih*16/9:ih" -codec:v mjpeg -q:v 2 -codec:a pcm_s16le -r 30 -y "output.avi"

However this does not work with other source videos in 16:9 (1280x720) or 4:3 (640x480) format. 然而,这并不在16与其他源的视频工作:9(1280×720)或4:3(640×480)的格式。 Is there a single crop command that will work on all videos? 是否有单个裁剪命令适用于所有视频?

You need conditional expressions: 您需要条件表达式:

crop='if(gte(dar,16/9),ih*16/9,iw)':'if(gte(dar,16/9),ih,iw*9/16)'

dar is the display aspect ratio ie iw * sar / ih dar是显示宽高比,即iw * sar / ih

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM