使用FFMPEG裁剪视频时出错 [英] Error when cropping video using FFMPEG

查看:123
本文介绍了使用FFMPEG裁剪视频时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:是否有一个适用于所有视频的FFMPEG裁剪过滤器,包括(但不限于)856x480、640x480和1280x720?

Question: Is there a single FFMPEG crop filter that will work for all videos, including (but not limited to): 856x480, 640x480, and 1280x720?

我们有一个视频处理系统(使用DirectShow),并且使用MJPEG编解码器,送入该系统的所有视频都必须为16:9.我们使用以下ffmpeg命令将源视频转换为MJPEG,缩放像素以使其变为正方形,然后将其裁剪为16:9的宽高比.这对于大多数输入视频都非常有用,而输出正是我们想要的.

We have a video processing system (uses DirectShow), and all videos fed into this system must be 16:9 using the MJPEG codec. 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. 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"

但是,当我们使用分辨率为856x480的输入视频时,会出现以下错误:

However, when we use an input video with a resolution of 856x480, we get the following error:

[Parsed_crop_1 @ 0000000004615720]无效,太大或无效宽度"852"或高度"480"的大小

[Parsed_crop_1 @ 0000000004615720] Invalid too big or non positive size for width '852' or height '480'

我尝试了另一个作物过滤器,该作物过滤器在计算中使用输入高度而不是输入宽度,并且可以使用856x480

I tried a different crop filter that uses the input height in the calculation instead of input width, and it works with 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"

但是,不能不能与其他16:9(1280x720)或4:3(640x480)格式的源视频一起使用.是否有一个裁切命令可以在所有视频上使用?

However this does not work with other source videos in 16:9 (1280x720) or 4:3 (640x480) format. Is there a single crop command that will work on all videos?

推荐答案

您需要条件表达式:

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

dar 是显示宽高比,即 iw * sar/ih

这篇关于使用FFMPEG裁剪视频时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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