joc*_*ull 395 ffmpeg rotation video-processing
我一直试图找出如何使用FFmpeg旋转视频.我正在处理以纵向模式拍摄的iPhone视频.我知道如何使用MediaInfo(优秀的库,顺便说一句)确定当前的旋转度,但我现在卡在FFmpeg上.
根据我的阅读,您需要使用的是vfilter选项.根据我的看法,它应该是这样的:
ffmpeg -vfilters "rotate=90" -i input.mp4 output.mp4
Run Code Online (Sandbox Code Playgroud)
但是,我不能让这个工作.首先,-vfilters不再存在,它现在只是-vf.其次,我收到此错误:
No such filter: 'rotate'
Error opening filters!
Run Code Online (Sandbox Code Playgroud)
据我所知,我有一个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.
Run Code Online (Sandbox Code Playgroud)
拥有vflip和hflip的选项非常棒,但他们只是不会让我到达我需要去的地方.我需要能够将视频至少旋转90度.270度也是一个很好的选择.旋转选项哪里去了?
小智 644
顺时针旋转90度:
ffmpeg -i in.mov -vf "transpose=1" out.mov
Run Code Online (Sandbox Code Playgroud)
对于转置参数,您可以传递:
0 = 90CounterCLockwise and Vertical Flip (default)
1 = 90Clockwise
2 = 90CounterClockwise
3 = 90Clockwise and Vertical Flip
Run Code Online (Sandbox Code Playgroud)
使用-vf "transpose=2,transpose=2"
180度.
确保你从这里使用最近的ffmpeg版本(静态构建将正常工作).
请注意,这将重新编码音频和视频部分.您通常可以通过使用来复制音频而无需触摸它-c:a copy
.要更改视频质量,请设置比特率(例如-b:v 1M
)或者如果您想要VBR选项,请查看H.264编码指南.
解决方案也是使用此便捷脚本.
Rod*_*olo 131
如果您不想重新编码视频并且您的播放器可以处理旋转元数据,您只需使用ffmpeg更改元数据中的旋转:
ffmpeg -i input.m4v -metadata:s:v rotate="90" -codec copy output.m4v
Run Code Online (Sandbox Code Playgroud)
rwi*_*ams 82
你试过transpose
了吗?喜欢(来自其他答案)
ffmpeg -i input -vf transpose=2 output
Run Code Online (Sandbox Code Playgroud)
如果您使用的是旧版本,则必须更新ffmpeg才能使用2011年10月添加的转置功能.
FFmpeg 下载页面提供静态构建,您可以直接执行而无需编译它们.
小智 19
我在搜索相同的答案时遇到了这个页面.现在已经有六个月的时间了,这个问题从那时起已经多次更新了版本.但是,我想为在这里遇到的其他人寻找此信息添加答案.
我正在使用这些存储库中的Debian Squeeze和FFmpeg版本.
ffmpeg的MAN页面说明了以下用法
ffmpeg -i inputfile.mpg -vf "transpose=1" outputfile.mpg
Run Code Online (Sandbox Code Playgroud)
关键是您不要使用度数变量,而是使用MAN页面中的预定义设置变量.
0=90CounterCLockwise and Vertical Flip (default)
1=90Clockwise
2=90CounterClockwise
3=90Clockwise and Vertical Flip
Run Code Online (Sandbox Code Playgroud)
Bij*_*lle 16
要顺时针旋转图片,您可以使用旋转滤镜,指示以弧度为单位的正角度.90度等于PI/2,您可以这样做:
ffmpeg -i in.mp4 -vf "rotate=PI/2" out.mp4
Run Code Online (Sandbox Code Playgroud)
对于逆时针方向,角度必须为负
ffmpeg -i in.mp4 -vf "rotate=-PI/2" out.mp4
Run Code Online (Sandbox Code Playgroud)
转置滤镜在90度时同样适用,但对于其他角度,这是更快或唯一的选择.
小智 12
ffmpeg -vfilters "rotate=90" -i input.mp4 output.mp4
Run Code Online (Sandbox Code Playgroud)
即使有最新的来源,也行不通
必须改变顺序:
ffmpeg -i input.mp4 -vf vflip output.mp4
Run Code Online (Sandbox Code Playgroud)
工作良好
小智 8
与最后提到的解决方案采用不同方法的另一个解决方案是检查您的相机驱动程序是否支持 v4l2 相机控制(这很常见)。
在终端中,只需输入:
v4l2-ctl -L
Run Code Online (Sandbox Code Playgroud)
如果您的相机驱动程序支持 v4l2 相机控件,您应该得到类似以下内容(下面的列表取决于您的相机驱动程序支持的控件):
contrast (int) : min=0 max=255 step=1 default=0 value=0 flags=slider
saturation (int) : min=0 max=255 step=1 default=64 value=64 flags=slider
hue (int) : min=0 max=359 step=1 default=0 value=0 flags=slider
white_balance_automatic (bool) : default=1 value=1 flags=update
red_balance (int) : min=0 max=4095 step=1 default=0 value=128 flags=inactive, slider
blue_balance (int) : min=0 max=4095 step=1 default=0 value=128 flags=inactive, slider
exposure (int) : min=0 max=65535 step=1 default=0 value=885 flags=inactive, volatile
gain_automatic (bool) : default=1 value=1 flags=update
gain (int) : min=0 max=1023 step=1 default=0 value=32 flags=inactive, volatile
horizontal_flip (bool) : default=0 value=0
vertical_flip (bool) : default=0 value=0
Run Code Online (Sandbox Code Playgroud)
如果你幸运的话它支持horizontal_flip和vertical_flip。
然后你需要做的就是设置horizo ntal_flip:
v4l2-ctl --set-ctrl horizontal_flip=1
Run Code Online (Sandbox Code Playgroud)
或者通过以下方式进行vertical_flip:
v4l2-ctl --set-ctrl vertical_flip=1
Run Code Online (Sandbox Code Playgroud)
然后您可以调用您的视频设备来捕获新视频(请参见下面的示例),并且视频将被旋转/翻转。
ffmpeg -f v4l2 -video_size 640x480 -i /dev/video0 -vcodec libx264 -f mpegts input.mp4
Run Code Online (Sandbox Code Playgroud)
当然,如果您需要处理已经存在的视频,那么此方法不是您正在寻找的解决方案。
这种方法的优点是我们在传感器级别翻转图像,因此驱动程序的传感器已经为我们提供了翻转的图像,这节省了应用程序(如 FFmpeg)任何进一步的和不必要的处理。
如果您收到"编解码器是实验性的但未启用实验性编解码器"错误,请使用以下命令:
ffmpeg -i inputFile -vf "transpose=1" -c:a copy outputFile
Run Code Online (Sandbox Code Playgroud)
我发生了一些带有aac音频的.mov文件.