使用 FFmpeg 旋转视频 [英] Rotating videos with FFmpeg

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

问题描述

我一直在试图弄清楚如何使用 FFmpeg 旋转视频.我正在处理以纵向模式拍摄的 iPhone 视频.我知道如何使用 MediaInfo(优秀的库,顺便说一句)确定当前的旋转度数,但我现在坚持使用 FFmpeg.

据我所知,您需要使用的是 vfilter 选项.根据我所见,它应该是这样的:

ffmpeg -vfilters "rotate=90" -i input.mp4 output.mp4

但是,我无法让它发挥作用.首先,-vfilters 不再存在,它现在只是 -vf.其次,我收到此错误:

没有这样的过滤器:'旋转'打开过滤器时出错!

据我所知,我有一个 FFmpeg 的全选项版本.运行 ffmpeg -filters 显示:

过滤器:anull 将源不变地传递到输出.纵横比 设置帧纵横比.裁剪 将输入视频裁剪为 x:y:width:height.fifo 缓冲输入图像并在需要时发送它们.格式 将输入视频转换为指定的像素格式之一.hflip 水平翻转输入视频.noformat 强制 libavfilter 不使用任何指定的像素格式用于下一个过滤器的输入.null 将源不变地传递到输出.pad 将输入图像填充到 width:height[:x:y[:color]](默认 x 和 y:0,默认颜色:黑色).pixdesctest 测试像素格式定义.pixelaspect 设置像素纵横比.scale 将输入视频缩放到宽度:高度大小和/或转换 i法师格式.slicify 将输入视频的图像作为 multi 传递到下一个视频过滤器多片.unsharp 锐化或模糊输入视频.vflip 垂直翻转输入视频.buffer 缓冲视频帧,并使它们可以被 filterchai 访问n.color 提供统一颜色的输入,语法为:[color[:size[:ra]]]]]nullsrc 空视频源,从不返回图像.nullsink 对输入视频完全不做任何事情.

vfliphflip 的选项很棒,但它们无法让我到达我需要去的地方.我至少需要能够将视频旋转 90 度.270 度也是一个很好的选择.旋转选项去哪儿了?

解决方案

顺时针旋转 90 度:

ffmpeg -i in.mov -vf "transpose=1";out.mov

对于转置参数,您可以传递:

0 = 90CounterCLockwise 和垂直翻转(默认)1 = 90 顺时针2 = 90 逆时针3 = 90 顺时针和垂直翻转

使用 -vf "transpose=2,transpose=2" 180 度.

确保您使用最新的 ffmpeg 版本来自此处(静态构建可以正常工作).

请注意,这将重新编码音频和视频部分.您通常可以使用 -c:a copy 复制音频而无需触摸它.要更改视频质量,请设置比特率(例如使用 -b:v 1M)或查看 H.264 编码指南,如果您需要 VBR 选项.

一个解决方案也是使用这个便捷脚本.>

I have been trying to figure out how to rotate videos with FFmpeg. I am working with iPhone videos taken in portrait mode. I know how to determine the current degrees of rotation using MediaInfo (excellent library, btw) but I'm stuck on FFmpeg now.

From what I've read, what you need to use is a vfilter option. According to what I see, it should look like this:

ffmpeg -vfilters "rotate=90" -i input.mp4 output.mp4

However, I can't get this to work. First, -vfilters doesn't exist anymore, it's now just -vf. Second, I get this error:

No such filter: 'rotate'
Error opening filters!

As far as I know, I have an all-options-on build of FFmpeg. Running ffmpeg -filters shows this:

Filters:
anull            Pass the source unchanged to the output.
aspect           Set the frame aspect ratio.
crop             Crop the input video to x:y:width:height.
fifo             Buffer input images and send them when they are requested.
format           Convert the input video to one of the specified pixel formats.
hflip            Horizontally flip the input video.
noformat         Force libavfilter not to use any of the specified pixel formats
 for the input to the next filter.
null             Pass the source unchanged to the output.
pad              Pad input image to width:height[:x:y[:color]] (default x and y:
 0, default color: black).
pixdesctest      Test pixel format definitions.
pixelaspect      Set the pixel aspect ratio.
scale            Scale the input video to width:height size and/or convert the i
mage format.
slicify          Pass the images of input video on to next video filter as multi
ple slices.
unsharp          Sharpen or blur the input video.
vflip            Flip the input video vertically.
buffer           Buffer video frames, and make them accessible to the filterchai
n.
color            Provide an uniformly colored input, syntax is: [color[:size[:ra
te]]]
nullsrc          Null video source, never return images.
nullsink         Do absolutely nothing with the input video.

Having the options for vflip and hflip are great and all, but they just won't get me where I need to go. I need to the ability to rotate videos 90 degrees at the very least. 270 degrees would be an excellent option to have as well. Where have the rotate options gone?

解决方案

Rotate 90 clockwise:

ffmpeg -i in.mov -vf "transpose=1" out.mov

For the transpose parameter you can pass:

0 = 90CounterCLockwise and Vertical Flip (default)
1 = 90Clockwise
2 = 90CounterClockwise
3 = 90Clockwise and Vertical Flip

Use -vf "transpose=2,transpose=2" for 180 degrees.

Make sure you use a recent ffmpeg version from here (a static build will work fine).

Note that this will re-encode the audio and video parts. You can usually copy the audio without touching it, by using -c:a copy. To change the video quality, set the bitrate (for example with -b:v 1M) or have a look at the H.264 encoding guide if you want VBR options.

A solution is also to use this convenience script.

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

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