Multiple slices on Jetson NX Jetpack 4.6

Hello,
I’m trying to encode multiple slices on frames (H265), using:

hevcConfig.sliceMode = 3;          // modes slice = 3
hevcConfig.sliceModeData = 3; // number of slices per frame

Running on Jetson Xavier NX, with Jetpack 4.6, I’m getting a single slice.
Are multiple slices supported in Jetpack 4.6?

Thanks for your help,
Adi

Hi,
We have jetson_multiemdia_api sample to demonstrate hardware encoding. Please try this sample:

/usr/src/jetson_multimedia_api/samples/01_video_encode/

For slice level encoding, please configure the options:

        -slt <type>           Slice length type (1 = Number of MBs, 2 = Bytes) [Default = 1]
        -slen <length>        Slice length [Default = 0]
        --sle                 Slice level encode output [Default = disabled]

Thank you,
I tried that and I’m getting the same result with slices enabled/disabled.
I ran the following:

  • Creating a yuv file:
 gst-launch-1.0 videotestsrc ! video/x-raw,format=I420,width=1920,height=1080 ! filesink location=~/work/adi/filetst.yuv
  • Encoding with no slices:
    under /usr/src/jetson_multimedia_api/samples/01_video_encode:
    ./video_encode ~/work/adi/filetst.yuv 1920 1080 H265 ~/work/adi/filetst.h265

  • Encoding with slices:
    under /usr/src/jetson_multimedia_api/samples/01_video_encode:
    ./video_encode ~/work/adi/filetst.yuv 1920 1080 H265 ~/work/adi/filetst-s3.h265 --sle -slen 1036800 -slt 2

  • Diff result files → no difference:

$ diff ~/work/adi/filetst-s3.h265 ~/work/adi/filetst.h265 
$ echo $?
0

Hi,
Please try smaller slice length such as -slen 1000. Default bitrate is 4Mbps and 1036800 may be too large.

Thank you!
I can see the slices now.
Is there a way to determine the number of slices per frame?

I wanted to test 3 slices per frame, resolution 1920*1080, YUV420, I got frame size of 3110400, divided by 3 to get slice size 1036800.

Now running with -slen 1000 I saw about 20 slices per frame. I ran again with -slen 5000 and saw about 4 slices per frame.

How do I calculate the desired slice length?

Thank you for your help,
Adi

Hi,
Please refer to this comment:
How does slice mode video encoding work for Jetson? - #14 by DaneLLL

You can set to -slt 1 and set macro blocks for each slice.

Thanks again,
I followed the instructions there and it works well when encoding H264 (getting 4 slices):
./video_encode ~/work/adi/filetst.yuv 1920 1080 H264 ~/work/adi/filetst-4s.264 --sle -slen 2040 -slt 1

But I don’t get 4 slices when encoding H265 / VP9
(Tried on Jetpack 4.6 on AGX, 5.1 on NX, and 5.0.1 on Orin)

Is it calculated differently there?

@DaneLLL
Can you please help with number of slices for H265 and VP9?

Thank you,
Adi

Hi,
We are checking this with our teams. Will update once there is further detail about it.

Many thanks,
I think we figured the calculation for H265:
macroblock_alignment =32
macroblock_size = 32*32 = 1024
macroblocks = WIDTH_ALIGN_TO_32*HEIGHT_ALIGN_TO_32/macroblock_size
macroblocks_per_slice = macroblocks / slices

We still need the calculation for VP9.

When analyzing the slices, we are looking for headers on every IDR.
I tried using --insert-spspps-idr option, but we still get only one header.
How can we get the headers on every IDR?

Thanks again,
Adi

Hi,
Have checked with our teams and confirmed your understanding to h265 is correct. And slice encoding is not supported in VP9.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.