H.264 CBR Encoding Problems

Hi,

I’m having difficulty with the h.264 encoder. Much of the content I am trying to encode contains high detail; so much detail that it could be considered similar to random noise. An example of this would be an aerial shot of a corn field or forest.

The encoder is configured as CBR, but it will not obey the bitrate at lower bitrates. Here is a sample pipeline:

gst-launch-1.0 videotestsrc num-buffers=48 pattern=1 ! 'video/x-raw,width=1920,height=1080,format=I420,framerate=24/1' ! omxh264enc iframeinterval=12 bitrate=3000000 control-rate=constant num-B-Frames=0 qp-range=32,51:32,51:60,61 EnableTwopassCBR=true EnableStringentBitrate=true ! identity silent=0 ! qtmux ! filesink location=/tmp/test.mp4 -v

I see that most frames generated are around 60kB. I set the bitrate to 3mbps, but it is producing 11.5mbps in this case.

While we can’t support HEVC, I did try the same with omxh265enc, and it did respect bitrate.

Here is the equivalent H.265 command:

gst-launch-1.0 videotestsrc num-buffers=48 pattern=1 ! 'video/x-raw,width=1920,height=1080,format=I420,framerate=24/1' ! omxh265enc iframeinterval=12 bitrate=3000000 control-rate=constant qp-range=32,51:32,51:60,61 EnableTwopassCBR=true EnableStringentBitrate=true ! identity silent=0 ! matroskamux ! filesink location=/tmp/test.mkv -v

Hi phabsch,
Are you on r28.2.1?

I don’t know the sub, sub version, but I know it is a flavour of 28.2. This has been a persistent problem dating back many versions. I also see this on the TK1 platform.

Can you please take a look and try to reproduce? I did offer a very simple command line to demonstrate the issue.

Thanks.

You can get your exact L4T version with

head -n 1 /etc/nv_tegra_release

R28 (release), REVISION: 2.0, GCID: 10567845, BOARD: t186ref, EABI: aarch64, DATE: Fri Mar 2 04:57:01 UTC 2018

So, 2.0

Have you verified that CBR encoding works properly in 2.2, but not in 2.0?

Hi phabsch,
The case hits HW limitation.

We get the h264stream:

$ gst-launch-1.0 videotestsrc num-buffers=48 pattern=1 ! 'video/x-raw,width=1920,height=1080,format=I420,framerate=24/1' ! omxh264enc iframeinterval=12 bitrate=3000000 control-rate=constant num-B-Frames=0 qp-range=32,51:32,51:60,61 EnableTwopassCBR=true EnableStringentBitrate=true ! video/x-h264,stream-format=byte-stream ! filesink location=a.h264

And all frames are quantized at qp=51:

danel@ce-tw-daneliu:~/D/home/daneliu/temp/jm19.0$ ./JM/bin/ldecod.exe -i a.h264 Setting Default Parameters...
Parsing Configfile decoder.cfg

******************************************************
*               Decoder Parameters                   *
******************************************************
Parameter InputFile = a.h264
Parameter OutputFile = test_dec.yuv
Parameter RefFile = test_rec.yuv
Parameter WriteUV = 1
Parameter FileFormat = 0
Parameter RefOffset = 0
Parameter POCScale = 2
Parameter DisplayDecParams = 1
Parameter ConcealMode = 0
Parameter RefPOCGap = 2
Parameter POCGap = 2
Parameter Silent = 0
Parameter IntraProfileDeblocking = 1
Parameter DecFrmNum = 0
Parameter DecodeAllLayers = 0
Parameter DPBPLUS0 = 1
Parameter DPBPLUS1 = 0
******************************************************
----------------------------- JM 19.0 (FRExt) -----------------------------
 Input reference file                   : test_rec.yuv does not exist
                                          SNR values are not available
POC must = frame# or field# for SNRs to be correct
--------------------------------------------------------------------------
  Frame          POC  Pic#   QP    SnrY     SnrU     SnrV   Y:U:V Time(ms)
--------------------------------------------------------------------------
00000(IDR)        0     0    51                             4:2:0      43
00001( P )        2     1    51                             4:2:0      41
00002( P )        4     2    51                             4:2:0      40
00003( P )        6     3    51                             4:2:0      40
00004( P )        8     4    51                             4:2:0      40
00005( P )       10     5    51                             4:2:0      55
00006( P )       12     6    51                             4:2:0      53
00007( P )       14     7    51                             4:2:0      53
00008( P )       16     8    51                             4:2:0      53
00009( P )       18     9    51                             4:2:0      53
00010( P )       20    10    51                             4:2:0      53
00011( P )       22    11    51                             4:2:0      54
00000(IDR)        0     0    51                             4:2:0     109
00001( P )        2     1    51                             4:2:0      39
00002( P )        4     2    51                             4:2:0      39
00003( P )        6     3    51                             4:2:0      39
00004( P )        8     4    51                             4:2:0      39
00005( P )       10     5    51                             4:2:0      53
00006( P )       12     6    51                             4:2:0      53
00007( P )       14     7    51                             4:2:0      53
00008( P )       16     8    51                             4:2:0      53
00009( P )       18     9    51                             4:2:0      53
00010( P )       20    10    51                             4:2:0      53
00011( P )       22    11    51                             4:2:0      54
00000(IDR)        0     0    51                             4:2:0     109
00001( P )        2     1    51                             4:2:0      40
00002( P )        4     2    51                             4:2:0      39
00003( P )        6     3    51                             4:2:0      39
00004( P )        8     4    51                             4:2:0      39
00005( P )       10     5    51                             4:2:0      53
00006( P )       12     6    51                             4:2:0      53
00007( P )       14     7    51                             4:2:0      53
00008( P )       16     8    51                             4:2:0      53
00009( P )       18     9    51                             4:2:0      53
00010( P )       20    10    51                             4:2:0      53
00011( P )       22    11    51                             4:2:0      55
00000(IDR)        0     0    51                             4:2:0     109
00001( P )        2     1    51                             4:2:0      39
00002( P )        4     2    51                             4:2:0      39
00003( P )        6     3    51                             4:2:0      39
00004( P )        8     4    51                             4:2:0      39
00005( P )       10     5    51                             4:2:0      53
00006( P )       12     6    51                             4:2:0      53
00007( P )       14     7    51                             4:2:0      53
00008( P )       16     8    51                             4:2:0      53
00009( P )       18     9    51                             4:2:0      53
00010( P )       20    10    51                             4:2:0      53
00011( P )       22    11    51                             4:2:0      53
-------------------- Average SNR all frames ------------------------------
 SNR Y(dB)           :  0.00
 SNR U(dB)           :  0.00
 SNR V(dB)           :  0.00
 Total decoding time : 2.515 sec (19.085 fps)[48 frm/2515 ms]
--------------------------------------------------------------------------
 Exit JM 19 (FRExt) decoder, ver 19.0
 Output status file                     : log.dec
48 frames are decoded.

Can you give more details about this hardware limitation?
I can run a software encoder (x264) and obtain lower bitrates. Are there too many bits being put in to the residual?

https://devtalk.nvidia.com/default/topic/1042921/jetson-tx2/jeston-tx2-encoding-quality-issues/post/5290466/#5290466
Above post explains deviation between SW and HW encoders.

https://devtalk.nvidia.com/default/topic/973295/jetson-tx1/constant-bitrate-help/post/5011599/#5011599
Above post explains the compression limit.