Attention

This version of the SDK has been superseded by the latest release of the SDK.

FFmpeg Tutorials

This page provides tutorials on how to use FFmpeg with the AMD AMA Video SDK. The complete reference guide for the FFmpeg version included in the AMD AMA Video SDK can be found here.

The tutorials break down the commands, starting with simple decode, scale and encode pipelines. The tutorials end with different varieties of full transcode pipelines.

Environment Setup

  1. The AMD AMA Video SDK version of FFmpeg, Gstreamer and XMA applications can be found in the /opt/amd/ama/ma35/bin folder of your system. If this folder is not present, install the required packages:

    See On Premises

  2. Configure the environment to use the AMD AMA Video SDK. This a mandatory step for all applications:

    source /opt/amd/ama/ma35/scripts/setup.sh
    

The setup script exports important environment variables and ensures proper execution environment for AMD AMA Video SDK.

Sourcing the setup script should be performed each time you open a new terminal on your system. This is required for the environment to be correctly configured.


Simple FFmpeg Examples

Some of the examples read or write RAW files from disk (encode-only or decode-only pipelines). There is a chance that due to the massive bandwidth required for operating on these RAW files, you will notice a drop in FPS; this is not due to the AMD AMA Video SDK but the disk speeds. We recommend reading/writing from /dev/shm which is a RAM disk.

In the following sections, description of command line options is done in an accumulative manner, i.e., previously described options are not explained further.

Decode Only

This example accepts a clip that is already encoded in H.264, and will decode the file into a RAW format and save it to disk.

Command Line:

ffmpeg -y -hwaccel ama -c:v h264_ama -out_fmt nv12 -i <INPUT> \
 -vf hwdownload,format=nv12 -f rawvideo /tmp/dec_out.nv12

Explanation of the flags:

  • ffmpeg

    • The ffmpeg application, which is provided by AMD, and moved to the top of the PATH when you sourced the setup.sh script

  • hwaccel ama

    • Instructs FFmpeg to use accelerated plugins provided by AMD AMA Video SDK

  • -out_fmt nv12

    • Specifies nv12 output format for the decoded video. Note that this option has to be specified twice: 1) To convert from the internal buffer format to nv12 in the decoder and 2) To convert when transferring to the host.

  • -f rawvideo

    • This signifies that the video is in a raw format, without container or other metadata/information about the clip

  • -c:v h264_ama

    • Declares the decoder's codec for video (as opposed to, e.g., audio -c:a ac3) is the hardware-accelerated H.264 decoder

  • -i <INPUT>

    • The input file to be transcoded

  • -vf hwdownload

    • Internally, the decoder operates on AMD AMA Video SDK type buffers to improve performance. To convert back to a host-buffer, you must execute this filter.

  • -y

    • Enable overwrite without prompting the user if they're sure

  • /tmp/dec_out.yuv

    • The decoder will save the file to the path above

Encode Only

This example accepts a RAW 1080p60 clip in YUV420 format. It will pass the clip to the encoder to produce an AV1 encoded MP4 output with a target bitrate of 5Mbps and saves it to disk. The command uses the default VQ setting. See FFmpeg Video Quality for details.

Command Line:

ffmpeg -re -hwaccel ama -f rawvideo -s 1920x1080 -framerate 60 -i <INPUT> -vf "hwupload" -c:v av1_ama -b:v 5M -f mp4 -y sn1_av1.mp4

Explanation of the flags:

  • -re

    • Flag to maintain the target frame rate

  • -s 1920x1080

    • Since there is no container or metadata in a RAW clip, the user must define the input clip's resolution/size. This example states the input is 1080p

  • -framerate 60

    • Again, without metadata, the encoder requires the framerate of the incoming stream

  • -pix_fmt yuv420p

    • The color space of the encoder is by default yuv420p. this example is defining the input clip as being this same color space

  • -f mp4

    • Sets the output video container to MP4

  • -b:v 5M

    • The target bitrate of the encoded stream. 8M signifies a target bitrate of 8 Megabits per second. You can also use 8000K or 8000000.

  • -c:v av1_ama

    • Declares the encoder's codec for video (as opposed to audio -c:a ...) is the hardware-accelerated AV1 encoder

  • /tmp/enc_out.mp4

    • Save the output in the above path.

