Skip to content

[Question]: (H.264) How to enforce limit of maximum encoded frame size in bits? #577

@samisallinen

Description

@samisallinen

Our streaming application requires minimum latency, so we'd like to enforce a maximum for encoded frame size in bits to have an upper bound for the network transfer delay for the encoded data.

We're initializing the encoder like this:

  SETPROPERTY(pEncoder, AMF_VIDEO_ENCODER_USAGE, AMF_VIDEO_ENCODER_USAGE_ULTRA_LOW_LATENCY);          
  pEncoder->SetProperty(AMF_VIDEO_ENCODER_B_PIC_PATTERN, 0);
  SETPROPERTY(pEncoder, AMF_VIDEO_ENCODER_TARGET_BITRATE, bitRate);
  SETPROPERTY(pEncoder, AMF_VIDEO_ENCODER_FRAMERATE, ::AMFConstructRate(frameRate, 1));

  SETPROPERTY(pEncoder, AMF_VIDEO_ENCODER_RATE_CONTROL_METHOD,    AMF_VIDEO_ENCODER_RATE_CONTROL_METHOD_LATENCY_CONSTRAINED_VBR);     
  SETPROPERTY(pEncoder, AMF_VIDEO_ENCODER_ENFORCE_HRD, true);
  SETPROPERTY(pEncoder, AMF_VIDEO_ENCODER_FILLER_DATA_ENABLE, false);
  SETPROPERTY(pEncoder, AMF_VIDEO_ENCODER_VBV_BUFFER_SIZE, static_cast<amf_int64>((1.3 * bitRate / (frameRate)))); 

Then before submitting every frame, we've tried various combinations of the following (including none of them):

  SETPROPERTY_BOOLRET(AMF_VIDEO_ENCODER_RATE_CONTROL_METHOD, AMF_VIDEO_ENCODER_RATE_CONTROL_METHOD_LATENCY_CONSTRAINED_VBR); 
  SETPROPERTY_BOOLRET(AMF_VIDEO_ENCODER_TARGET_BITRATE, static_cast<amf_int64>(0.75*m_bitRate * m_currBandwidthAdjustment));      
  SETPROPERTY_BOOLRET(AMF_VIDEO_ENCODER_PEAK_BITRATE, static_cast<amf_int64>(0.85*m_bitRate * m_currBandwidthAdjustment));
  SETPROPERTY_BOOLRET(AMF_VIDEO_ENCODER_VBV_BUFFER_SIZE, static_cast<amf_int64>((1.3*m_bitRate * m_currBandwidthAdjustment / (m_frameRate))));      
  SETPROPERTY_BOOLRET(AMF_VIDEO_ENCODER_INITIAL_VBV_BUFFER_FULLNESS, static_cast<amf_int64>(32));

Being desperate enough, we've tried various fudge factors on the target and peak bitrates and the vbv buffer size.

However, when there are step changes in the input video data, we get a lot larger frames output than what we are asking for:

Image

(Target bitrate 8Mbit/s, individual frame sizes (purple graph) hit ~19Mbit/s. The average bitrate seems to be somewhat close to what we're asking.

We have tried a lot of different combinations and parameters, including AMF_VIDEO_ENCODER_RATE_CONTROL_SKIP_FRAME_ENABLE, but so far haven't found the solution.

Any advise on what we're doing wrong would be greatly appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions