No encoder perfomance improvement before/after jetson_clocks.sh

 I try to see the low latency encoding capabilities of a full performance jetson tx2.

 I use follow script to do h.264 encoding with latency log:

gst-launch-1.0 nvcamerasrc fpsRange=30,30 ! ‘video/x-raw(memory:NVMM),width=1280, height=720, framerate=30/1, format=NV12’ ! omxh264enc MeasureEncoderLatency=true ! fakesink

 Then do jestion_clocks.sh. From ./jetson_clocks.sh --show, I do see the working frequency goes to peak value:
         Before: GPU MinFreq=140250000 MaxFreq=1122000000 CurrentFreq=140250000

         After:  GPU MinFreq=1122000000 MaxFreq=1122000000 CurrentFreq=1122000000

 But the encoder latency logged is not changing. Before and after jetson_clocks.sh it always show   something around 9ms 

        KPI: omx: frameNumber= 13147 encoder= 9 ms pts= 438590033292

        KPI: omx: frameNumber= 13148 encoder= 9 ms pts= 438623375206

        KPI: omx: frameNumber= 13149 encoder= 9 ms pts= 438656716128


 I had experience on overclocking raspberry pi and can make encoder perform differently before/after overclocking.

Hi pin,
jetson_clocks.sh does not configure HW encoding engine MSENC to max clocks.

What is our usecase? 4Kp30 h264 encoding?

Not very big size, 1920x1080. But I try to minimize the latency of encoder.

Beside I happen to find out the latency of H.264 and H.265 will ramp up from 3ms to a stable 20ms:

  KPI: omx: frameNumber= 1 encoder= 3 ms pts= 270194832

  ................

  KPI: omx: frameNumber= 1114 encoder= 19 ms pts= 37367505415

  KPI: omx: frameNumber= 1115 encoder= 20 ms pts= 37400801940

The VP9 is rather stable at 3 ms

 KPI: omx: frameNumber= 1249 encoder= 3 ms pts= 41868951467

 KPI: omx: frameNumber= 1250 encoder= 3 ms pts= 41902295194

 KPI: omx: frameNumber= 1251 encoder= 3 ms pts= 41935634602

The encoders are all with same parameter sets control-rate=2 bitrate=4000000 MeasureEncoderLatency=true

Hi pin,
It is expected the result is different with different codecs. If vp9 is good for your case, you can run vp9 encoding.

Hi pin,
It enables DFS(dynamic frequency scaling) in h264/h265 encoding by default.

You can rebuild libgstomx.so with below patch to disable DFS:

diff --git a/omx/gstomxh264enc.c b/omx/gstomxh264enc.c
index 81359bb..a0589fd 100644
--- a/omx/gstomxh264enc.c
+++ b/omx/gstomxh264enc.c
@@ -212,7 +212,7 @@ gst_omx_h264_enc_set_params (GstOMXVideoEnc * enc)
   NVX_PARAM_VIDENCPROPERTY oEncodeProp;
   GstOMXH264Enc *self = GST_OMX_H264_ENC (enc);
 
-  if (self->insert_sps_pps) {
+  if (TRUE) {
     GST_OMX_INIT_STRUCT (&oEncodeProp);
     oEncodeProp.nPortIndex = enc->enc_out_port->index;
 
@@ -227,6 +227,7 @@ gst_omx_h264_enc_set_params (GstOMXVideoEnc * enc)
         oEncodeProp.bInsertSPSPPSAtIDR = self->insert_sps_pps;
         oEncodeProp.bInsertAUD = self->insert_aud;
         oEncodeProp.bInsertVUI = self->insert_vui;
+        oEncodeProp.bSetMaxEncClock = TRUE;
 
         eError =
             gst_omx_component_set_parameter (GST_OMX_VIDEO_ENC (self)->enc,
@@ -392,9 +393,7 @@ gst_omx_h264_enc_set_format (GstOMXVideoEnc * enc, GstOMXPort * port,
   }
 
 
-  if (self->insert_sps_pps ||
-      self->insert_aud ||
-      self->insert_vui) {
+  if (TRUE) {
     err = gst_omx_h264_enc_set_params (enc);
     if (err != OMX_ErrorNone) {
       GST_WARNING_OBJECT (self,

Hi, DaneLLL

I tried to follow what you said in the post: https://devtalk.nvidia.com/default/topic/1023695/how-to-compile-gstomx-for-tx2-/

First download from https://developer.nvidia.com/embedded/downloads, I found several version exists, I pick 24.1,
L4T Libgstomx for gstreamer 1-0 sources 24.1
L4T GstEGL sources 24.1

First I do compilation for GstEGL, everything is fine
./configure --libdir=/usr/lib/aarch64-linux-gnu/
make & make install

When I tried to compile libgstomx, I got

make all-recursive
make[1]: Entering directory ‘/home/nvidia/repos/gstomx1_src/gst-omx1’
Making all in common
make[2]: Entering directory ‘/home/nvidia/repos/gstomx1_src/gst-omx1/common’
Making all in m4
make[3]: Entering directory ‘/home/nvidia/repos/gstomx1_src/gst-omx1/common/m4’
make[3]: Nothing to be done for ‘all’.
make[3]: Leaving directory ‘/home/nvidia/repos/gstomx1_src/gst-omx1/common/m4’
make[3]: Entering directory ‘/home/nvidia/repos/gstomx1_src/gst-omx1/common’
make[3]: Nothing to be done for ‘all-am’.
make[3]: Leaving directory ‘/home/nvidia/repos/gstomx1_src/gst-omx1/common’
make[2]: Leaving directory ‘/home/nvidia/repos/gstomx1_src/gst-omx1/common’
Making all in omx
make[2]: Entering directory ‘/home/nvidia/repos/gstomx1_src/gst-omx1/omx’
CC libgstomx_la-gstomx_config.lo
CC libgstomx_la-gstomx.lo
CC libgstomx_la-gstomxvideodec.lo
CC libgstomx_la-gstomxvideoenc.lo
CC libgstomx_la-gstomxaudioenc.lo
gstomxvideodec.c:31:30: fatal error: gstnvivameta_api.h: No such file or directory
compilation terminated.
Makefile:699: recipe for target ‘libgstomx_la-gstomxvideodec.lo’ failed
make[2]: *** [libgstomx_la-gstomxvideodec.lo] Error 1
make[2]: *** Waiting for unfinished jobs…
gstomxvideoenc.c:31:30: fatal error: gstnvivameta_api.h: No such file or directory
compilation terminated.
Makefile:706: recipe for target ‘libgstomx_la-gstomxvideoenc.lo’ failed
make[2]: *** [libgstomx_la-gstomxvideoenc.lo] Error 1
make[2]: Leaving directory ‘/home/nvidia/repos/gstomx1_src/gst-omx1/omx’
Makefile:526: recipe for target ‘all-recursive’ failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory ‘/home/nvidia/repos/gstomx1_src/gst-omx1’
Makefile:458: recipe for target ‘all’ failed
make: *** [all] Error 2

Hi pin, please check your BSP revision and download corresponding package.

head -1 /etc/nv_tegra_release

Thanks DaneLLL. I found respective GstEGL and Libgstomx from L4T TX2 Sources 28.2

I got it patched and H264 encoding is also stable at 2-3ms for 1080P now.

Can you also show how to patch H265 branch?

Hi pin, you can apply the same to gstomxh265enc.c

I add bSetMaxEncClock = TRUE as follow :

static OMX_ERRORTYPE gst_omx_h265_enc_set_params (GstOMXVideoEnc * enc)
{
  OMX_INDEXTYPE eIndex;
  OMX_ERRORTYPE eError = OMX_ErrorNone;
  NVX_PARAM_VIDENCPROPERTY oEncodeProp;
  GstOMXH265Enc *self = GST_OMX_H265_ENC (enc);

  GST_OMX_INIT_STRUCT (&oEncodeProp);
  oEncodeProp.nPortIndex = enc->enc_out_port->index;

  eError = gst_omx_component_get_index (GST_OMX_VIDEO_ENC (self)->enc,
          (gpointer) NVX_INDEX_PARAM_VIDEO_ENCODE_PROPERTY, &eIndex);

  if (eError == OMX_ErrorNone) {
      eError =
          gst_omx_component_get_parameter (GST_OMX_VIDEO_ENC (self)->enc,
                  eIndex, &oEncodeProp);
      if (eError == OMX_ErrorNone) {
          oEncodeProp.bInsertSPSPPSAtIDR = self->insert_sps_pps;
          oEncodeProp.codecParams.hevc.nSliceHeaderSpacing = self->slice_header_spacing;
          oEncodeProp.bInsertAUD = self->insert_aud;
          oEncodeProp.bInsertVUI = self->insert_vui;

          eError =
              gst_omx_component_set_parameter (GST_OMX_VIDEO_ENC (self)->enc,
                      eIndex, &oEncodeProp);
      }
  }

  oEncodeProp.bSetMaxEncClock = TRUE;

But I found the latency is still long:

KPI: omx: frameNumber= 1380 encoder= 27 ms pts= 46265409936
KPI: omx: frameNumber= 1381 encoder= 24 ms pts= 46298817846
KPI: omx: frameNumber= 1382 encoder= 24 ms pts= 46332068882
KPI: omx: frameNumber= 1383 encoder= 24 ms pts= 46365909875
KPI: omx: frameNumber= 1384 encoder= 24 ms pts= 46398995845
KPI: omx: frameNumber= 1385 encoder= 24 ms pts= 46432830854
KPI: omx: frameNumber= 1386 encoder= 24 ms pts= 46465913688
KPI: omx: frameNumber= 1387 encoder= 23 ms pts= 46499556332

Hi Pin,
You should set it before set parameter:

if (eError == OMX_ErrorNone) {
          oEncodeProp.bInsertSPSPPSAtIDR = self->insert_sps_pps;
          oEncodeProp.codecParams.hevc.nSliceHeaderSpacing = self->slice_header_spacing;
          oEncodeProp.bInsertAUD = self->insert_aud;
          oEncodeProp.bInsertVUI = self->insert_vui;
<b>oEncodeProp.bSetMaxEncClock = TRUE;</b>

          eError =
              gst_omx_component_set_parameter (GST_OMX_VIDEO_ENC (self)->enc,
                      eIndex, &oEncodeProp);
      }