4:2:2 10 Bit Conversion

To encode YUV, 4:2:2, 10 bit pixel format to YUV, 4:2:0, 8 bit use the following command:

Command Line:

ffmpeg -hwaccel ama -i <INPUT>  -vf "format=yuv420p,hwupload" -c:v h264_ama -b:v 1M <OUTPUT>

Explanation of the flags:

  • -vf "format=yuv420p,hwupload"

    • Instructs the pipeline to upload and convert the input video as yuv420p.

Constant Rate Factor (CRF) Mode

The following examples demonstrate the usage of the -crf flag and impact of the -qp option on the quality of the encoded streams.

High Quality Encoding

Command Line:

ffmpeg -re -hwaccel ama -f rawvideo -s 1920x1080 -framerate 60 -i <INPUT> -vf "hwupload" -c:v av1_ama -crf 1 -qp 0 -f mp4 sn1_crf_hq.mp4

Explanation of the flags:

  • -crf 1

    • Enables the -crf mode

  • -qp 0

    • Sets the encoded AV1 stream to highest CRF quality

Low Quality Encoding

Command Line:

ffmpeg -re -hwaccel ama -f rawvideo -s 1920x1080 -framerate 60 -i <INPUT> -vf "hwupload" -c:v av1_ama -crf 1 -qp 255 -f mp4 sn1_crf_lq.mp4

Explanation of the flags:

  • -qp 255

    • Sets the encoded AV1 stream to lowest CRF quality

Basic Transcode

This example takes an H.264 clip and transcodes it to HEVC at the bitrate of 8Mbps. The output is written into /tmp/h264_to_hevc.

Command Line:

ffmpeg -y -hwaccel ama -c:v h264_ama -i <INPUT> \
 -c:v hevc_ama -b:v 8M  -f rawvideo  /tmp/h264_to_hevc.hevc

Decode Only Into Multiple-Resolution Outputs

This example decodes an existing H.264 file and then scales it into multiple resolutions as defined below. It will not re-encode them, but save the RAW outputs to disk under /tmp/_scale<resolution>.yuv

Command Line:

 ffmpeg -y -hwaccel ama \
-c:v h264_ama  -out_fmt nv12 -i <INPUT>  \
-filter_complex "scaler_ama=outputs=4:out_res=(1920x1080|full|nv12)(1280x720|full|nv12)(720x480|full|nv12)(360x240|full|nv12) [a][b][c][d]; \
                 [a]hwdownload,format=nv12[a1];[b]hwdownload,format=nv12[b1];[c]hwdownload,format=nv12[c1];[d]hwdownload,format=nv12[d1]" \
-map '[a1]' -f rawvideo -pix_fmt nv12 -y /tmp/scale_1080p.yuv \
-map '[b1]' -f rawvideo -pix_fmt nv12 -y /tmp/scale_720p.yuv  \
-map '[c1]' -f rawvideo -pix_fmt nv12 -y /tmp/scale_480p.yuv \
-map '[d1]' -f rawvideo -pix_fmt nv12 -y /tmp/scale_240p.yuv

Explanation of the flags:

  • -filter_complex

    • The FFmpeg -filter_complex flag allows combining multiple filters together using a graph-like syntax. This example uses the scaler_ama to create 4 output resolutions from the input stream.

    • The scaler_ama filter configures the hardware-accelerated scaler to produce 4 output resolutions (1920x1080, 1280x720, 720x480, and 360x240). For each output, the width, height, frame rate and pixel format are defined as arguments to out_res option as in (WidthxHeight|Rate|Format). The 4 outputs are transfered to the host as a1, b1, c1 and d1 respectively.

  • -map "[ID]"

    • Selects an output of the filter graph. The flags that follow apply to the selected stream.

  • /tmp/scale_<resolution>.yuv

    • Save the output files to the paths listed

