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

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

问题描述

我一直试图找出如何用FFmpeg旋转视频。我正在使用以纵向模式拍摄的iPhone视频。我知道如何使用 MediaInfo (优秀的图书馆,btw)确定当前的旋转度,但现在我被困在FFmpeg上。 / p>

从我所看到的,您需要使用的是一个 vfilter 选项。根据我看到的,它应该是这样的:

  ffmpeg -vfiltersrotate = 90-i input.mp4输出.mp4 

但是,我无法让这个工作。首先, -vfilters 不再存在,现在只是 -vf 。第二,我得到这个错误:

 没有这样的过滤器:'rotate'
打开过滤器错误!

据我所知,我有一个全选择的FFmpeg构建。

  b anull将源传递给输出。 
aspect设置框架宽高比。
裁剪将输入视频裁剪为x:y:width:height。
fifo缓冲区输入图像并在请求时发送它们。
格式将输入视频转换为指定像素格式之一。
hflip水平翻转输入视频。
noformat强制libavfilter不要使用任何指定的像素格式
作为下一个过滤器的输入。
null将源传递给输出。
pad将图像输入宽度:height [:x:y [:color]](默认x和y:
0,默认颜色:黑色)。
pixdesctest测试像素格式定义。
pixelaspect设置像素长宽比。
scale将输入视频缩放为width:height size和/或转换i
mage格式。
sliceify将输入视频的图像传递到下一个视频过滤器,作为多
的片段。
反锐化锐化或模糊输入视频。
vflip垂直翻转输入视频。
缓冲区缓冲区视频帧,并使其可访问filterchai
n。
颜色提供均匀的彩色输入,语法是:[color [:size [:ra
te]]]
nullsrc空的视频源,从不返回图像。
nullsink输入视频完全没有。

选择 vflip hflip 是伟大的和所有,但他们只是不会让我在哪里我需要去。我至少需要旋转视频90度的能力。 270度将是一个很好的选择。

解决方案

顺时针旋转90:

  ffmpeg -i in.mov -vftranspose = 1out.mov 

对于转置参数,您可以通过:

  0 = 90CounterCLockwise和垂直翻转(默认)
1 = 90Clockwise
2 = 90CounterClockwise
3 = 90Clockwise和Vertical Flip

使用

确保使用最近的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天全站免登陆