ffmpeg - 使用 FFmpeg 旋转视频

标签 ffmpeg rotation video-processing

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

根据我的阅读,您需要使用的是 vfilter 选项。根据我的观察,它应该是这样的:

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

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

No such filter: 'rotate'
Error opening filters!

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

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.

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

最佳答案

顺时针旋转90:

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

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

0 = 90° counterclockwise and vertical flip (default)
1 = 90° clockwise
2 = 90° counterclockwise
3 = 90° clockwise and vertical flip

使用 -vf "transpose=2,transpose=2" 旋转 180 度。

确保您使用最新的 FFmpeg 版本 from here (静态构建可以正常工作)。

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

解决方案也是使用这个convenience script .

关于ffmpeg - 使用 FFmpeg 旋转视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3937387/

相关文章:

c++ - 如何在 OpenGL 中更改对象的旋转速率?

ios - CGAffineTransform 缩放和旋转

reactjs - 使用@mmfpeg React 连接多个视频时出现 "memory access out of bounds"错误

c++ - 为什么 MediaFoundation InitializeSinkWriter (SetInputMediaType) 只接受 WMV3 格式?

ios - 使用 CGAffineTransformTranslate 旋转后将图像移动到其原始维度空间

c# - 使用 OpenCV 检测越线人员

c - 如何从 C 中的图像目录创建视频

video - FFMPEG,播放器在编码后播放生涩的视频

video - 我可以使用 ffmpeg 或 ffprobe 获取 h.264 每帧的引用列表吗?

音频样本格式 s16p、ffmpeg 或音频编解码器错误?