Skip to content

Advanced Encoder Configuration

ReferenceType edited this page Mar 12, 2025 · 3 revisions

Advanced H.264 Encoder Configuration

The OpenH264 library provides extensive configuration options to fine-tune the H.264 encoding process. This section details the advanced configuration parameters available through the TagEncParamExt structure, demonstrating how to customize encoding behavior for various scenarios.

Table of Contents

Configuration Parameters

The TagEncParamExt structure encapsulates a wide range of encoding parameters. Below is a breakdown of key fields and their significance:

Basic Settings

ParameterTypeDescriptionExample
iUsageTypeEUsageTypeSpecifies the usage scenario, such as real-time camera video (CAMERA_VIDEO_REAL_TIME), screen capture, etc.EUsageType.CAMERA_VIDEO_REAL_TIME
iPicWidthintSets the width of the input video frames in pixels.iPicWidth = 1280
iPicHeightintSets the height of the input video frames in pixels.iPicHeight = 720
iTargetBitrateintDefines the desired bitrate for the encoded video in bits per second.iTargetBitrate = 1000000 (1 Mbps)
iTemporalLayerNumintSpecifies the number of temporal layers for scalable video coding (SVC).iTemporalLayerNum = 1 (no temporal scalability)
iSpatialLayerNumintSpecifies the number of spatial layers for scalable video coding (SVC).iSpatialLayerNum = 1 (no spatial scalability)
iRCModeRC_MODESSets the rate control mode, such as constant bitrate (RC_BITRATE_MODE).RC_MODES.RC_BITRATE_MODE

Spatial Layer Settings

(sSpatialLayers[0])

ParameterTypeDescriptionExample
iVideoWidthintSets the width of the spatial layer, if spatial scalability is enabled.iVideoWidth = 0
iVideoHeightintSets the height of the spatial layer, if spatial scalability is enabled.iVideoHeight = 0
fFrameRatefloatSpecifies the target frame rate for the spatial layer.fFrameRate = 60
iSpatialBitrateintSets the bitrate for the spatial layer.iSpatialBitrate = 1000000
uiProfileIdcEProfileIdcDefines the H.264 profile, such as High profile (PRO_HIGH).EProfileIdc.PRO_HIGH
uiLevelIdcintSets the H.264 level.uiLevelIdc = 0
iDLayerQpintSets the QP value for the layer.iDLayerQp = 0

Advanced Settings

ParameterTypeDescriptionExample
iComplexityModeECOMPLEXITY_MODEControls the encoder's complexity, affecting encoding speed and quality.ECOMPLEXITY_MODE.HIGH_COMPLEXITY
uiIntraPeriodintSets the interval between intra (I) frames.uiIntraPeriod = 300
iNumRefFrameintSpecifies the number of reference frames used for motion estimation.iNumRefFrame = 0
eSpsPpsIdStrategyEParameterSetStrategyDefines the strategy for handling Sequence Parameter Sets (SPS) and Picture Parameter Sets (PPS).EParameterSetStrategy.SPS_LISTING_AND_PPS_INCREASING
bPrefixNalAddingCtrlboolControl prefix nal adding.bPrefixNalAddingCtrl = false
bEnableSSEIboolEnable Supplemental Enhancement Information.bEnableSSEI = true
bSimulcastAVCboolEnable simulcast AVC.bSimulcastAVC = false
iPaddingFlagintPadding flag.iPaddingFlag = 0
iEntropyCodingModeFlagintEntropy coding mode flag (0: CAVLC, 1: CABAC).iEntropyCodingModeFlag = 1 (CABAC)
bEnableFrameSkipboolEnables frame skipping.bEnableFrameSkip = false
iMaxBitrateintSets the maximum bitrate.iMaxBitrate = 0
iMinQpintSets the minimum quantization parameter.iMinQp = 0
iMaxQpintSets the maximum quantization parameter.iMaxQp = 51
uiMaxNalSizeintMaximum NAL unit size.uiMaxNalSize = 0
bEnableLongTermReferenceboolEnables long-term reference frames.bEnableLongTermReference = true
iLTRRefNumintSets the number of long-term reference frames.iLTRRefNum = 1
iLtrMarkPeriodintSets the marking period for long-term reference frames.iLtrMarkPeriod = 180
iMultipleThreadIdcintControls multi-threading.iMultipleThreadIdc = 1
bUseLoadBalancingboolEnables load balancing.bUseLoadBalancing = true

Quality Enhancements

ParameterTypeDescriptionExample
bEnableDenoiseboolEnables denoising.bEnableDenoise = false
bEnableBackgroundDetectionboolEnables background detection.bEnableBackgroundDetection = true
bEnableAdaptiveQuantboolEnables adaptive quantization.bEnableAdaptiveQuant = true
bEnableSceneChangeDetectboolEnables scene change detection.bEnableSceneChangeDetect = true
bIsLosslessLinkboolEnables lossless link.bIsLosslessLink = false
bFixRCOverShootboolFixes rate control overshoot.bFixRCOverShoot = true
iIdrBitrateRatiointIDR frame bitrate ratio.iIdrBitrateRatio = 400
fMaxFrameRatefloatMaximum frame rate.fMaxFrameRate = 30

Usage Example

encoder=newH264Encoder();varparam=encoder.GetDefaultParameters();param.iUsageType=EUsageType.CAMERA_VIDEO_REAL_TIME;param.iPicWidth=w;param.iPicHeight=h;param.iTargetBitrate=1000000;param.iTemporalLayerNum=1;param.iSpatialLayerNum=1;param.iRCMode=RC_MODES.RC_BITRATE_MODE;param.sSpatialLayers[0].iVideoWidth=0;param.sSpatialLayers[0].iVideoWidth=0;param.sSpatialLayers[0].fFrameRate=60;param.sSpatialLayers[0].iSpatialBitrate=1000000;param.sSpatialLayers[0].uiProfileIdc=EProfileIdc.PRO_HIGH;param.sSpatialLayers[0].uiLevelIdc=0;param.sSpatialLayers[0].iDLayerQp=0;param.iComplexityMode=ECOMPLEXITY_MODE.HIGH_COMPLEXITY;param.uiIntraPeriod=300;param.iNumRefFrame=0;param.eSpsPpsIdStrategy=EParameterSetStrategy.SPS_LISTING_AND_PPS_INCREASING;param.bPrefixNalAddingCtrl=false;param.bEnableSSEI=true;param.bSimulcastAVC=false;param.iPaddingFlag=0;param.iEntropyCodingModeFlag=1;param.bEnableFrameSkip=false;param.iMaxBitrate=0;param.iMinQp=0;param.iMaxQp=51;param.uiMaxNalSize=0;param.bEnableLongTermReference=true;param.iLTRRefNum=1;param.iLtrMarkPeriod=180;param.iMultipleThreadIdc=1;param.bUseLoadBalancing=true;param.bEnableDenoise=false;param.bEnableBackgroundDetection=true;param.bEnableAdaptiveQuant=true;param.bEnableSceneChangeDetect=true;param.bIsLosslessLink=false;param.bFixRCOverShoot=true;param.iIdrBitrateRatio=400;param.fMaxFrameRate=30;encoder.Initialize(param);

Clone this wiki locally