Video Quality Examples¶
This page is dedicated to explaining some of the details behind Video Quality (VQ), how it is measured, and how you can optimize your FFmpeg commands with the AMD AMA Video SDK to maximize its performance.
Further documentation on this topic can be found in the Tuning Video Quality section of the AMD AMA Video SDK user guide.
Environment Setup¶
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
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.
Introduction to Video Quality¶
There has been a longstanding goal for video engineers to quantitatively determine the output quality of an encoder without having to watch and inspect every individual frame. This has led to an evolution of algorithmic solutions, the most common of which are:
Many people will argue which metric is best (although PSNR is commonly considered the least accurate). Jan Ozer from the Streaming Media Center posted his experimental correlation of MOS vs the above metrics. You can review the findings here.
Furthermore, due to the industry standard of tracking encoder "performance" to quantitative metrics like the ones listed above, many encoders have "taught to the test"; that is, they provide different command-line arguments that will give higher scores but may look worse to the human eye. For example, common CPU encoders x264 and x265 have a tune
parameter which optimizes to objective metrics.
This page discusses the AMD AMA Video SDK command line flags used to optimize for objective quality (scores) and subjective quality (visual appeal) and provides additional details as to what is happening behind the scenes and why.
Optimized Settings for the AMD AMA Video SDK¶
It is highly recommended to perform encoding on raw video clips; that is, clips that have not undergone a transform/compression/encoding in the past. This ensures that the clips are in a universally known state in order to fairly compare encoders.
Alternatively, you can add the flags to decode before encoding, and the results will remain accurate as long as the same pre-encoded file is used as the source across all encoders under test. Information on this process can be found on the FFmpeg tutorial page.
Flags not illustrated in this page are covered in the Using FFmpeg chapter of the AMD AMA Video SDK user guide.
The following table demonstrates various encoder parameters that effect VQ and latency.
Tune Mode |
Latency Setting |
Preset Type |
Encoder |
---|---|---|---|
VMAF VQ SSIM PSNR (See |
Normal Ultra Low Latency (See |
Medium Slow (See |
h264_ama hevc_ama av1_ama (See |
Various permutations of Metrics, Latency and Preset are possible. The following sections provide demonstrative examples.
AV1 VMAF - Normal Latency - Medium Preset¶
In this mode, which is the default mode, the only adjustable parameter is the tuning mode. The following example, illustrates the VMAF tune mode, for AV1 encoder
ffmpeg -y -hwaccel ama -hwaccel_device /dev/ama_transcoder0 -s 1920x1080 -framerate 60 -pix_fmt yuv420p -i <INPUT> -vf hwupload -c:v av1_ama -tune_metrics 4 -b:v 2000k -f rawvideo <OUTPUT>
, where -tune_metrics
4 specifies VMAF optimization mode.
AVC VMAF - Normal Latency - Slow Preset¶
In this mode, real-time performance at capacity is not guaranteed; however, better results are obtained, with respect to the selected tune metric. Note that this mode is not applicable to either types of AV1.
The following example, illustrates the VMAF tune mode, for AVC encoder.
ffmpeg -y -hwaccel ama -hwaccel_device /dev/ama_transcoder0 -s 1920x1080 -framerate 60 -pix_fmt yuv420p -i <INPUT> -vf hwupload -c:v h264_ama -tune_metrics 4 -preset slow -b:v 2000k -f rawvideo <OUTPUT>
, where -preset
slow
optimizes the objective tuning modes.
AV1 VMAF - Ultra Low Latency - Medium Preset¶
Ultra Low Latency (ULL) is achieved by setting the -lookahead_depth
to 0. The following example, illustrates the VMAF tune ULL mode, for AV1 encoder.
ffmpeg -y -hwaccel ama -hwaccel_device /dev/ama_transcoder0 -s 1920x1080 -framerate 60 -pix_fmt yuv420p -i <INPUT> -vf hwupload -c:v av1_ama -tune_metrics 4 -b:v 2000k -lookahead_depth 0 -f rawvideo <OUTPUT>
AVC VMAF - Ultra Low Latency - Slow Preset¶
This mode is the combination of ULL and metric optimized options. Note that this mode is not applicable to either types of AV1.
The following example, illustrates the VMAF tune ULL mode, for AVC encoder.
ffmpeg -y -hwaccel ama -hwaccel_device /dev/ama_transcoder0 -s 1920x1080 -framerate 60 -pix_fmt yuv420p -i <INPUT> -vf hwupload -c:v h264_ama -tune_metrics 4 -lookahead_depth 0 -preset slow -b:v 2000k -f rawvideo <OUTPUT>
, where -preset
slow
optimizes the objective tuning modes.
Running PSNR/SSIM/VMAF Scores¶
Due to licensing reasons, the FFmpeg binary delivered in this package does not include a comprehensive set of codecs or plugins required for scoring video quality. You have many options:
(Easiest) Download a static FFmpeg build from John Van Sickle which has VMAF (among other plugins) precompiled + installed
Recompile another version FFmpeg and include the VMAF library
Recompile the FFmpeg starting from the source code included in this repository and include the VMAF library. For instructions on how to customize and rebuild the FFmpeg provided with the AMD AMA Video SDK, see the Rebuilding FFmpeg section
The following sample command line demonstrates a typical VMAF calculation, through FFmpeg:
<FFMPEG PATH>/ffmpeg -i <DISTORTED FILE> -framerate <FRAME RATE> -s <RESOLUTION> -pix_fmt yuv420p -i <ORIGINAL> \
-lavfi libvmaf="log_fmt=json:ms_ssim=1:ssim=1:psnr=1:log_path=/<LOG FILE PATH>.vmaf.json:model_path=<PATH TO VMAF MODEL>" -f null -
, where FFMPEG PATH
is the path to modified FFmpeg, DISTORTED FILE
is the encoded file, RESOLUTION
is WidthxHeigth resolution of the original clip, ORIGINAL
is the original clip, LOG FILE PATH
is the path of log file and PATH TO VMAF MODEL
is the path to an appropriate VMAF model, which typically is vmaf_4k_v0.6.1.pkl
for 4K resolution or vmaf_float_v0.6.1.pkl
for lower resolutions. See Models for relevant details. The above command line calculates PSNR, SSIM and VMAF, in json format.