Guide to SVT-AV1 Encoder API Initialization
This article provides a direct guide to initializing the SVT-AV1
(libsvtav1) video encoder using its C API. It details the
essential structures and sequential function calls required to allocate
encoder handles, configure encoding parameters, and initialize the
encoder state to prepare for video compression.
Essential Structures
To initialize the SVT-AV1 encoder, you must work with two primary structures defined in the library’s headers:
EbComponentType
This is the component handle that represents the encoder instance. All subsequent API calls targeting the encoder will require a pointer to this handle.EbSvtAv1EncConfiguration
This structure contains all the configuration parameters for the encoding process, such as video resolution, frame rate, bit depth, rate control mode, target bitrate, and preset speeds.
Sequential Initialization Steps and Functions
Initializing the SVT-AV1 encoder requires a strict four-step sequence of function calls.
Step 1: Initialize the Handle and Default Parameters
Before configuring the encoder, you must allocate the component
handle and populate the configuration structure with default settings.
This is achieved using the svt_av1_enc_init_handle
function.
EbComponentType *svt_handle = NULL;
EbSvtAv1EncConfiguration svt_config;
EbErrorType return_error = svt_av1_enc_init_handle(&svt_handle, NULL, &svt_config);
if (return_error != EB_ErrorNone) {
// Handle initialization handle error
}svt_av1_enc_init_handle: Allocates memory for theEbComponentTypehandle and fills theEbSvtAv1EncConfigurationstruct with default configuration values.
Step 2: Configure Encoding Parameters
After receiving the default configuration, you must modify the fields
of the EbSvtAv1EncConfiguration structure to match your
input video properties and target output quality.
At a minimum, you must specify: * Source width and height
(source_width, source_height) * Frame rate
numerator and denominator (frame_rate_numerator,
frame_rate_denominator) * Color format and bit depth
(encoder_color_format, encoder_bit_depth)
svt_config.source_width = 1920;
svt_config.source_height = 1080;
svt_config.frame_rate_numerator = 60000;
svt_config.frame_rate_denominator = 1001;
svt_config.encoder_bit_depth = 8;
svt_config.encoder_color_format = EB_YUV420;Step 3: Apply the Configuration Parameters
Once the configuration structure is updated, you must apply these
parameters to the encoder handle using
svt_av1_enc_set_parameter.
return_error = svt_av1_enc_set_parameter(svt_handle, &svt_config);
if (return_error != EB_ErrorNone) {
// Handle parameter setting error
}svt_av1_enc_set_parameter: Validates the parameters inside your configuration structure and applies them to the allocated encoder instance.
Step 4: Initialize the Encoder Instance
The final step is to initialize the encoder instance, which allocates
the internal buffers, threads, and resources needed for the encoding
pipeline. This is triggered by calling
svt_av1_enc_init.
return_error = svt_av1_enc_init(svt_handle);
if (return_error != EB_ErrorNone) {
// Handle final initialization error
}svt_av1_enc_init: Completes the setup. Once this function returnsEB_ErrorNone, the encoder is fully initialized and ready to receive input video frames viasvt_av1_enc_send_picture.