Encode Only Into Multiple-Resolution Outputs

This example takes a raw 1080p60 YUV file, scales it down to different resolutions and frame rates, encodes each of the scaled streams to different formats and saves them to disk under /tmp/<encode format>_<resolution>p<frame rate>.mp4

Command Line:

ffmpeg -y -hwaccel ama -f rawvideo -pix_fmt yuv420p -s:v 1920x1080 -framerate 60 -i <INPUT> \
-filter_complex "hwupload,scaler_ama=outputs=4:out_res=(1920x1080|full)(1280x720|half)(720x480|half)(360x240|half) [a][b][c][d]" \
-map '[a]' -c:v hevc_ama -b:v 6M -f mp4 -y /tmp/hevc_1080p60.mp4 \
-map '[b]' -c:v av1_ama  -b:v 2M -f mp4 -y /tmp/av1_720p30.mp4 \
-map '[c]' -c:v h264_ama -b:v 1M -f mp4 -y /tmp/h264_480p30.mp4 \
-map '[d]' -c:v av1_ama  -b:v 1M -f mp4 -y /tmp/av1_240p30.mp4

Explanation of the flags:

  • -filter_complex "hwupload...

    • Specifies that video clip gets upload to the device.

  • -filter_complex "...scaler_ama=outputs=4:out_res=...(1280x720|half)...

    • Declares scaler output of given resolution and rate. See scaler_ama for more details.

  • -c:v [hevc_ama | av1_ama | h264_ama]

    • Declares various encode types HEVC, AV1 and H.264, respectively.

  • /tmp/encode-format_resoultion.encode-format

    • Saves the output clips to the location listed

Transcode with Multiple-Resolution Outputs

This example implements a complete transcoding pipeline on an 1080p60 H.264 input. It decodes the input stream, scales it to 4 different resolutions and encodes scaler's outputs into various formats and saves them to disk under /tmp/<encoder format>_<resolution>.mp4

Command Line:

ffmpeg -y -hwaccel ama \
-c:v h264_ama -i <INPUT> \
-filter_complex "scaler_ama=outputs=4:out_res=(1920x1080)(1280x720)(720x480)(360x240) [a][b][c][d]" \
-map '[a]' -c:v hevc_ama -b:v 6M -f mp4 -y /tmp/hevc_1080p.mp4 \
-map '[b]' -c:v av1_ama  -b:v 2M -f mp4 -y /tmp/av1_720p.mp4 \
-map '[c]' -c:v h264_ama -b:v 1M -f mp4 -y /tmp/h264_480p.mp4 \
-map '[d]' -c:v av1_ama  -b:v 1M -f mp4 -y /tmp/av1_240p.mp4

Transcode in ULL Mode

This example implements an ultra low latency transcode pipeline. For more details refer Tuning Transcode Latency.

Command Line:

ffmpeg  -hide_banner -loglevel error -y -hwaccel ama -low_latency 1 -c:v h264_ama -i <INPUT> \
-c:v hevc_ama -b:v 10M -lookahead_depth 0 -f rawvideo /tmp/h264_to_hevc.hevc

Explanation of the flags:

  • -low_latency 1

    • Enables low latency decoding mode.

  • -lookahead_depth 0

    • LA size of 0 triggers ultra low latency encoding mode.

Double Density Example with xrmd

This example demonstrates an example on how to achieve 4x4kp60 density on a single device

Command Line:

ffmpeg -hide_banner -hwaccel ama -c:v h264_ama -i <4Kp6 H.264 file> \
 -filter_complex "split=4[a][b][c][d]" \
 -map "[a]" -c:v av1_ama -f rawvideo -y /tmp/out_3840x2160_0.av1 \
 -map "[b]" -c:v hevc_ama -f rawvideo -y /tmp/out_3840x2160_0.hevc \
 -map "[c]" -c:v av1_ama -f rawvideo -y /tmp/out_3840x2160_1.av1 \
 -map "[d]" -c:v hevc_ama -f rawvideo -y /tmp/out_3840x2160_1.hevc

Explanation of the flags:

  • -split

    • Splits input into several identical outputs.

Double Density Example without xrmd

This example demonstrates how to achieve 4x4kp60 density on a single device, by explicitly allocating tasks on slices 0 and 1. Note in this example xrmd service has to be stopped.

Command Line:

ffmpeg -hide_banner -hwaccel ama -c:v h264_ama -i <4Kp6 H.264 file> \
 -filter_complex "split=4[a][b][c][d]" \
 -map "[a]" -c:v av1_ama -slice 0 -f rawvideo -y /tmp/out_3840x2160_0.av1 \
 -map "[b]" -c:v hevc_ama -slice 0 -f rawvideo -y /tmp/out_3840x2160_0.hevc \
 -map "[c]" -c:v av1_ama -slice 1 -f rawvideo -y /tmp/out_3840x2160_1.av1 \
 -map "[d]" -c:v hevc_ama -slice 1 -f rawvideo -y /tmp/out_3840x2160_1.hevc

Full Double Density

This example demonstrates how to achieve full density, by distributing transcode pipelines, between 2 devices.

Command Line:

for i in `seq 1 16`; do
 ffmpeg -y -nostdin -hwaccel ama -hwaccel_device /dev/ama_transcoderX -re -c:v h264_ama -i <30 FPS INPUT> -c:v <TYPE 2 ENCODER> -lookahead_depth 10 -f null /dev/null > out_T2_0_$i.log 2>&1 &
 ffmpeg -y -nostdin -hwaccel ama -hwaccel_device /dev/ama_transcoderX -re -c:v h264_ama -i <30 FPS INPUT> -c:v av1_ama -lookahead_depth 10 -f null /dev/null > out_av1_0_$i.log 2>&1 &
 ffmpeg -y -nostdin -hwaccel ama -hwaccel_device /dev/ama_transcoderY -re -c:v h264_ama -i <30 FPS INPUT> -c:v <TYPE 2 ENCODER> -lookahead_depth 10 -f null /dev/null > out_T2_1_$i.log 2>&1 &
 ffmpeg -y -nostdin -hwaccel ama -hwaccel_device /dev/ama_transcoderY -re -c:v h264_ama -i <30 FPS INPUT> -c:v av1_ama -lookahead_depth 10 -f null /dev/null > out_av1_1_$i.log 2>&1 &
done

, where X and Y represent 2 different devices. <30 FPS INPUT> is a 30 FPS encoded video input. (The above example assumes H264 encoded input.), and <TYPE 2 ENCODER> is any one of AV1 Type-2, H264 or HEVC encoder. Note that by default av1_ama uses Type-1 AV1 encoder.

The above example transcodes 64 simultaneous 1080p30 pipelines. Note that if XRMD is disabled, then -slice parameter must be set explicitly.

Cropping

The following example demonstrates a 256x256 crop at offset (1500,450). See crop for details.

Command Line:

ffmpeg -y -hwaccel ama -hwaccel_device /dev/ama_transcoder0 -re -out_fmt yuv420p -c:v h264_ama -i <INPUT> \
-filter_complex "scaler_ama=outputs=1:out_res=(256x256|yuv420p):crop=256|256|1500|450 [b]" -map "[b]" -c:v h264_ama -f mp4 <OUTPUT>

2D GPU

This section provides examples on usage of various 2D GPU utilities.

Video Processing Accelerators

Accelerator Core

Functions/Supported Models

Notes

2D GPU

Video Rotation, Color Space Conversion, Chroma Subsampling, Picture In Picture and Tiling.

Picture In Picture and Tiling require the same frame rate on all inputs to the 2d_ama plugin.
To cascade multiple 2D GPU cores, pixel format yuv420p must be set, explicitly.

