H264 encoder inconsistent bitrate issue

We are using Multimedia API 28.1 video encoder to encode H264 video stream at 30FPS with resolution 1080p. The rate control mode is VBR.

We constantly adjust the encoder bitrate using NvVideoEncoder::setBitrate() API based on estimated network bandwidth. While sometimes we can get requested bitrate, but other times, we only get portion of the request bitrate. For example, we requested 5Mbps, but the encoder only output ~2Mbps. After comparing the metadata of encoded frames of these two scenarios, we found when we got the desired bitrate, the average QP was around 20, whereas when we got less bitrate than we asked, the average QP was around 28. Additionally, if we fix our QP by using the API NvVideoEncoder::setQpRange() to 20, the encoder does give us higher bitrate, however the actual bitrate is less stable, we saw many spikes where the output bitrate exceeded what we requested.

What is the right way to set up the encoder in order to have it output requested bitrate all the time?

Hi rong1129,

I’m struggling with unstable output bit rate, too.

Then I count NAL unit size between each IDR and the next IDR,
compare the bitrate set by setBitrate(),
and feed-back the difference to setBitrate().

Best Regards,

The problem I’m having is even if I ask it for say 5Mbps, it only produces around 2Mbps stream, and it’s the same if I ask it for 10Mbps or more. However, in some cases, I do get what I asked for (6M). It looks to me the encoder somehow chooses the QP value on the fly, but I’m having trouble figuring out what factor(s) it uses to determine the right QP for a requested bitrate. I checked my output and capture queue size, they were both fed/drained every 33ms or so, and the encoder profile showed the average FPS was 30FPS.

Anyone knows how the encoder chooses the QP value for the incoming frames?

Have you tried with cbr mode, then set your bit rate?
Normally bit variation should be low than 5%.