Attention
This version of the SDK has been superseded by the latest release of the SDK.
Using GStreamer¶
Introduction¶
GStreamer is a pipeline-based multimedia framework that links together a wide variety of media processing systems to complete complex workflows. The pipeline design serves as a base to create many types of multimedia applications such as video editors, transcoders, streaming media broadcasters and media players. The AMD AMA Video SDK includes an enhanced version of GStreamer which can communicate with the hardware accelerated transcode pipeline in AMD devices.
It is not within the scope of this document to provide an exhaustive guide on the usage of GStreamer. Various resources can be found online, for example:
Overview of the GStreamer Plugins¶
The AMD AMA Video SDK provides the following GStreamer plugins for building hardware-accelerated video pipelines using AMA compatible devices:
ama_av1dec
av1 decoderama_av1enc
av1 encoderama_h264dec
h264 decoderama_h264enc
h264 encoderama_h265dec
h264 decoderama_h264enc
h265 encoderama_vp9dec
VP9 decoderama_scaler
hardware accelerated scaler and cropperama_download
data downloader, from device to hostama_upload
data uploader, from host to deviceama_compositor
feature rich compositorama_jpegdec
JPEG decoderama_jpegenc
JPEG encoderama_ljpegenc
Lossless JPEG encoderama_videoconvert
accelerated pixel converter
The following sections describe the options used with GStreamer to configure and use the various hardware accelerators available on AMA compatible devices.
Decoder Plugin¶
The ama_av1dec
, ama_h264dec
, ama_h265dec
, and ama_vp9dec
plugins provide support for hardware-accelerated decoding using AMA compatible devices, for AV1, AVC, HEVC and VP9.
SDK also supports JPEG decoding through ama_jpegdec
plugin.
Decoder Inputs and Outputs¶
Video Decoders:
Input: 8 or 10 bits AV1, AVC, HEVC and VP9 encoded stream, in OBU format for AV1, byte-stream format for AVC or HEVC, or VP9 stream format for VP9.
Output: One of NV12_4L4, NV12, I420, NV12_10LE32, P010_10E, I420_10LE, RGBP, or NV12_10LE_4L4 formats
JPEG Decoder:
Input: Standard JPEG file
Output: One of NV12_4L4, NV12,I420, or RGBP
Decoder Parameters¶
Property Name |
Description |
---|---|
|
Numeric ID of an XMA device
Type: Integer
Default: -1 (auto)
Range -1 to 2147483647
|
|
Whether to enable low latency decoding
Type: Boolean
Default: false
|
|
Log latency info to syslog
Type: Boolean
Default: false
|
|
Downscale through decoder
Allow the decoder to downscale the output if negotiated with downstream. When FALSE, the decoder always outputs video in its native resolution. Scaling RGBP format isn't supported. | Type: Boolean
Default: false
|
Decoder Example Pipelines¶
Refer to the Decoder Pipeline example for an illustration of how to use this plugin.
Encoder Plugin¶
The ama_av1enc
, ama_h264enc
and ama_h265enc
plugins provide support for hardware-accelerated encoding using AMA compatible devices, for AV1, AVC and HEVC.
Encoder Inputs and Outputs¶
Input: NV12_4L4, I420, NV12_10LE32, P010_10LE, I420_10LE, or NV12_10LE_4L4
Output: One of AV1, AVC or HEVC 8-bit/10-bit encoded stream, in OBU format for AV1 and byte-stream for AVC and HEVC
Encoder Parameters¶
Property Name |
Description |
---|---|
|
Number of B-frames between two consecutive P-frames
Type: Integer
Range: -1 - 7, for AV1 Type 1, with default 7 for FPS greater than 30, and 3 otherwise.
Range: -1 - 3, for AVC, HEVC, and AV1 Type 2, with default 3.
Default: -1 (auto)
|
|
Fixed output bitrate in bits per second
Type: Integer
Range: 0 - 4294967295
Default: 5000000
|
|
Constant Rate Factor value
Type: Integer
Range -1 - 63
Default: -1
|
|
Numeric ID of an XMA device
Type: Integer
Range: -1 - 2147483647
Default: -1 (auto)
|
|
Enable Dynamic B Frame Insertion
Type: Integer
Range: -1 - 1
Default: -1 (auto)
|
|
AV1 device type to use
Type: Enum
(0): any
(1): Type 1
(2): Type 2
Default: 1
|
|
Encode all intra frames as IDR
Type: Boolean
Default: True
|
|
Maximum distance between two consecutive I frames
Type: Integer
Range: -1 - 2147483647
Default: -1 (auto)
|
|
The periodicity of IDR frames
Type: Integer
Range: 0 - 4294967295
Default: 4294967295
|
|
Number of frames in the future of the currently encoded frame that the encoder will analyze and take into account
Type: Integer
Range: 0 - 47+Maximum number of B frames
b-frames Default: -1 (auto)
|
|
Use to limit encoding bitrate if you have not specified
bitrate parameterType: Integer
Range: 0 - 35000000000
Default: -1 (auto)
|
|
Maximum QP value allowed for the rate control
Type: Integer
Range: 0 - 51, for AVC and HEVC
Range: 0 - 255, for AV1
Default: 51, for AVC and HEVC
Default: 255, for AV1
|
|
Minimum QP value allowed for the rate control
Type: Integer
Range: 0 - 51, for AVC and HEVC
Range: 0 - 255, for AV1
Default: 0
|
|
Fixed quantization value. When constant quality is enabled,
bitrate must be set to 0Type: Integer
Range: -1 - 255
Default: -1 (disable)
|
|
FQuantization offset value - P/B
Type: Integer
Range: -51 - 51
Auto selection mode is
-1 .Default: 0
|
|
FQuantization offset value - I
Type: Integer
Range: -51 - 51
Auto selection mode is
-1 .Default: 0
|
|
QP control mode.
Type: Enum
(0): auto - Auto
(1): relative-load - Relative load (spatial AQ + temporal AQ)
(2): uniform - Uniform (AQ off)
|
|
Rate control mode to use for encoding
Type: Enum
(-1): auto - Auto
(0): cqp - Constant QP
(1): cbr - Constant bitrate
(2): vbr - Variable bitrate
(3): cvbr - Constrained variable bitrate
(4): cabr - DEPRECATED Content adaptive bitrate
(5): crf - RESERVED
|
|
Which slice of the XMA device to use
Type: Integer
Range: -1 - 1
Default: -1
|
|
Enable spatial AQ
Type: Boolean
Default: True
|
|
Spatial AQ gain scale factor
Type: Integer
Range: 0 -255
Default: 255
|
|
Enable temporal AQ
Type: Boolean
Default: True
|
|
Temporal AQ gain scale factor
Type: Integer
Range: 0 -255
Default: 255
Default: 1
|
|
Tier
Type: Boolean
(-1): auto - Auto
(0): main - Main
(1): high - High
|
|
Encoder VQ-Density preset
Valid values: medium or slow. (default is medium)
(medium) Full density with medium VQ - default
(fast) Allows for increase in total throughput from 4kp60 to 4kp75 , when 2 or more channels are used. Does not apply to AV1
device-type 1 encoding. Not applicable under ULL setting. Note lower VQ than medium preset is to be expected.(slow) High VQ at lower density. (For AV1 Type 1, improvements are observed in 10 bit contents only.)
Consult the Tuning Video Quality section for more details on how to use this option.
Note that this option has no effects on AV1
device-type 1 encoding. |
|
Tune VQ for objective metrics
Type: Enum
(1): vq - Best visual quality
(2): psnr - Best PSNR
(3): ssim - Best SSIM
(4): vmaf - Best VMA
|
|
Dynamic Configuration File
Path to dynamic file location (default is empty)
Consult the Dynamic Encoder Parameters section for more details on how to use this option.
|
|
Encoder latency in milliseconds that the encoder will analyze and take into account
Type: Integer
Range: -1 - 60000
Default: -1 (auto)
|
|
No low latency B Frames
Type: Integer
Range: -1 - 1
Default: -1 (auto)
|
Encoder Example Pipelines¶
Refer to the Encoder Pipeline example for an illustration of how to use this plugin.
Scaler Plugin¶
The ama_scaler
plugin provides support for hardware-accelerated resizing.
Scaler Inputs and Outputs¶
Input: NV12_4L4, NV12, I420, NV12_10LE32, P010_10LE, I420_10LE, I420_10BE, RGBP, ARGB, ABGR, RGBA, BGRA, RGB, BGR, and NV12_10LE_4L4
Output: NV12_4L4, NV12, I420, NV12_10LE32, P010_10LE, I420_10LE, I420_10BE, RGBP, ARGB, ABGR, RGBA, BGRA, RGB, BGR, and NV12_10LE_4L4
Scaler Parameters¶
Property Name |
Description |
---|---|
|
Numeric ID of an XMA device
Type: Integer
Range: -1 - 2147483647
Default: -1 (auto)
|
The output width, height and frame rate are set through the succeeding cap filter.
Pad Property |
Description |
---|---|
width |
Output width
Type: Integer
Range: 144 - 7580
|
height |
Output height
Type: Integer
Range: 144 - 7580
|
framerate |
Output frame rate
Type: Enum
Range: -1 - 1
(-1): auto - Full rate
(0): full - Full rate
(1): half - Half rate
|
Scaler Example Pipelines¶
Refer to the Transcode with Multiple-Resolution Outputs example for an illustration of how to use this plugin.
2D Engines¶
This section describes different hardware accelerated 2D processing engines that are available in AMA SDK. The following plugins may take core-id
and device
as configuration parameters to specify the target core and device, respectively.
Inputs and Outputs¶
Input: NV12_4L4, NV12, I420, NV12_10LE32, P010_10LE, I420_10LE, I420_10BE, RGBP, ARGB, ABGR, RGBA, BGRA, RGB, BGR, and NV12_10LE_4L4
Output: NV12_4L4, NV12, I420, NV12_10LE32, P010_10LE, I420_10LE, I420_10BE, RGBP, ARGB, ABGR, RGBA, BGRA, RGB, BGR, and NV12_10LE_4L4
2D Plugins¶
Engine Name |
Description |
Options |
---|---|---|
|
Video crop
Takes coordinates.
|
bottom Pixels to crop at the bottom (from 0 to 2147483647) (default 0)top Pixels to crop at the top (from 0 to 2147483647) (default 0)left Pixels to crop on the left (from 0 to 2147483647) (default 0)right Pixels to crop on the right (from 0 to 2147483647) (default 0) |
|
Video pad
Takes size, coordinates, and pad color.
|
bottom Pixels to add at the bottom (from 0 to 2147483647) (default 0)top Pixels to add at the top (from 0 to 2147483647) (default 0)left Pixels to add on the left (from 0 to 2147483647) (default 0)right Pixels to add on the right (from 0 to 2147483647) (default 0)color Padded area color in ARGB format (e.g. 0xFF000000 for black) |
|
Draw box
Takes size, coordinates, and pad color.
|
height Height of the box (from 0 to 2147483647) (default 10)width Width of the box (from 0 to 2147483647) (default 10)top Number of pixels from the top of the video to the top of the box (from 0 to 2147483647) (default 0)left Number of pixels from the left side of the video to the left side of the box (from 0 to 2147483647) (default 0)thickness Box line thickness (from 2 to 16) (default 2)color Box line color in ARGB format (e.g. 0xFF000000 for black) |
|
Rotate frame
Takes an angle.
|
angle one of 0, 90, 180 or 270 (default 0) |
|
Color space conversion ans subsampling
Converts between RGB and YUV.
Converts from I422 to I420
|
|
|
Video overlay
Overlays 1 picture over another
|
alpha-blend Enable alpha blend (Boolean) default falseoffset-x Horizontal offset of the overlay in pixels from the left of the main video (from 0 to 2147483647) (default 0)offset-y Vertical offset of the overlay in pixels from the top of the main video (from 0 to 2147483647) (default 0) |
|
Video tile
Maps input streams to specified layout
|
grid-x Number of video tiles per line of the grid (from 1 to 16) (default 2)grid-y Number of lines in the video grid (from 1 to 16) (default 2) |
Compositor Plugin¶
The ama_compositor
plugin provides support for hardware-accelerated video composition operations such as alpha-belding, rotation, drawbox, etc.
Compositor Inputs and Outputs¶
Input: NV12_4L4, NV12, I420, NV12_10LE32, P010_10LE, I420_10LE, I420_10BE, RGBP, ARGB, ABGR, RGBA, BGRA, RGB, BGR, and NV12_10LE_4L4
Output: NV12_4L4, NV12, I420, NV12_10LE32, P010_10LE, I420_10LE, I420_10BE, RGBP, ARGB, ABGR, RGBA, BGRA, RGB, BGR, and NV12_10LE_4L4
Compositor Parameters¶
Property Name |
Description |
---|---|
|
Alpha blending of the picture.
Type: float
Rang: 0 - 1
Default: 1
|
|
Border color of the picture encoded as 0x00RRGGBB
Type: Integer
Range: 0 - 16777215
Default: 0
|
|
Inner width of the picture's border in pixels
Type: Integer
Range: 0 - 4294967295
Default: 0
|
|
Outer width of the picture's border in pixels
Type: Integer
Range: 0 - 4294967295
Default: 0
|
|
Outer width of the picture's border in pixels
Type: Integer
Range: 0 - 4294967295
Default: 0
|
|
Pixels to crop at the bottom
Type: Integer
Range: 0 - 4294967295
Default: 0
|
|
Pixels to crop on the left
Type: Integer
Range: 0 - 4294967295
Default: 0
|
|
Pixels to crop on the right
Type: Integer
Range: 0 - 4294967295
Default: 0
|
|
Pixels to crop at the top
Type: Integer
Range: 0 - 4294967295
Default: 0
|
|
Height of the picture
Type: Integer
Range: 0 - 4294967295
Default: 0
|
|
Video direction's rotation and flip
Type: Enum
(0): identity - No rotation
(1): 90r - Rotate clockwise 90 degrees
(2): 180 - 180 degrees
(3): 90l - Rotate counter-clockwise 90 degrees
(4): horiz - Horzontal flip
(5): vert - Vertical flip
(6): ul-lr - Flip across upper left/lower right diagonal
(7): ur-ll - Flip across upper right/lower left diagonal
(8): auto - Select flip method based on image-orientation tag
(9): custom - Current status depends on plugin internal setup
|
|
Width of the picture
Type: Integer
Range: 0 - 4294967295
Default: 0
|
|
X Position of the picture
Type: Integer
Range: 0 - 4294967295
Default: 0
|
|
Y Position of the picture
Type: Integer
Range: 0 - 4294967295
Default: 0
|
|
Z Order of the picture
Type: Integer
Range: 0 - 4294967295
Default: 0
|
Property Name |
Description |
---|---|
|
Background type
Type: Enum
(0) transparent - Transparent Background to enable further compositing
(0) color - Solid Color Background
|
|
Color of the composition's background encoded as 0x00RRGGBB
Type: Unsigned Integer
Range: 0 - 16777215
Default: 0
|
|
ID of the device core to use
Type: Integer
Range: 0 - 1
Default: 0
|
|
Numeric ID of an XMA device (-1 = unspecified)
Type: Integer.
Range: -1 - 2147483647
Default: -1
|
Hardware Down and Up Loads¶
The ama_download
and ama_upload
plugins provide support for DMA transfer of data to and from the host, respectively. Note that transaction directions are with respect to the host.
Inputs and Outputs¶
Input: I420, NV12, I420_10LE, I420_10BE, ARGB, ABGR, RGBA, BGRA, RGB, BGR
Output: I420, NV12, I420_10LE, I420_10BE, ARGB, ABGR, RGBA, BGRA, RGB, BGR
DMA Parameters¶
Property Name |
Description |
---|---|
|
Numeric ID of an XMA device
Type: Integer
Range: -1 - 2147483647
Default: -1 (auto)
|
Moving Data through the Pipeline¶
The GStreamer plugins included in the AMD AMA Video SDK take care of efficiently moving data through the video processing pipeline. For optimal performance, video buffers will be moved between the host and the appropriate device only if needed by plugins in the pipeline. This is known as "zero-copy".
The decoder plugin will only copy the output buffer from the device to the host if a downstream element (e.g. filesink) running on the host needs to access the decoded frame. This allows downstream hardware-accelerated plugins (e.g. scaler, encoder) running on the same AMD device to process the decoded frames without unnecessary data transfers.
The encoder plugin will only copy the input buffer from host to the device if it is allocated in user-space memory on the host or in a different device. This allows the encoder to process frames produced by upstream hardware-accelerated plugins (e.g. decoder, scaler) running on the same AMD device without unnecessary data transfers.
Working with Multiple Devices¶
By default, if no device identifier is specified, a job is submitted to device 0. When running large jobs or multiple jobs in parallel, device 0 is bound to run out of resources and additional jobs will error out due to insufficient resources.
By using the device
option of the GStreamer plugins, included in the AMD AMA Video SDK, different functionalities such as decode, scale, etc. of a pipeline can be individually submitted to a specific device. This allows for an easy and straightforward way to leverage the entire video acceleration capacity of your system.
Rebuilding GStreamer¶
Obtain the zipped version of SDK's Gstreamer code from ma35d_sdk_v1.2.0_gstreamer.zip. Unzip this file into ma35_gstreamer
folder. This folder will contain the source code for AMA SDK plugins and a patch for Gstreamer.
You can rebuild the Gstreamer executable with optional plugins by following the instructions below.
Install the prerequisite packages:
sudo apt install ninja-build flex bison python3-pip unzip pkg-config libjansson-dev uuid-dev sudo snap install cmake --classic sudo pip3 install meson ninja
Unzip the downloaded zip file:
unzip ma35d_sdk_v1.2.0_gstreamer.zip -d ma35_gstreamer
Get Gstreamer:
git clone https://github.com/GStreamer/gstreamer.git cd gstreamer git checkout f6e672f27fcac06af58d7ac995551893d36944ce
Apply the patch to Gstreamer:
cp ../ma35_gstreamer/ama_gstreamer.patch . git apply ama_gstreamer.patch
Build Gstreamer and AMA SDK plugins:
cd ../ma35_gstreamer ln -s ../gstreamer/subprojects ./ export C_INCLUDE_PATH=/opt/amd/ama/ma35/include/xma/:/opt/amd/ama/ma35/include/xrm/:/opt/amd/ama/ma35/include/xrm_interface/:$C_INCLUDE_PATH export LIBRARY_PATH=/opt/amd/ama/ma35/lib/:$LIBRARY_PATH meson setup build cd build ninja
Install Gstreamer and plugins:
ninja install