Machine Learning

ML Based Face ROI and ML Based Text ROI models

Supported ROI models are 1080p in landscape mode, 720p in both landscape and portrait modes.
Maximum supported instances of ml_ama plugin (ROI model) per card is 8x720p60.

Video Rotation

The following example demonstrates how to transcode a flip-over operation on an AMA AMD compatible card:

ffmpeg -y -hide_banner -hwaccel ama -hwaccel_device /dev/ama_transcoder0 \
-c:v h264_ama -i <INPUT> \
-filter_complex "[0:v]2d_ama=inputs=1:processor=rotate:rotation=180[c]" \
-map "[c]" -c:v hevc_ama -f mp4 <OUTPUT>

, where 2d_ama is graphic processor's plugin, set for rotation operation; INPUT and OUTPUT are any one of supported encoded files. Note that only rotations which are multiples of 90 degrees are supported.

The following example demonstrates flip-over and 720p scaling operations:

ffmpeg -y -hide_banner -hwaccel ama -hwaccel_device /dev/ama_transcoder0 \
-c:v h264_ama  -i <INPUT> \
-filter_complex "[0:v]2d_ama=inputs=1:processor=rotate:rotation=180:w=1280:h=720[c]" \
-map "[c]" -c:v hevc_ama -f mp4 <OUTPUT>

Color Space Conversion

The following example demonstrates how to convert from RGB to YUV on an AMA AMD compatible card:

ffmpeg -y -hide_banner -hwaccel ama -hwaccel_device /dev/ama_transcoder0 -s 1920x1080 \
-pix_fmt bgra -i <INPUT> \
-filter_complex "[0:v]hwupload[a];[a]2d_ama=inputs=1:processor=csc:csc=rgb2yuv[c];[c]hwdownload" \
-pix_fmt yuv420p -f rawvideo <OUTPUT>

, where graphic processor is set for color conversion operation.

The following example demonstrates how to encode a RGBA video file on an AMA AMD compatible card:

ffmpeg -y -hide_banner -hwaccel ama -hwaccel_device /dev/ama_transcoder0 -f rawvideo -s 1920x1080 \
-pix_fmt bgra -i <INPUT> \
-filter_complex "[0:v]hwupload[a];[a]2d_ama=inputs=1:processor=csc:csc=rgb2yuv[c]" \
-map "[c]" -c:v hevc_ama -f mp4 <OUTPUT>

Similarly, the following example demonstrates YUV to planar RGB conversion:

ffmpeg -y  -hide_banner -hwaccel ama -hwaccel_device /dev/ama_transcoder0 \
-c:v h264_ama -i <INPUT> \
-filter_complex "scaler_ama=outputs=1:out_res=(1920x1080|rgbp)[a];[a]hwdownload,format=rgbp[a1]" \
-map '[a1]' -f rawvideo -y <RGBP OUTPUT>

Chroma Subsampling

The following example demonstrates how to convert from 4:2:2 pixel format to 4:2:0 on an AMA AMD compatible card:

ffmpeg -y -hide_banner -hwaccel ama -hwaccel_device /dev/ama_transcoder0 -s 1920x1080 \
-pix_fmt yuv422p -i <INPUT> \
-filter_complex "[0:v]hwupload[a];[a]2d_ama=inputs=1:processor=subsample[c];[c]hwdownload" \
-pix_fmt yuv420p -f rawvideo <OUTPUT>

, where graphic processor is set for pixel subsampling operation.

The following example demonstrates how to transcode a 4:2:2 pixel format video to 4:2:0 using both the host, for decoding, and an AMA AMD compatible card, for subsampling and encoding:

ffmpeg -y -hide_banner -hwaccel ama -hwaccel_device /dev/ama_transcoder0 \
-i <INPUT> \
-filter_complex "[0:v]hwupload[a];[a]2d_ama=inputs=1:processor=subsample[c]" \
-map [c] -c:v h264_ama -b:v 5M -f mp4 <OUTPUT>

