- Notifications
You must be signed in to change notification settings - Fork 9
Advanced Encoder Configuration
ReferenceType edited this page Mar 12, 2025
·
3 revisions
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.
- Configuration Parameters
- Basic Settings
- Spatial Layer Settings
- Advanced Settings
- Quality Enhancements
- Usage Example
The TagEncParamExt structure encapsulates a wide range of encoding parameters. Below is a breakdown of key fields and their significance:
| Parameter | Type | Description | Example |
|---|---|---|---|
iUsageType | EUsageType | Specifies the usage scenario, such as real-time camera video (CAMERA_VIDEO_REAL_TIME), screen capture, etc. | EUsageType.CAMERA_VIDEO_REAL_TIME |
iPicWidth | int | Sets the width of the input video frames in pixels. | iPicWidth = 1280 |
iPicHeight | int | Sets the height of the input video frames in pixels. | iPicHeight = 720 |
iTargetBitrate | int | Defines the desired bitrate for the encoded video in bits per second. | iTargetBitrate = 1000000 (1 Mbps) |
iTemporalLayerNum | int | Specifies the number of temporal layers for scalable video coding (SVC). | iTemporalLayerNum = 1 (no temporal scalability) |
iSpatialLayerNum | int | Specifies the number of spatial layers for scalable video coding (SVC). | iSpatialLayerNum = 1 (no spatial scalability) |
iRCMode | RC_MODES | Sets the rate control mode, such as constant bitrate (RC_BITRATE_MODE). | RC_MODES.RC_BITRATE_MODE |
(sSpatialLayers[0])
| Parameter | Type | Description | Example |
|---|---|---|---|
iVideoWidth | int | Sets the width of the spatial layer, if spatial scalability is enabled. | iVideoWidth = 0 |
iVideoHeight | int | Sets the height of the spatial layer, if spatial scalability is enabled. | iVideoHeight = 0 |
fFrameRate | float | Specifies the target frame rate for the spatial layer. | fFrameRate = 60 |
iSpatialBitrate | int | Sets the bitrate for the spatial layer. | iSpatialBitrate = 1000000 |
uiProfileIdc | EProfileIdc | Defines the H.264 profile, such as High profile (PRO_HIGH). | EProfileIdc.PRO_HIGH |
uiLevelIdc | int | Sets the H.264 level. | uiLevelIdc = 0 |
iDLayerQp | int | Sets the QP value for the layer. | iDLayerQp = 0 |
| Parameter | Type | Description | Example |
|---|---|---|---|
iComplexityMode | ECOMPLEXITY_MODE | Controls the encoder's complexity, affecting encoding speed and quality. | ECOMPLEXITY_MODE.HIGH_COMPLEXITY |
uiIntraPeriod | int | Sets the interval between intra (I) frames. | uiIntraPeriod = 300 |
iNumRefFrame | int | Specifies the number of reference frames used for motion estimation. | iNumRefFrame = 0 |
eSpsPpsIdStrategy | EParameterSetStrategy | Defines the strategy for handling Sequence Parameter Sets (SPS) and Picture Parameter Sets (PPS). | EParameterSetStrategy.SPS_LISTING_AND_PPS_INCREASING |
bPrefixNalAddingCtrl | bool | Control prefix nal adding. | bPrefixNalAddingCtrl = false |
bEnableSSEI | bool | Enable Supplemental Enhancement Information. | bEnableSSEI = true |
bSimulcastAVC | bool | Enable simulcast AVC. | bSimulcastAVC = false |
iPaddingFlag | int | Padding flag. | iPaddingFlag = 0 |
iEntropyCodingModeFlag | int | Entropy coding mode flag (0: CAVLC, 1: CABAC). | iEntropyCodingModeFlag = 1 (CABAC) |
bEnableFrameSkip | bool | Enables frame skipping. | bEnableFrameSkip = false |
iMaxBitrate | int | Sets the maximum bitrate. | iMaxBitrate = 0 |
iMinQp | int | Sets the minimum quantization parameter. | iMinQp = 0 |
iMaxQp | int | Sets the maximum quantization parameter. | iMaxQp = 51 |
uiMaxNalSize | int | Maximum NAL unit size. | uiMaxNalSize = 0 |
bEnableLongTermReference | bool | Enables long-term reference frames. | bEnableLongTermReference = true |
iLTRRefNum | int | Sets the number of long-term reference frames. | iLTRRefNum = 1 |
iLtrMarkPeriod | int | Sets the marking period for long-term reference frames. | iLtrMarkPeriod = 180 |
iMultipleThreadIdc | int | Controls multi-threading. | iMultipleThreadIdc = 1 |
bUseLoadBalancing | bool | Enables load balancing. | bUseLoadBalancing = true |
| Parameter | Type | Description | Example |
|---|---|---|---|
bEnableDenoise | bool | Enables denoising. | bEnableDenoise = false |
bEnableBackgroundDetection | bool | Enables background detection. | bEnableBackgroundDetection = true |
bEnableAdaptiveQuant | bool | Enables adaptive quantization. | bEnableAdaptiveQuant = true |
bEnableSceneChangeDetect | bool | Enables scene change detection. | bEnableSceneChangeDetect = true |
bIsLosslessLink | bool | Enables lossless link. | bIsLosslessLink = false |
bFixRCOverShoot | bool | Fixes rate control overshoot. | bFixRCOverShoot = true |
iIdrBitrateRatio | int | IDR frame bitrate ratio. | iIdrBitrateRatio = 400 |
fMaxFrameRate | float | Maximum frame rate. | fMaxFrameRate = 30 |
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);