FFmpeg视频的旋转rotate


ffmpeg命令目录


在视频的播放时间内,将视频旋转360°

在这里插入图片描述

//T为旋转一周的时长,如果为视频的时长,则旋转一圈,正好可以播放完
ffmpeg -i a3.mp4 -vf rotate=PI*2/T*t rotate8.mp4

rotate的第一个参数angle的单位是弧度
1°=π/180
360°=2π

例如将视频旋转90°,注意此种方式,并没有改变水平尺寸

ffmpeg -i a3.mp4 -vf rotate=PI/2 rotate9.mp4

Rotate完整的参数

Rotate video by an arbitrary angle expressed in radians.

The filter accepts the following options:

A description of the optional parameters follows.

angle, a
Set an expression for the angle by which to rotate the input video clockwise, expressed as a number of radians. A negative value will result in a counter-clockwise rotation. By default it is set to "0".

This expression is evaluated for each frame.

out_w, ow
Set the output width expression, default value is "iw". This expression is evaluated just once during configuration.

out_h, oh
Set the output height expression, default value is "ih". This expression is evaluated just once during configuration.

bilinear
Enable bilinear interpolation if set to 1, a value of 0 disables it. Default value is 1.

fillcolor, c
Set the color used to fill the output area not covered by the rotated image. For the general syntax of this option, check the (ffmpeg-utils)"Color" section in the ffmpeg-utils manual. If the special value "none" is selected then no background is printed (useful for example if the background is never shown).

Default value is "black".

The expressions for the angle and the output size can contain the following constants and functions:

n
sequential number of the input frame, starting from 0. It is always NAN before the first frame is filtered.

t
time in seconds of the input frame, it is set to 0 when the filter is configured. It is always NAN before the first frame is filtered.

hsub
vsub
horizontal and vertical chroma subsample values. For example for the pixel format "yuv422p" hsub is 2 and vsub is 1.

in_w, iw
in_h, ih
the input video width and height

out_w, ow
out_h, oh
the output width and height, that is the size of the padded area as specified by the width and height expressions

rotw(a)
roth(a)
the minimal width/height required for completely containing the input video rotated by a radians.

These are only available when computing the out_w and out_h expressions.
### 使用FFmpeg实现视频旋转 #### 命令行方法 对于简单的视频旋转需求,可以直接利用命令行操作。例如,要将输入视频顺时针旋转90度: ```bash ffmpeg -i input.mp4 -vf "transpose=1" output_rotated.mp4 ``` 这里`transpose=1`表示顺时针方向上的第一次变换,即向右转90度[^4]。 如果需要逆时针旋转,则应调整参数值为其他选项之一(具体取决于所需的角度变化): - `transpose=2`: 逆时针旋转90度并垂直翻转 - `transpose=3`: 顺时针旋转90度并水平翻转 - `transpose=0`: 仅交换宽度和高度而不做任何角度改变 另外一种方式是使用`rotate`滤镜来指定任意角度的旋转效果,比如下面的例子展示了如何让视频围绕中心点按给定弧度值进行旋转: ```bash ffmpeg -i input.mp4 -vf "rotate=PI/2" output_rotated.mp4 ``` 此命令中的`PI/2`代表&pi;的一半也就是直角转换成弧度制后的表达形式。 #### 编程接口集成 当希望在应用程序内部调用这些功能时,可以通过C/C++等语言结合Qt框架完成更复杂的应用场景构建。此时除了基本的编译配置之外还需要额外引入必要的库文件支持,如`avcodec`, `avformat`, `avutil`以及用于图像缩放处理的`spscale`组件[^2]。 ```cpp // 示例代码片段展示如何初始化FFmpeg环境并与Qt项目相结合 extern "C" { #include <libavcodec/avcodec.h> #include <libavformat/avformat.h> } int main(int argc, char *argv[]) { av_register_all(); // 注册所有可用解码器、编码器和其他组件 /* ... */ } ``` 上述设置完成后便可以在程序逻辑里嵌入相应的API调用来执行具体的媒体流处理任务了。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值