, where graphic processor is set for pixel subsampling operation.

Picture In Picture (PIP)

The following example demonstrates how to create a PIP video on an AMA AMD compatible card:

ffmpeg -y -hide_banner  -hwaccel ama -hwaccel_device /dev/ama_transcoder0  \
-c:v h264_ama -out_fmt yuv420p -i <INPUT 1> \
-c:v h264_ama -out_fmt yuv420p -i <INPUT 2> \
-filter_complex "[1:v]scaler_ama=outputs=1:out_res=(720x480|yuv420p)[p]; \
                 [0:v][p]2d_ama=inputs=2:processor=overlay:core_id=0:x=0:y=0[x]" \
-map "[x]" -c:v h264_ama -frames 1000 -b:v 15M -f mp4 -y <OUTPUT>

, where graphic processor is set for scaling and overlay operations, with INPUT 1 set as the background.

Tiling

The following example demonstrates how to create a tiling video on an AMA AMD compatible card:

ffmpeg -y -hide_banner -hwaccel ama -hwaccel_device /dev/ama_transcoder0 \
-c:v h264_ama -out_fmt yuv420p -i <INPUT 1> \
-c:v h264_ama -out_fmt yuv420p -i <INPUT 2> \
-c:v h264_ama -out_fmt yuv420p -i <INPUT 3> \
-c:v h264_ama -out_fmt yuv420p -i <INPUT 4> \
-filter_complex "[0:v]scaler_ama=outputs=1:out_res=(1280x720|yuv420p)[0]; \
                 [1:v]scaler_ama=outputs=1:out_res=(1280x720|yuv420p)[1]; \
                 [2:v]scaler_ama=outputs=1:out_res=(1280x720|yuv420p)[2]; \
                 [3:v]scaler_ama=outputs=1:out_res=(1280x720|yuv420p)[3]; \
                 [0][1][2][3]2d_ama=layout=2x2:inputs=4:processor=tile[c]; \
                 [c]scaler_ama=outputs=1:out_res=(1920x1080|yuv420p)[r]" \
-map "[r]" -c:v h264_ama -b:v 15M -f mp4 -y <OUTPUT>

, where graphic processor's is set for scaling and tiling operations, with INPUT 1 ... INPUT 4 set as tiles.

ML Processing

This section provides examples on usage of ROI for both face and text VQ enhancement.

ML Based Face ROI

The following example demonstrates how to perform ROI face encoding on an AMA AMD compatible card:

ffmpeg -y -hwaccel ama -hwaccel_device /dev/ama_transcoder0 -c:v h264_ama -i <INPUT> \
-filter_complex "scaler_ama=outputs=3:out_res=(1280x720|yuv420p)(1280x720|yuv420p)(1280x720|rgbp)[def][ori][a]; \
                 [a]ml_ama=model=roi:model_args=type=face[mlop];[ori][mlop]roi_scale_ama[res1]" \
-map [res1] -c:v hevc_ama -b:v 300K -f mp4 <OUTPUT 1> \
-map [def] -c:v hevc_ama -b:v 300K -f mp4 <OUTPUT 2>

, where ML engine is set for face ROI enhancement, and the resulting enhanced image, res1, is encoded.

ROI Gain Factor

The following example demonstrates the impact of probability-to-QP mapping gain factor:

ffmpeg -y -hwaccel ama -hwaccel_device /dev/ama_transcoder0 -c:v h264_ama -i  <INPUT> \
   -filter_complex "split=outputs=5 [plain][ml0][l][n][h]; \
                             [ml0] scaler_ama=outputs=1:out_res=(1280x720|rgbp) [ml1]; \
                             [ml1] ml_ama=model=roi:model_args=type=face [ml2]; \
                             [ml2] split=outputs=3 [ml3_1][ml3_2][ml3_3]; \
                             [l][ml3_1] roi_scale_ama=strength=low [ml_l]; \
                             [n][ml3_2] roi_scale_ama=strength=normal [ml_n]; \
                             [h][ml3_3] roi_scale_ama=strength=high [ml_h]" \
     -map '[plain] ' -c:v h264_ama -b:v 300k -f mp4 <OUTPUT1> \
     -map '[ml_l]' -c:v h264_ama -b:v 300k -f mp4 <OUTPUT2> \
     -map '[ml_n]' -c:v h264_ama -b:v 300k -f mp4 <OUTPUT3> \
     -map '[ml_h]' -c:v h264_ama -b:v 300k -f mp4 <OUTPUT4>

