Rotating videos with FFmpeg
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.
Have you tried transpose
yet? Like (from the other answer)
ffmpeg -i input -vf transpose=2 output
If you are using an old version, you have to update ffmpeg if you want to use the transpose feature, as it was added in October 2011.
The FFmpeg download page offers static builds that you can directly execute without having to compile them.
如果您不想重新编码视频,并且您的播放器可以处理旋转元数据,则可以使用ffmpeg更改元数据中的旋转:
ffmpeg -i input.m4v -metadata:s:v rotate="90" -codec copy output.m4v
链接地址: http://www.djcxy.com/p/95150.html
上一篇: 跟踪OpenCV中连续帧的特征
下一篇: 用FFmpeg旋转视频