TK1 H264 encoder bitrate/profile/level issue

I performed various bitrate tests on TK1 h264 encoder and I found bitrate/profile/level setting has some issues. My software version is R21.4.

  1. For bitrate even in the CBR mode (rc-mode=0), the lowest bitrate we can go is 500kbps for 1024x768. It looks like the encoder is trying to maintain some minimum framesize in the rate control algorithm.
GST_DEBUG=2 gst-launch-1.0 -vvv videotestsrc ! 'video/x-raw, format=(string)I420,width=(int)1024, height=(int)768' ! omxh264enc rc-mode=0 bitrate=500000  ! 'video/x-h264, stream-format=(string)avc' ! h264parse ! queue name=queenc !  mpegtsmux name=mux ! filesink location=test_low_500k.ts -e

2.Profile and level is hardcoded as CBP and level4.1. We would like to use up to high profile and level5.0, as we want to use CABAC and B frames. I tried to changed the code in gstomx1 but it seems that the encoder just ignore the setting in omx.

Does someone has the similar issue? Could NVIDIA experts provide some help on this?
Thanks

This is a table of minimum bitrate I can go for different resolution:
1920x1080: ~1Mbps
1024x768: ~600Kbps
720x480: ~500Kpbbps

Does someone also notice the similar issue?

Hello, dk1900:

  1. bitrate
    With omxh264enc, there are 2 properties:‘control-rate’ and ‘bitrate’. By default, ‘control-rate’ is ‘variable’. You can change that to ‘constant’, and change prop ‘bitrate’ to see the result.
  2. Profile and level
    default level should be configured in /etc/enctune.conf, but profile should be set with a parameter.
    In high profile, we use CABAC default. B frames, we need a parameter to set b_frame_nums. You can try it.

br
ChenJian

Hi Jian,

  1. I have set the control-rate as CBR during my test and I found that the bitrate issue only happens in I-only mode. For the same configuration, the bitrate setting for I-only will not be respected by encoder, but seems ok if I change GOP size to be a relatively large value like 15. To me, it looks like the I frame size of H264 encoder has a minimum size setting and that’s why the bitrate cannot be lower than a certain value for I-only mode.

  2. I have tried the level setting in enctune.conf but I did not see it make any difference. I also tried changed it directly in the GstOmx1 code NVIDIA, I can change the level but cannot change the profile. I checked the output bitstream and profile is always CBP.

dk1900,
Sorry to drop the ball …we will need to revisit the issue using TK1/r21.5. Is there a test stream you are using we can check to ensure we are talking about the same observation? Thanks.

You can just use standard gstreamer videotestsrc pattern.

Hi dk,
The issue here is that high profile cannot be configured?

Hi DaneLLL,

Sorry for the confusion. I can set high profile to omxh264enc but I am no seeing the coding tool set being used. For example, I am seeing no B frames at all from the following gstreamer pipeline.

gst-launch-1.0 videotestsrc is-live=true do-timestamp=true ! video/x-raw, format=I420, width=1920, height=1080, framerate=30/1 ! omxh264enc insert-sps-pps=true iframeinterval=10 no-B-Frames=false profile=high ! video/x-h264, stream-format=byte-stream !  filesink location=/tmp/nv.264

Hi dk1900,
It is a SW issue and it should be number of B frames. Please rebuild libgstomx.so by referring to the following sample(hack to have two B frames between P frames):

--- a/omx/gstomxh264enc.c
+++ b/omx/gstomxh264enc.c
@@ -735,6 +735,7 @@ gst_omx_set_avc_encoder_property (GstOMXVideoEnc * enc)
       OMX_IndexParamVideoAvc, &oH264Type);
   if (eError == OMX_ErrorNone) {
     oH264Type.nBFrames = self->no_BFrames;
+    oH264Type.nBFrames = 2;
     oH264Type.nSliceHeaderSpacing = self->slice_header_spacing;
     oH264Type.eProfile = self->profile;

Thanks DaneLLL. This patch did fix the B frame issue.

I guess one last question is whether CABAC supported by TK1 omxh264enc or not? I am parsing the frame header and still see it is off.
In our usecase, the bandwidth is quite limited. Enabling cabac can save us significant amount bandwidth.

Thanks

Hi dk,
How do you check CAVLC/CABAC mode? I can see entropy_coding_mode_flag is set to 1 in high profile bitstream.

Hi DaneLLL,

There were some issue with my old tool and now I can confirm that CABAC flag is set in the bitstream.
Thanks for your help