-
Notifications
You must be signed in to change notification settings - Fork 152
Recommended FFmpeg Encoder Settings
The Advanced Media Framework (AMF) is a multimedia processing framework developed by AMD (Advanced Micro Devices). It provides a set of components and interfaces for developing and optimizing multimedia applications, particularly those involving graphics processing units (GPUs) and accelerated processing units (APUs).
AMF features cross-platform and cross-API capabilities, allowing integration with various technologies and graphics APIs such as DirectX, OpenGL, OpenCL and Vulkan. It offers powerful functionalities including video encoding and decoding, audio processing, image processing, data transformation, and more.
AMD AMF Encoder is a professional video encoder on top of AMF, that provides powerful video encoding capabilities and a wide range of customization options. It is designed to meet the individual needs of different users.
Users can adjust the encoder's parameter settings to meet different encoding requirements, such as resolution, bit rate, frame rate, encoding quality, and more. These parameter settings can be customized based on users' needs to meet different video encoding scenarios.
AMF encoder provides users with various options related to video quality, performance and latency. Video quality, encoding performance, and latency form the "impossible triangle" of video encoding. In other words, no encoder option can simultaneously benefit all three of these requirements. Using a specific encoding option can effectively enhance video quality. On the other hand, some encoding options require additional computational resources, which will decrease the encoding performance. This can be considered as the "cost" of using these encoding settings. Some encoding options can improve video quality but may introduce encoding latency. In scenarios where real-time performance is required, using such encoding options may not be appropriate.
When fine-tuning video encoding, it is essential to have a clear understanding of the business scenarios associated with these encoding options.
This document will provide configuration recommendations for encoders based on typical video application scenarios. In the examples demonstrating how to configure the encoder, we will use FFmpeg as the application for illustration.
A preset refers to a predefined set of internal encoding parameters that determine the trade-off between video quality and encoding speed. Presets are used to simplify the process of selecting appropriate settings for different encoding scenarios.
Each preset is designed to optimize the encoding process for specific use cases. The presets typically vary in terms of the level of compression, encoding complexity, and resulting video quality.
It has three or four valid values (depending on the type of encoder used):
- high quality: This preset prioritizes quality as the primary consideration.
- quality: This preset is optimized for high video output, suitable for applications such as video production, broadcasting, and live streaming.
- balanced: This preset balances the trade-off between quality and speed, making it suitable for a variety of applications that require a balance between the two, such as video conferencing, game casting and webinar.
- speed: This preset prioritizes speed over quality, making it suitable for applications that require real-time video encoding with low latency, such as game streaming and remote desktop applications.
AMF encoder supports typical video encoder rate control methods.
- Constant QP: In this mode, all the blocks/CTBs/SBs are coded at the same QP/QPIndex (Supports setting QP/QPIndex based on different frame types I, P, B.) throughout the stream. In AVC/HEVC, QP ranges from 0 to 51, while in AV1, QPIndex ranges from 0 to 255. As is expected, the coded stream is variable in size, depending mainly on the complexity of the video contents.
- Constant bitrate (CBR): In video coding, CBR means that the bitrate generated by the encoder could be outputted at constant rate over certain period of time This can be guaranteed that the coded picture buffer (CPB) should never underflow, or filler data need to be inserted, and never overflow.
- Peak Constrained Variable bitrate (PCVBR): PCVBR means that the bitrate generated by the encoder could be outputted at non-constant rate. In other words, the CPB buffer is allowed to underflow.
- Quality Based Variable Bitrate (QVBR): This mode sets the RC mode to QUALITY_VBR and sets QVBR_QUALITY_LEVEL to 1 to 51, with 1 to be the worst quality, and 51 to be the best quality.
- High Quality Variable Bitrate (HQVBR): This mode sets the RC mode to HIGH_QUALITY_VBR. It is based on AMD patented technology on constant quality video coding.
- High Quality Constant Bitrate (HQCBR): This mode sets the RC mode to HIGH_QUALITY_CBR. It is based on AMD patented technology on constant quality video coding.
VBV Buffer Size refers to the capacity of the decoder's buffer, measured in bits. The encoder uses this buffer size to control the instantaneous variation in bitrate, ensuring that the decoder can consistently receive and play back the video stream within a set timeframe.
Preencode is a process that occurs before the actual encoding takes place. During preencode, the video encoder analyzes the input video to determine its visual characteristics and complexity. This information is then used to optimize the encoding process for the specific video content.
Set the number of B-frames between two reference frames (I- or P-frames). B-frames may have higher encoding efficiency than I- and P-frames, but they require a greater encoding overhead.
GOP size (Group of Pictures size) refers to the number of frames between two I-frames traditionally. A GOP starts with an I-frame, followed by several P-frames and/or B-frames.
High Motion Quality Boost is a parameter in video encoding that is typically used to address issues such as motion blur, pixelation, and artifacts that can occur in videos with fast-moving objects or high levels of motion.
AQ (Adaptive Quantization) works by analyzing the spatial complexity of each region in a frame, and intelligently varies the amount of quantization parameter applied based on the complexity of different areas within the frame.
Intra Refresh is primarily used as a replacement for the traditional I-frame (Intra Frame) refresh method. It gradually refreshes specific parts of video frames to achieve the effect of a keyframe, without needing to refresh the entire frame like an I-frame.
Preanalysis is the process of analyzing the input video prior to the actual encoding process. Preanalysis can involve several different operations, such as scene detection, motion analysis, and quantization parameter decision.
Lookahead in video encoding refers to a technique where the encoder analyzes a number of future frames (or part of the video) before deciding how to encode the current frame.
In video encoding, quantization is the process of reducing the precision of video data to reduce file size. Higher quantization levels result in lower quality but smaller file sizes, while lower quantization levels provide better quality but larger file sizes.
Adaptive mini-GOP allows the encoder to decide whether to use B-frames, and if so, how many, depending on the complexity of the video content.
We have summarized in the table below which dimension(s) --- performance, quality, or latency --- each encoding feature affects.
No | Encoding Feature | Quality | Performance | Latency |
---|---|---|---|---|
1 | Preset | ● | ● | ● |
2 | Rate control | ● | ● | ● |
3 | VBV buffer size | ● | ● | |
4 | Preencode | ● | ● | ● |
5 | B-frame | ● | ● | ● |
6 | GOP Size | ● | ||
7 | High Motion Quality Boost | ● | ● | ● |
8 | VBAQ or AQ | ● | ||
9 | Intra Refresh | ● | ||
10 | Preanalysis | ● | ● | ● |
11 | Lookahead | ● | ● | ● |
12 | TAQ Mode | ● | ● | ● |
13 | Adaptive B-Frame | ● | ● | ● |
The table below shows the correspondence between Encoding Features and AMF properties.
No | Encoding Feature | H.264 (Prefix "AMF_VIDEO_ENCODER_") | HEVC (Prefix "AMF_VIDEO_ENCODER_HEVC_") | AV1 (Prefix "AMF_VIDEO_ENCODER_AV1_") |
---|---|---|---|---|
1 | Preset | QUALITY_PRESET | QUALITY_PRESET | QUALITY_PRESET |
2 | Rate control | RATE_CONTROL_METHOD | RATE_CONTROL_METHOD | RATE_CONTROL_METHOD |
3 | VBV buffer size | VBV_BUFFER_SIZE | VBV_BUFFER_SIZE | VBV_BUFFER_SIZE |
4 | Preencode | PREENCODE_ENABLE | PREENCODE_ENABLE | RATE_CONTROL_PREENCODE |
5 | B-frame | B_PIC_PATTERN | B_PIC_PATTERN | |
6 | GOP Size | IDR_PERIOD | GOP_SIZE | GOP_SIZE |
7 | High Motion Quality Boost | HIGH_MOTION_QUALITY_BOOST_ENABLE | HIGH_MOTION_QUALITY_BOOST_ENABLE | HIGH_MOTION_QUALITY_BOOST_ENABLE |
8 | AQ | ENABLE_VBAQ | ENABLE_VBAQ | AQ_MODE |
9 | Intra Refresh | INTRA_REFRESH_NUM_MBS_PER_SLOT | INTRA_REFRESH_NUM_CTBS_PER_SLOT | INTRAREFRESH_STRIPES |
10 | Preanalysis | PRE_ANALYSIS_ENABLE | PRE_ANALYSIS_ENABLE | PRE_ANALYSIS_ENABLE |
11 | Lookahead Buffer Depth | AMF_PA_LOOKAHEAD_BUFFER_DEPTH | AMF_PA_LOOKAHEAD_BUFFER_DEPTH | AMF_PA_LOOKAHEAD_BUFFER_DEPTH |
12 | TAQ Mode | AMF_PA_TAQ_MODE | AMF_PA_TAQ_MODE | AMF_PA_TAQ_MODE |
13 | Adaptive B-Frame | AMF_PA_MINIGOP_ADAPTIVE_MINIGOP_ENABLE | AMF_PA_MINIGOP_ADAPTIVE_MINIGOP_ENABLE | AMF_PA_MINIGOP_ADAPTIVE_MINIGOP_ENABLE |
We provide two methods to guide users on how to set encoder parameters.
Given that performance, quality, and latency are the three key dimensions people typically consider when configuring an encoder, we have created a three-dimensional matrix. This matrix represents all possible combinations of values across these three dimensions: performance, quality, and latency.
- Performance dimension has three options: speed, balanced, fast quality, quality, high quality.
- Latency dimension has two options: low latency, high latency.
- Quality dimension has two options: normal quality, high quality.
Users can identify the combination that best suits their needs within the matrix below, and then configure their encoder based on the suggested parameter settings.
How encoder parameters work and how they affect encoding performance, quality, and latency require professional knowledge to fully understand. Most users of video encoders, however, have a better understanding of their own use cases than of the technical details of video encoders. Therefore, helping users set encoder parameters based on their specific use cases is a simpler and more intuitive approach.
The table below lists some typical application scenarios.
Use Case | Recommended AMF Encoder Settings |
---|---|
Archive | Preset = speed, balanced, quality or high quality Rate control mode = VBR VBV buffer size (4 seconds) PeakBitrate (4 second) Adaptive B-Frame B-frame as reference VBAQ (or AQ) enabled Preencode GOP Size = 10 second High Motion Quality Boost Preanalysis Lookahead Buffer Depth TAQ mode |
Video on Demand | Preset = speed, balanced, quality or high quality Rate control mode = VBR VBV buffer size (2 seconds) Adaptive B-Frame B-frame as reference VBAQ (or AQ) enabled Preencode GOP Size = 2 second High Motion Quality Boost Preanalysis Lookahead Buffer Depth TAQ mode |
Video Broadcast | Preset = speed, balanced, quality or high quality Rate control mode = CBR VBV buffer size (2 seconds) 2 B-Frame B-frame as reference VBAQ (or AQ) enabled Preencode GOP Size = 1 second High Motion Quality Boost Preanalysis Lookahead Buffer Depth TAQ mode |
Recording | Preset = quality or high quality Rate control mode = VBR VBV buffer size (2 seconds) 2 B-Frame B-frame as reference VBAQ (or AQ) enabled Preencode GOP Size = 2 second High Motion Quality Boost |
Online Streaming or Live Streaming | Preset = speed, balanced, quality or high quality Rate control mode = VBR VBV buffer size (2 seconds) 2 B-Frame B-frame as reference VBAQ (or AQ) enabled Preencode GOP Size = 2 second High Motion Quality Boost |
Game Cast Webinar |
Preset = speed, balanced, quality or high quality Rate control mode = CBR VBV buffer size (1 seconds) 2 B-Frame B-frame as reference VBAQ (or AQ) enabled Preencode GOP Size = 2 second High Motion Quality Boost |
Video Conference Game Streaming Webcam |
Preset = speed, balanced, quality or high quality Rate control mode = CBR VBV buffer size (0.1 seconds) No B-Frame VBAQ (or AQ) enabled GOP Size Infinite Intra Refresh |
Given the widespread use of FFmpeg in the ecosystem, the AMF encoder has provided comprehensive support for FFmpeg. Most of the key encoder parameters are supported in FFmpeg's AMF encoder. In the examples demonstrating how to set the encoder for those typical use cases, we will use FFmpeg as the application for illustration.
To understand the basics of configuring the FFmpeg AMF encoder, you may need to browse the page AMF Encoder Settings and Tuning in FFmpeg for the necessary assistance.
In the following sample command lines, for H.264 and HEVC, the preset
parameter can be replaced with speed
, balanced
, and quality
. For AV1, the preset
parameter can be replaced with speed
, balanced
, quality
, and high quality
. Using speed
results in faster encoding but sacrifices some quality, while quality
does the opposite, offering better quality at the cost of performance.
Suppose the input file input.mp4 framerate is 60 fps, resolution 1920x1080.
H.264
ffmpeg -i input.mp4 -c:v h264_amf -preset quality -rc vbr_peak -b:v 4000000 -maxrate 16000000 -bufsize 16000000 -vbaq true -preencode true -g 600 -high_motion_quality_boost_enable true -preanalysis true -max_b_frames 3 -pa_adaptive_mini_gop true -pa_lookahead_buffer_depth 40 -pa_taq_mode 2 output.mp4
HEVC
ffmpeg -i input.mp4 -c:v hevc_amf -preset quality -rc vbr_peak -b:v 4000000 -maxrate 16000000 -bufsize 16000000 -vbaq true -preencode true -g 600 -high_motion_quality_boost_enable true -preanalysis true -pa_lookahead_buffer_depth 40 -pa_taq_mode 2 output.mp4
AV1
ffmpeg -i input.mp4 -c:v av1_amf -preset quality -rc vbr_peak -b:v 4000000 -maxrate 16000000 -bufsize 16000000 -aq_mode caq -preencode true -g 600 -high_motion_quality_boost_enable true -preanalysis true -max_b_frames 3 -pa_adaptive_mini_gop true -pa_lookahead_buffer_depth 40 -pa_taq_mode 2 output.mp4
H.264
ffmpeg -i input.mp4 -c:v h264_amf -preset quality -rc vbr_peak -b:v 4000000 -maxrate 8000000 -bufsize 8000000 -vbaq true -preencode true -g 120 -high_motion_quality_boost_enable true -preanalysis true -max_b_frames 3 -pa_adaptive_mini_gop true -pa_lookahead_buffer_depth 40 -pa_taq_mode 2 output.mp4
HEVC
ffmpeg -i input.mp4 -c:v hevc_amf -preset quality -rc vbr_peak -b:v 4000000 -maxrate 8000000 -bufsize 8000000 -vbaq true -preencode true -g 120 -high_motion_quality_boost_enable true -preanalysis true -pa_lookahead_buffer_depth 40 -pa_taq_mode 2 output.mp4
AV1
ffmpeg -i input.mp4 -c:v av1_amf -preset quality -rc vbr_peak -b:v 4000000 -maxrate 8000000 -bufsize 8000000 -aq_mode caq -preencode true -g 120 -high_motion_quality_boost_enable true -preanalysis true -max_b_frames 3 -pa_adaptive_mini_gop true -pa_lookahead_buffer_depth 40 -pa_taq_mode 2 output.mp4
H.264
ffmpeg -i input.mp4 -c:v h264_amf -preset quality -rc cbr -b:v 4000000 -bufsize 8000000 -vbaq true -preencode true -g 60 -high_motion_quality_boost_enable true -preanalysis true -max_b_frames 2 -bf 2 -pa_lookahead_buffer_depth 40 -pa_taq_mode 2 output.mp4
HEVC
ffmpeg -i input.mp4 -c:v hevc_amf -preset quality -rc cbr peak -b:v 4000000 -bufsize 8000000 -vbaq true -preencode true -g 60 -high_motion_quality_boost_enable true -preanalysis true -pa_lookahead_buffer_depth 40 -pa_taq_mode 2 output.mp4
AV1
ffmpeg -i input.mp4 -c:v av1_amf -preset quality -rc cbr -b:v 4000000 -bufsize 8000000 -aq_mode caq -preencode true -g 60 -high_motion_quality_boost_enable true -preanalysis true -max_b_frames 2 -bf 2 -pa_lookahead_buffer_depth 40 -pa_taq_mode 2 output.mp4
H.264
ffmpeg -i input.mp4 -c:v h264_amf -preset quality -rc vbr_peak -b:v 4000000 -maxrate 8000000 -bufsize 8000000 -vbaq true -preencode true -g 120 -high_motion_quality_boost_enable true -max_b_frames 3 -bf 2 output.mp4
HEVC
ffmpeg -i input.mp4 -c:v hevc_amf -preset quality -rc vbr_peak -b:v 4000000 -maxrate 8000000 -bufsize 8000000 -vbaq true -preencode true -g 120 -high_motion_quality_boost_enable true output.mp4
AV1
ffmpeg -i input.mp4 -c:v av1_amf -preset high_quality -rc vbr_peak -b:v 4000000 -maxrate 8000000 -bufsize 8000000 -aq_mode caq -preencode true -g 120 -high_motion_quality_boost_enable true -max_b_frames 3 -bf 2 output.mp4
H.264
ffmpeg -i input.mp4 -c:v h264_amf -preset quality -rc vbr_peak -b:v 4000000 -maxrate 8000000 -bufsize 8000000 -vbaq true -preencode true -g 120 -high_motion_quality_boost_enable true -max_b_frames 3 -bf 2 output.mp4
HEVC
ffmpeg -i input.mp4 -c:v hevc_amf -preset quality -rc vbr_peak -b:v 4000000 -maxrate 8000000 -bufsize 8000000 -vbaq true -preencode true -g 120 -high_motion_quality_boost_enable true output.mp4
AV1
ffmpeg -i input.mp4 -c:v av1_amf -preset quality -rc vbr_peak -b:v 4000000 -maxrate 8000000 -bufsize 8000000 -aq_mode caq -preencode true -g 120 -high_motion_quality_boost_enable true -max_b_frames 3 -bf 2 output.mp4
H.264
ffmpeg -i input.mp4 -c:v h264_amf -preset quality -rc cbr -b:v 4000000 -bufsize 4000000 -vbaq true -preencode true -g 120 -high_motion_quality_boost_enable true -max_b_frames 3 -bf 2 output.mp4
HEVC
ffmpeg -i input.mp4 -c:v hevc_amf -preset quality -rc cbr -b:v 4000000 -bufsize 4000000 -vbaq true -preencode true -g 120 -high_motion_quality_boost_enable true output.mp4
AV1
ffmpeg -i input.mp4 -c:v av1_amf -preset quality -rc cbr -b:v 4000000 -bufsize 4000000 -aq_mode caq -preencode true -g 120 -high_motion_quality_boost_enable true -max_b_frames 3 -bf 2 output.mp4
H.264
ffmpeg -i input.mp4 -c:v h264_amf -preset quality -rc cbr -b:v 4000000 -bufsize 200000 -vbaq true -preencode true -g 120 -high_motion_quality_boost_enable true -intra_refresh_mb 1 output.mp4
Recommendation: Set -intra_refresh_mb to 1. The AMF encoder will infer how many slots to encode per frame using the -g parameter (group size). Ideally, the -g parameter should be set to width/16. If more frequent refresh is desired, reduce the -g value (recommended for widths greater than 1920). If sparser refresh is needed, increase the -g value (can be considered for widths less than 1280).
HEVC
ffmpeg -i input.mp4 -c:v hevc_amf -preset quality -rc cbr -b:v 4000000 -bufsize 200000 -vbaq true -g 240 output.mp4
AV1
ffmpeg -i input.mp4 -c:v av1_amf -preset quality -rc cbr -b:v 4000000 -bufsize 200000 -aq_mode caq -g 240 output.mp4
Acronym | Definition |
---|---|
AMD | Advanced Micro Devices |
AMF | Advanced Media Framework |
CBR | Constant Bit Rate |
CPU | Central Processing Unit |
CQP | Constant Quantization Parameter |
GOP | Group of Picture |
GPU | Graphics Processing Unit |
HEVC | High Efficiency Video Coding |
HQCBR | High Quality Constant Bit Rate |
HQVBR | High Quality Variable Bit Rate |
LCVBR | Latency Constrained Variable Bit Rate |
ME | Motion Estimation |
MKV | Matroska Video files |
MP4 | MPEG-4 Part 14 |
PA | Pre-Analysis |
PCVBR | Peak Constrained Variable Bit Rate |
PSNR | Peak Signal-to-Noise Ratio |
QP | Quantization Parameter |
QVBR | Quality Variable Bit Rate |
SSIM | Multi-Scale Structural Similarity Index Measure |
TAQ | Temporal Adaptive Quantization |
VBR | Variable Bit Rate |
VBV | Video Buffering Verifier |