4. Bit Rate Control Topics¶
4.1. Bit Rate Stability¶
Dropping frames when the bit rate exceeds a threshold reduces instantaneous bit rate fluctuations during rapid scene changes while maintaining image quality
Recommended settings:
VENC_FRAMELOST_S::bFrmLostOpen = TRUE
VENC_FRAMELOST_S::u32FrmLostBpsThr = u32BitRate * 1.2
VENC_FRAMELOST_S::enFrmLostMode = FRMLOST_PSKIP
VENC_FRAMELOST_S::u32EncFrmGaps = 1
4.2. Image Quality Improvement¶
u32MaxIQp and u32MaxQp limit the maximum macroblock QP. A lower maximum QP can preserve image quality during low-bit-rate encoding or rapid scene changes, but may also cause bit rate overshoot. Adjust the maximum QP according to application requirements
4.3. Adjust Breathing Effects¶
s32IPQPDelta is the QP difference between I and P frames. An appropriate difference can reduce breathing effects. A larger difference is recommended for static scenes. Recommended values: [2, 6] for static scenes and [2, 4] for dynamic scenes
When noise is high in low-light scenes, slightly reduce s32IPQPDelta. Reducing the I-frame bit rate to increase the P-frame bit rate can prevent high-quality I-frames from introducing excessive noise and breathing effects.
4.4. Limit I-Frame Size¶
Setting a minimum I-frame QP can reduce the I-frame bit rate, but may reduce image quality.useonnoteasycontrol, need toforscenehasuseonalreadyverify beforecanhasbetterset. bit ratepasshighcasestillmayoccur.
4.5. Reduce Motion Ghosting¶
Texture-level bit rate control can effectively reduce noticeable ghosting in flat areas. Fine-tune the texture macroblock-level bit rate control parameters to reduce ghosting and increase detail. Increasing the QP of complex texture areas also increases distortion there, so balance the settings according to the target bit rate and scene.
4.6. Reduce Chroma Shift¶
cb_qp_offset and cr_qp_offset adjust chroma quality. Lowering the chroma QP improves chroma image quality and reduces color shifts, but may reduce luma quality. Balance the settings according to the target bit rate and scene.
4.7. Initial QP for Bit Rate Control¶
Set an appropriate initial QP according to the scene, bit rate, resolution, and other factors. Users can configure the initial QP with VENC_RC_PARAM_S::s32FirstFrameStartQp. This API is effective when called after channel creation and before encoding the first frame.
4.8. Low-Bit-Rate Scenarios¶
Enable texture-based macroblock-level bit rate control and set the recommended parameters or fine-tune them. For example, set u32ThrdLv=3 for outdoor scenes.
Reduce the frame rate appropriately for the scene. For example, set the target frame rate to 20 fps.
Dynamically reduce the frame rate by encoding PSkip frames: VENC_FRAMELOST_S::enFrmLostMode = FRMLOST_PSKIP; VENC_FRAMELOST_S::u32EncFrmGaps = 1.
Set a large GOP and make the bit rate statistics duration u32StatTime match the GOP value. Set GOP to 5 to 10 times the frame rate; for example, for 30 fps, set GOP to 150 to 300 and u32StatTime to 5 to 10 seconds.
SmartP mode is recommended for mostly static scenes such as fixed cameras. When using SmartP mode, u32BgInterval should match u32StatTime.
Reduce the sensitivity of ISP module AE and increase the AE response delay to avoid frequent AE adjustments after changes in light.
Increase 3DNR strength and appropriately reduce Sharpen strength to reduce image detail.
4.9. Precautions¶
u32Gop: Set it to an integer multiple of the encoding frame rate. Otherwise, uneven temporal distribution of I-frames may cause instantaneous bit rate fluctuations.
u32StatTime: Set it to an integer multiple of (GOP/fps). For example, at 30 fps with GOP=60, the statistics duration should be an integer multiple of 2 seconds. Otherwise, the bit rate may be inaccurate.
u32MaxIQp and u32MaxQp: Limit the maximum intra-frame QP. When prioritizing quality, [40, 46] is recommended, but bit rate overshoot is more likely.
u32MinQp and u32MinIQp: Limit the minimum intra-frame QP. Proper settings save bit rate in static or low-motion scenes.
An ROI QP that is too low affects bit rate control stability. Set the ROI according to the target bit rate.
OSD images usually contain text with sharp edges. An excessively large OSD area may increase encoding load.