The ni_quadra_ai_pre AI pre-processing provides a filter to do picture pre-processing by AI model. The pixel format and resolution depend on the AI model and the input of picture.
The filter takes a segm_32 object segmentation model as input, down to the AI module specified by the user. The imported model will be unfolded and initialized in memory. As for the segm32 model, the dimensions of the input and output are as defined. The segm32 model requires a tensor with custom designed and should match the input resolution.
The input frames can be SW/HW frames. The output frame must be HW frames.
Parameters
The following are the ni_quadra_ai_pre parameters:
nb
Specifies the AI model (segm32.nb) network binary file path including the file name. This field is required for the filter to work.
Supported Values | String |
|---|---|
Default | Null |
devid
Specifies the device index of card. This parameter should be set when the input is software frame.
Supported Values | Integer 0 |
|---|---|
Default | 0 |
mode
Specifies the AI processing mode. mode=0 means the AI model will process the whole YUV, while mode=1 means the AI model will only process Y channel and keep U and V unchanged. Users should specify network binary file according to the mode.
Supported Values |
|
|---|---|
Default | 0 |
keep_alive_timeout
Specifies a session keep alive timeout value. This is a periodic request/response between libxcoder and XCoder firmware that when timed out, terminates the session instance in the XCoder firmware.
Supported Values | Integer 0 to 100 |
|---|---|
Default | 10 |
buffer_limit
Whether to limit the number of output buffers. If enabled, the buffering count of the filter is its buffer pool size (default 4) plus encoding buffering count if its downstream is encoder. It is enabled by default in FFmpeg-n6.1, FFmpeg-n7.1, FFmpeg 7.1.3, FFmpeg-n8.0.1 and FFmpeg-n8.1.
Supported Values | Integer 0 to 8192 |
|---|---|
Default | 4 |
width
Specify the output frame width. For some nb model the input and output frame width is not same, in this case, the width should be set so that filter can’t know and check the output from AI engine.
Supported Values | Integer 0 to 8192 |
|---|---|
Default | -1 |
height
Specify the output frame height. For some nb model the input and output frame height is not same, in this case, the width should be set so that filter can’t know and check the output from AI engine.
Supported Values | Integer 0 to 8192 |
|---|---|
Default | -1 |
timeout
Specifies timeout value for processing one frame. This is the timeout checking in ffmpeg’s software. It reminds developers the AI processing may take too much time and should increase this timeout and all the keep_alive_timeout on the pipeline.
Supported Values | Integer 1 to 100 |
|---|---|
Default | 3 |
align_w
Specifies ai align width value for input frame. This parameter is used to set the padding of the boundary pixels of the input frame used for AI processing. Our ai_engine data processing is 128 byte aligned, so when the input stream is not 128 aligned, the last pixel of the input stream will be referenced backwards with an illegal value. Therefore, we can set this value to fill the pixels after the boundary with 0.
Ai_engin will reference 3 pixels backwards, the default value is set to 4.
Supported Values | Integer 0 to 8192 |
|---|---|
Default | 4 |
skip_ai_align
Specifies skip_ai_align value for processing one frame. Skip or do ai align.
Supported Values | Integer 0 and 1 |
|---|---|
Default | 1 |
The following example shows using the ni_quadra_ai_pre filter to do picture pre-processing on 1080p clip transcode.
ffmpeg -y -loglevel info -c:v h264_ni_quadra_dec -dec 0 -xcoder-params "out=hw" -i Dinner_1920x1080p30_300.h264 -vf ni_quadra_ai_pre=nb=usm_1080P_level1.nb -c:v h265_ni_quadra_enc -enc -1 -xcoder-params "RcEnable=1:bitrate=1000000" ai_1080p_300.h264
NOTE:
The ai_pre_process filter supports SW/HW input frames and HW output frames, and also has different modes. So, there are various combinations of parameters. The setting of these parameters mainly depends on the AI models.
The resolution of the input frame must match the input resolution of the AI model. If they do not match, report an “init” error.
If the resolutions of input frames and output frames are not the same, the width/height parameters must be used to specify the resolution of the output frames. For example, the input resolution of the AI model "hw_bicubic_network_binary.nb" is 1080p, and the output resolution is 720p.
Mode 0 is a normal mode. Mode 1, however, is a special mode that modifies only the Y channel of HW frames and must be used in conjunction with a specific AI model. For example, the AI model "network_binary_no_noise_ml.nb" modifies the Y channel of HW frames, while the U/V channels are transmitted through the FW.