FFMpeg zoompan 镜头聚焦和移动走位

案例

原始图片

bash 复制代码
# 输出帧数,默认25帧/秒,25*4 代表4秒
# s=1280x80 # 输出视频比例,可以设置和输入图片大小一致
# zoom+0.002 表示每帧放大的倍数,下面代码是25帧/每秒 * 4秒,共1000帧
# 最终是 0.002*25*4 = 0.2,最终是放大1.2倍
ffmpeg -i "./sdout/1.jpg" \
-filter_complex \
"zoompan=z='zoom+0.002':d=25*4:s=600x380" \
out.gif

只是改变Z坐标的话,图片将会从左上角开始变化

也可以指定x,y,(默认值是0)

如果想缩放到图片右边,可以指定 x=iw-iw/zoom ,图片的宽-缩放后的宽

如果想缩放到图片底部,指定 y=ih-ih/zoom

如果想缩小图片,需要初始化图片尺寸,比如 z='if(eq(on,1),1.2,zoom-0.002)

bash 复制代码
ffmpeg -i "./sdout/1.jpg" \
-filter_complex \
"zoompan=x='iw-iw/zoom':y='ih-ih/zoom':z='if(eq(on,1),1.2,zoom-0.002)':d=25*4:s=600x338" \
out1.gif

bash 复制代码
# 如果zoom <= 1.0, z=1.5 否则 z= (1.001 和 zoom-0.0015)中大的
# 最终效果就是: 从 1.5 倍数缩小到 1.001

ffmpeg -i "./sdout/1.jpg" \
-filter_complex \
"zoompan=z='if(lte(zoom,1.0),1.5,max(1.001,zoom-0.0015))':d=25*4:s=600x380" \
out2.gif

聚焦中心点

bash 复制代码
# 聚焦到图片center中心点,时长4秒
ffmpeg -i "./sdout/1.jpg" \
-filter_complex \
"zoompan=x='iw/2*(1-1/zoom)':y='ih/2*(1-1/zoom)':z='zoom+0.002':d=25*4:s=600x338" \
out3.gif

# zoompan拆解
zoompan=
	x='iw/2*(1-1/zoom)': # iw/2 代表要聚焦的x轴,zoom = 下面放大的比例
	y='ih/2*(1-1/zoom)': # ih/2 代表要聚焦的y轴
	z='2': # 聚焦放大的比例,这里代表2倍
	d=25*4: # 输出帧数,默认25帧/秒,25*4 代表4秒
	s=640x360 # 输出视频比例,可以设置和输入图片大小一致

参数

bash 复制代码
# 以下是命令参数
zoom, z  放大倍数,1到10,默认1
x,y    坐标,默认0
d    总帧数,默认90
s    输出图片尺寸,默认hd720
fps    帧率,默认25

# 以下是参数里的常量
in_w, iw    输入宽
in_h, ih    输入高
out_w, ow    输出宽
out_h, oh    输出高
in    输入帧数
on    输出帧数
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    上一帧 z 值
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

表达式

Expression Evaluation - FFmpeg

bash 复制代码
# x,y 中取大值
max(x, y)


# x <= y 返回 1, 否则返回 0
lte(x, y)

参考:

FFmpeg滤镜效果--镜头聚焦和移动走位 - 知乎

FFmpeg Filters Documentation

Ken Burns Effect Slideshows with FFMPeg | mko.re

相关推荐
daidaidaiyu11 小时前
FFmpeg 关键的结构体
c++·ffmpeg
扶尔魔ocy20 小时前
【QT window】ffmpeg实现录音功能之无损格式--PCM
ffmpeg·pcm
止礼1 天前
FFmpeg8.0.1 源代码的深入分析
ffmpeg
小曾同学.com1 天前
音视频中的“透传”与“DTS音频”
ffmpeg·音视频·透传·dts
vivo互联网技术1 天前
数字人动画云端渲染方案
前端·ffmpeg·puppeteer·web3d
止礼1 天前
FFmpeg8.0.1 编解码流程
ffmpeg
qs70161 天前
c直接调用FFmpeg命令无法执行问题
c语言·开发语言·ffmpeg
止礼1 天前
FFmpeg8.0.1 Mac环境 CMake本地调试配置
macos·ffmpeg
简鹿视频2 天前
视频转mp4格式具体作步骤
ffmpeg·php·音视频·实时音视频