5. Filter

本章详细描述硬件支持的FFmpeg filter的参数及使用方法。

可以根据帮助文档查看当前版本的具体参数,使用方法如下:

ffmpeg -h filter=scale_metax

其中scale_metax为filter名称,可以替换成其他filter。

5.1. scale_metax

该filter用于转换图像格式和分辨率。支持的参数,参见表 5.1

表 5.1 scale_metax参数

参数

说明

w

输出的宽(默认iw)

h

输出的高(默认ih)

format

输出的格式(默认为输入格式)

in_left

输入图像中有效矩形的左上角横坐标(默认0)

in_top

输入图像中有效矩形的左上角纵坐标(默认0)

in_right

输入图像中有效矩形的右下角横坐标(默认iw)

in_bottom

输入图像中有效矩形的右下角纵坐标(默认ih)

out_left

输出图像中有效矩形的左上角横坐标(默认0)

out_top

输出图像中有效矩形的左上角纵坐标(默认0)

out_right

输出图像中有效矩形的右下角横坐标(默认ow)

out_bottom

输出图像中有效矩形的右下角纵坐标(默认ow)

flags

选择插值算法,可选值sync,blur,bicubic,bilinear(默认值)

window_size

窗口size,默认3(3*3),可选3、5

使用示例

host模式

ffmpeg -c:v h264_mxvid -i 1920x1080_24fps_h264_mm01.mp4 -vf hwupload_metax,scale_metax=w=960:h=540:format=yuv420p,hwdownload -c:v hevc_mxenc -y output.mp4
ffmpeg -c:v h264_mxvid -i 1920x1080_24fps_h264_mm01.mp4 -vf hwupload_metax,scale_metax_bsh=w=960:h=540:format=yuv420p,hwdownload -c:v hevc_mxenc -y output.mp4 //速度快,适用于缩放的宽高和原视频很接近

device模式

ffmpeg -hwaccel metax -hwaccel_output_format metax -c:v h264_mxvid -i 1920x1080_24fps_h264_mm01.mp4 -vf scale_metax=w=640:h=320:format=yuv420p -c:v hevc_mxenc -y output_device_scale.mp4

5.2. scale_metax_bsh

该filter用于转换图像格式和分辨率,速度较快。支持的参数,参见表 5.2

表 5.2 scale_metax_bsh参数

参数

说明

w

输出的宽(默认iw)

h

输出的高(默认ih)

format

输出的格式(默认为输入格式)

in_left

输入图像中有效矩形的左上角横坐标(默认0)

in_top

输入图像中有效矩形的左上角纵坐标(默认0)

in_right

输入图像中有效矩形的右下角横坐标(默认iw)

in_bottom

输入图像中有效矩形的右下角纵坐标(默认ih)

out_left

输出图像中有效矩形的左上角横坐标(默认0)

out_top

输出图像中有效矩形的左上角纵坐标(默认0)

out_right

输出图像中有效矩形的右下角横坐标(默认ow)

out_bottom

输出图像中有效矩形的右下角纵坐标(默认ow)

使用示例

host模式

ffmpeg -c:v h264_mxvid -i 1920x1080_24fps_h264_mm01.mp4 -vf hwupload_metax,scale_metax_bsh=w=960:h=540:format=yuv420p,hwdownload -c:v hevc_mxenc -y output.mp4

device模式

ffmpeg -hwaccel metax -hwaccel_output_format metax -c:v h264_mxvid -i 1920x1080_24fps_h264_mm01.mp4 -vf scale_metax_bsh=w=640:h=320:format=yuv420p -c:v hevc_mxenc -y output_device_scale.mp4

5.3. overlay_metax

该filter用于图像叠加/融合。支持的参数,参见表 5.3

表 5.3 overlay_metax参数

参数

说明

x

覆盖位置(x,y)中的x,默认0

y

覆盖位置(x,y)中的y,默认0

b

是否融合,默认0,不融合

使用示例

host模式

ffmpeg -c:v h264_mxvid -i 1920x1080_24fps_h264_mm01.mp4 -i 001_176x144_I420_b.jpeg -filter_complex "[0:v]hwupload_metax[base],[1:v]hwupload_metax[overlay],[base][overlay]overlay_metax=x=20:y=20" -c:v h264_mxenc -y output_jpeg.mp4

device模式

ffmpeg -hwaccel metax -hwaccel_output_format metax -c:v h264_mxvid -i 1920x1080_24fps_h264_mm01.mp4 -i 001_176x144_I420_b.jpeg -filter_complex "[0:v]scale_metax=w=960:h=540[base],[1:v]hwupload_metax[overlay],[base][overlay]overlay_metax=x=10:y=10" -c:v hevc_mxenc -y output_jpeg.mp4
ffmpeg -hwaccel metax -hwaccel_output_format metax -c:v h264_mxvid -i 1920x1080_24fps_h264_mm01.mp4 -i 001_176x144_I420_b.jpeg -filter_complex "[1:v]hwupload_metax[overlay],[0:v][overlay]overlay_metax=x=10:y=10" -c:v hevc_mxenc -y output_jpeg.mp4

5.4. drawbox_metax

该filter用于在图像上画框。支持的参数,参见表 5.4

表 5.4 drawbox_metax参数

参数

说明

x

画框的左上角横坐标,默认0

y

画框的左上角纵坐标,默认0

w/width

框的宽,默认0

h/height

框的高,默认0

c/color

框的颜色,默认black

t/thickness

框的厚度,默认3

使用示例

device模式

ffmpeg -hwaccel metax -hwaccel_output_format metax -c:v h264_mxvid -i 1920x1080_24fps_h264_mm01.mp4 -vf drawbox_metax=x=300:y=300:w=480:h=270:color=pink:t=2 -c:v hevc_mxenc -y output_device_drawbox.mp4

5.5. crop_metax

该filter用于裁剪图像。支持的参数,参见表 5.5

表 5.5 crop_metax参数

参数

说明

w/out_w

输出图像的宽,默认iw

h/out_h

输出图像的高,默认ih

x

裁剪时左上角横坐标,默认为(in_w-out_w)/2

y

裁剪时左上角纵坐标,默认为(in_h-out_h)/2

使用示例

device模式

ffmpeg -hwaccel metax -hwaccel_output_format metax -c:v h264_mxvid -i 1920x1080_24fps_h264_mm01.mp4 -vf crop_metax=w=960:h=540:x=480:y=270 -c:v hevc_mxenc -y output_device_crop.mp4

5.6. hwupload_metax

该filter用于将图像从系统内存拷贝到设备内存,和其他filter一起使用。支持的参数参见表 5.6

表 5.6 hwupload_metax参数

参数

说明

device

硬件卡编号,默认值为0

-vf "hwupload_metax=device=1"