Here <OUTPUTx>, for x={1-4}, represent encode streams without ML, low, normal and high gain factors, respectively.

ROI Ladder Transcoding

The following example demonstrates how to perform ROI transcoding at different resolutions:

ffmpeg -y -hwaccel ama -hwaccel_device /dev/ama_transcoder0 -c:v h264_ama -i <INPUT> \
 -filter_complex "split=2[s_org][s_ml]; \
                  [s_org]scaler_ama=outputs=4:out_res=(1920x1080)(1280x720)(720x480)(360x240) [sa][sb][sc][sd]; \
                  [s_ml]scaler_ama=outputs=1:(1280x720|rgbp)[ml_in]; \
                  [ml_in]ml_ama=model=roi:model_args=type=face[ml_out]; [ml_out]split=4[ml_out_sa][ml_out_sb][ml_out_sc][ml_out_sd]; \
                  [sa][ml_out_sa]roi_scale_ama[roi_a]; \
                  [sb][ml_out_sb]roi_scale_ama[roi_b]; \
                  [sc][ml_out_sc]roi_scale_ama[roi_c]; \
                  [sd][ml_out_sd]roi_scale_ama[roi_d]" \
-map [roi_a] -c:v av1_ama -b:v 300K -f rawvideo <OUTPUT1> \
-map [roi_b] -c:v av1_ama -b:v 300K -f rawvideo <OUTPUT2> \
-map [roi_c] -c:v av1_ama -b:v 300K -f rawvideo <OUTPUT3> \
-map [roi_d] -c:v av1_ama -b:v 300K -f rawvideo <OUTPUT4>

Note that scale engine is invoke twice. Once for scaling the outputs and second time to perform pixel conversion.

ROI Face Detection

The following example demonstrates inference engine's ability to detect faces:

ffmpeg -y -hwaccel ama -hwaccel_device /dev/ama_transcoder0 -c:v h264_ama  -i <INPUT> \
-filter_complex "scaler_ama=outputs=2:out_res=(1280x720|yuv420p)(1280x720|rgbp)[ori][mlip]; \
                 [mlip]ml_ama=model=roi:model_args=type=face[mlop]; \
                 [ori][mlop]roi_scale_ama=roi_map_type=roi[rso]; \
                 [rso]hwdownload, roi_overlay_ama[res1]" \
-map [res1] -f rawvideo -pix_fmt yuv420p -f rawvideo <OUTPUT>

, where software plugin roi_overlay_ama overlays transparent rectangular boxes around all detected faces.

ML Based Text ROI

The following example demonstrates how to perform ROI text encoding on an AMA AMD compatible card:

ffmpeg -y -hwaccel ama -hwaccel_device /dev/ama_transcoder0 -c:v h264_ama  -i <INPUT> \
-filter_complex "scaler_ama=outputs=3:out_res=(1280x720|yuv420p)(1280x720|yuv420p)(1280x720|rgbp)[def][ori][a]; \
                 [a]ml_ama=model=roi:model_args=type=text[mlop];[ori][mlop]roi_scale_ama[res1]" \
-map [res1] -c:v hevc_ama -b:v 200K -f mp4  <OUTPUT 1> \
-map [def] -c:v hevc_ama -b:v 200K -f mp4  <OUTPUT 2>

, where ML engine is set for text ROI enhancement, and the resulting enhanced image, res1, is encoded.