文章目录
表达式
表达式 | 描述 |
---|---|
abs(x) | 返回x的绝对值. |
acos(x) | 计算x反余弦 . |
asin(x) | 计算x的反正弦. |
atan(x) | 计算x反正切. |
between(x, min, max) | 判断min<=x<=max是否成立,成立返回1,否则返回0. |
ceil(expr) | 返回大于expr的最接近整数,例如"ceil(1.5)" 返回"2.0". |
clip(x, min, max) | Return the value of x clipped between min and max. |
cos(x) | 计算x的余弦. |
cosh(x) | 计算x的双余弦. |
eq(x, y) | 如果x==y返回1,否则为0 otherwise. |
exp(x) | 计算指数x,(底数为e,即计算欧拉数(Euler’s number)) |
floor(expr) | 返回不大于expr的整数,例如 “floor(-1.5)” 为 “-2.0”. |
gauss(x) | 计算x的高斯(Gauss )函数值,即计算(-xx/2) / sqrt(2PI). |
gcd(x, y) | 返回x和y的最大公约数,如果x和y为0或者任意数小于0则行为未定义。 |
gt(x, y) | 返回判断x>y的结果,符合则为1,否则为0 |
gte(x, y) | 返回判断x>=y的结果,符合则为1,否则为0 |
hypot(x, y) | 求长为x,宽为y的斜边长度 |
if(x, y) | 判断x值,如果x值为非0,则返回y,否则返回0 |
if(x, y, z) | 判断x值,如果x值为真(非0),则返回y,否则返回z. |
ifnot(x, y) | 判断x值,如果x值为0,则返回y,否则返回0 |
ifnot(x, y, z) | 判断x值,如果x值为0,则返回y,否则返回z. |
isinf(x) | 如果x值是正负无穷则返回1.0.否则返回0.0 |
isnan(x) | 如果x是NAN则返回1.0,否则返回0.0 |
ld(var) | 加载预订的内部变量var对应值,其中值是利用st(var, expr)存储的 |
log(x) | 计算x的自然对数值 |
lt(x, y) | 返回x<y判断式值,符合为1,否则为0 |
lte(x, y) | 返回x<=y判断式值,符合为1,否则为0 |
max(x, y) | 返回x和y中的更大的值 |
min(x, y) | 返回x和y中的更小的值 |
mod(x, y) | 计算x%y |
not(expr) | 如果expr==0则返回1,否则返回0 |
pow(x, y) | 计算"(x)^(y)". |
print(t) | 打印日志 |
print(t, l) | 以日志层次l打印t,如果l没有定义则采用当前默认日志层次,返回打印内容。 |
random(x) | 返回一个0.0-1.0间的随机数,x是一个随机数种子。 |
root(expr, max) | 对于不同的输入计算表达式expr的值,直到max输入值。即依次取ld(x),x的值为0…max,把ld(x)值作为参数计算expr值,表达式expr必须是一个连续函数,否则结果不定。ld(0)被用作expr表达式的参数,所以表达式可以依据不同的值计算多次。 |
sin(x) | 计算x的正弦 |
sinh(x) | 计算x的双曲正弦 |
sqrt(expr) | 计算x的平方根。相当于 “(expr)^.5”. |
squish(x) | 计算 1/(1 + exp(4*x)). |
st(var, expr) | 对var变量在内部存储一个expr值,供以后使用,var范围为0-9.注意这些变量当前不能在表达式间共享 |
tan(x) | 返回x的正切. |
tanh(x) | 计算x的双曲正切 |
taylor(expr, x) taylor(expr, x, id) | 计算泰勒(Taylor)级数值。给出表达式(ld(id))在0阶的导数函数,即taylor(expr,x)=taylor(expr,x,0),如果级数不收敛,则结果是不确定的。ld(id)用来表示expr的导数阶,这意味着对给定的表达式,输入不同的值可以通过ld(id)进行多次计算。这里我们假定不是预设的0阶。注意当你用一个Y值替代默认的0时,相当于计算 taylor(expr, x-y) |
time(0) | 返回当前时间,单位为秒 |
trunc(expr) | 返回expr最接近的(向0)整数,如"trunc(-1.5)" 值为 “-1.0”. |
while(cond, expr) | 当cond不为0时循环执行expr,直至cond为0 |
The following constants are available:
参数 | 描述 |
---|---|
PI | area of the unit disc, approximately 3.14 |
E | exp(1) (Euler’s number), approximately 2.718 |
PHI | golden ratio (1+sqrt(5))/2, approximately 1.618 |
滤镜效果
zoompan
放大和平移效果
参数 | 说明 |
---|---|
zoom, z | Set the zoom expression. Range is 1-10. Default is 1. |
x / y | Set the x and y expression. Default is 0. |
d | Set the duration expression in number of frames. This sets for how many number of frames effect will last for single input image. |
s | Set the output image size, default is ’hd720’. |
fps | Set the output frame rate, default is ’25’. |
in_w, iw | Input width. |
in_h, ih | Input height. |
out_w, ow | Output width. |
out_h, oh | Output height. |
in | Input frame count. |
on | Output frame count. |
in_time, it | The input timestamp expressed in seconds. It’s NAN if the input timestamp is unknown. |
out_time, time, ot | The output timestamp expressed in seconds. |
x / y | Last calculated ’x’ and ’y’ position from ’x’ and ’y’ expression for current input frame. |
px / py | ’x’ and ’y’ of last output frame of previous input frame or 0 when there was not yet such frame (first input frame). |
zoom | Last calculated zoom from ’z’ expression for current input frame. |
pzoom | Last calculated zoom of last output frame of previous input frame. |
duration | Number of output frames for current input frame. Calculated from ’d’ expression for each input frame. |
pduration | number of output frames created for previous input frame |
a | Rational number: input width / input height |
sar | sample aspect ratio |
dar | display aspect ratio |
- zoom in up to 1.5x and pan at same time to some spot near center of picture (效果卡顿,不优秀)
ffmpeg \
-i photo.jpg \
-vf "zoompan=z='min(zoom+0.0015,1.5)':d=125:x='if(gte(zoom,1.5),x,x+1/a)':y='if(gte(zoom,1.5),y,y+1)'" \
-y output.mp4
- Zoom in up to 1.5x and pan always at center of picture:(抖动,不优秀)
ffmpeg \
-i photo.jpg \
-vf "zoompan=z='min(zoom+0.0015,1.5)':d=125:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)'" \
-y output.mp4
- Same as above but without pausing:(废话,d=1,当然不暂停,也许我没看懂,帧数多了依然抖动)
ffmpeg \
-i photo.jpg \
-vf "zoompan=z='min(max(zoom,pzoom)+0.0015,1.5)':d=1:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)'" \
-y output.mp4
- Zoom in 2x into center of picture only for the first second of the input video:
ffmpeg \
-i photo.jpg \
-vf "zoompan=z='if(between(in_time,0,1),2,1)':d=1:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)'" \
-y output.mp4
中心视距由远及近
ffmpeg \
-i photo.jpg \
-vf "zoompan=z='min(zoom+0.0015,1.5)':d=125:" \
-y output.mp4
中心视距由近及远
ffmpeg \
-i photo.jpg \
-vf "zoompan='if(lte(zoom,1.0),1.5,max(1.001,zoom-0.0015))':d=125:" \
-y output.mp4
水平视距从左到右
ffmpeg \
-i photo.jpg \
-vf "zoompan='1.5':x='if(lte(on,-1),(iw-iw/zoom)/2,x+3)':y='if(lte(on,1),(ih-ih/zoom)/2,y)':d=125" \
-y output.mp4
水平视距从右到左
ffmpeg \
-i photo.jpg \
-vf "zoompan='1.5':x='if(lte(on,1),(iw/zoom)/2,x-3)':y='if(lte(on,1),(ih-ih/zoom)/2,y)':d=125" \
-y output.mp4
垂直视距从上到下
ffmpeg \
-i photo.jpg \
-vf "zoompan='1.5':x='if(lte(on,1),(iw-iw/zoom)/2,x)':y='if(lte(on,-1),(ih-ih/zoom)/2,y+2)':d=125" \
-y output.mp4
垂直视距从下到上
ffmpeg \
-i photo.jpg \
-vf "zoompan='1.5':x='if(lte(on,1),(iw-iw/zoom)/2,x)':y='if(lte(on,1),(ih/zoom)/2,y-2)':d=125" \
-y output.mp4
rotate
使用弧度表示的任意角度随意旋转视频。
参数 | 描述 |
---|---|
angle, a | 弧度制的正值表达式将会让视频顺时针旋转,负值会让视频逆时针旋转,默认为0(补充:1°=π/180 360°=2π) |
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.
顺时针旋转 PI/6 弧度
ffmpeg \
-i input.mp4 \
-vf "rotate=PI/6'" \
-y -t 5 output.mp4
逆时针旋转 PI/6 弧度
ffmpeg \
-i input.mp4 \
-vf "rotate=-PI/6'" \
-y -t 5 output.mp4
顺时针旋转 45 度
ffmpeg \
-i input.mp4 \
-vf "rotate=45*PI/180" \
-y -t 5 output.mp4
从 PI/3 开始,已恒定的角度旋转
官网给的时段 T,给替换了视频的总长度 3
ffmpeg \
-i input.mp4 \
-vf "rotate=PI/3+2*PI*t/3" \
-y -t 5 output.mp4
使输入视频摆动,周期为T秒,振幅为弧度A
ffmpeg \
-i input.mp4 \
-vf "rotate=1*sin(2*PI/3*t)" \
-y -t 5 output.mp4
让输出视频完整显示
ffmpeg \
-i input.mp4 \
-vf "rotate='2*PI*t:ow=hypot(iw,ih):oh=ow'" \
-y -t 5 output.mp4
旋转视频,减小输出大小,这样就不会显示任何背景
官网没测试成功,提示宽度不能被 2 整除,应该是素材不一样,也没关系,理解就好,目的就是取旋转的最小的宽度,然后旋转过程中不显示背景,c = none
rotate=2*PI*t:ow='min(iw,ih)/sqrt(2)':oh=ow:c=none
ffmpeg \
-i input.mp4 \
-vf "rotate=2*PI*t:ow='min(iw,ih)':oh=ow:c=none" \
-y -t 5 output.mp4
错误:
Q: width not divisible by 2 (255x255)
A: 宽度不能被 2 整除