Encode H264 by slice

Is it possible to encode h264 by slice with NvVideoEncoder? It has methods to set the slice length and slice intra-refresh, and while those methods report success, the NALs the encoder generates don’t respect any slice length limit.

Hi,
We support slice length in macroblocks and bytes:

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

Do you run your case in macroblocks or bytes?

Hi DaneLLL, I’ve tried with both, and in neither case does the NAL length change. I’m using libargus, calling setSliceLength in NvVideoEncoder, so I’d expect the v4l2_buffer in the encoder callback to be smaller than the slice size I set, but that’s not the case. I’ve tried a variety of slice sizes, and I’m setting it after the format is set, per the comments in the NvVideoEncoder header.

Hi,
Please refer to
https://devtalk.nvidia.com/default/topic/1035839/jetson-tx2/how-does-slice-mode-video-encoding-work-for-jetson-/post/5267080/#5267080

The frame can be encoded into multiple slices, but it is sent out in a complete frame.

Hi @DaneLLL, based on your answer, I was expecting to find multiple NALs corresponding to individual slices in the encoder buffer in the dequeue thread, but that’s not the case. My goal is to slice the encoder output so that it is more resilient in the face of packet loss, and the way to do that is to make each slice smaller than the MTU of my radio. Is this impossible in Argus?

Encoding by slice doesn’t seem particularly useful if the resulting slices are all piled into a single NAL.

Thanks!

Hi,
Please refer to following commands:

01_video_encode$ gst-launch-1.0 nvcamerasrc num-buffers=10 ! nvvidconv ! video/x-raw,width=640,height=480 ! filesink location= a.yuv
01_video_encode$ ./video_encode a.yuv 640 480 H264 a.h264 -slt 1 -slen 300

And JM decoder output(partial):

Annex B NALU w/ long startcode, len 1452, forbidden_bit 0, nal_reference_idc 3, nal_unit_type 1

@454   SH: first_mb_in_slice                                         1 (  0) 
@455   SH: slice_type                                                1 (  0) 
@456   SH: pic_parameter_set_id                                      1 (  0) 
@457   SH: frame_num                                          00000010 (  2) 
@465   SH: pic_order_cnt_lsb                                  00000100 (  4) 
@473   SH: num_ref_idx_override_flag                                 0 (  0) 
@474   SH: ref_pic_list_reordering_flag_l0                           0 (  0) 
@475   SH: adaptive_ref_pic_buffering_flag                           0 (  0) 
@476   SH: slice_qp_delta                                        00111 ( -3) 
@481   SH: disable_deblocking_filter_idc                             1 (  0) 
@482   SH: slice_alpha_c0_offset_div2                                1 (  0) 
@483   SH: slice_beta_offset_div2                                    1 (  0) 

decode_one_slice POC: 2 Type 0

decode_one_slice POC: 2 Type 0

decode_one_slice POC: 2 Type 0

decode_one_slice POC: 2 Type 0


Annex B NALU w/ short startcode, len 1734, forbidden_bit 0, nal_reference_idc 3, nal_unit_type 1

@484   SH: first_mb_in_slice                           00000000100101101 (300) 
@501   SH: slice_type                                                1 (  0) 
@502   SH: pic_parameter_set_id                                      1 (  0) 
@503   SH: frame_num                                          00000010 (  2) 
@511   SH: pic_order_cnt_lsb                                  00000100 (  4) 
@519   SH: num_ref_idx_override_flag                                 0 (  0) 
@520   SH: ref_pic_list_reordering_flag_l0                           0 (  0) 
@521   SH: adaptive_ref_pic_buffering_flag                           0 (  0) 
@522   SH: slice_qp_delta                                      0001101 ( -6) 
@529   SH: disable_deblocking_filter_idc                             1 (  0) 
@530   SH: slice_alpha_c0_offset_div2                                1 (  0) 
@531   SH: slice_beta_offset_div2                                    1 (  0) 


Annex B NALU w/ short startcode, len 1930, forbidden_bit 0, nal_reference_idc 3, nal_unit_type 1

@532   SH: first_mb_in_slice                           0000000001001011001 (600) 
@551   SH: slice_type                                                1 (  0) 
@552   SH: pic_parameter_set_id                                      1 (  0) 
@553   SH: frame_num                                          00000010 (  2) 
@561   SH: pic_order_cnt_lsb                                  00000100 (  4) 
@569   SH: num_ref_idx_override_flag                                 0 (  0) 
@570   SH: ref_pic_list_reordering_flag_l0                           0 (  0) 
@571   SH: adaptive_ref_pic_buffering_flag                           0 (  0) 
@572   SH: slice_qp_delta                                        00111 ( -3) 
@577   SH: disable_deblocking_filter_idc                             1 (  0) 
@578   SH: slice_alpha_c0_offset_div2                                1 (  0) 
@579   SH: slice_beta_offset_div2                                    1 (  0) 


Annex B NALU w/ short startcode, len 2732, forbidden_bit 0, nal_reference_idc 3, nal_unit_type 1

@580   SH: first_mb_in_slice                           0000000001110000101 (900) 
@599   SH: slice_type                                                1 (  0) 
@600   SH: pic_parameter_set_id                                      1 (  0) 
@601   SH: frame_num                                          00000010 (  2) 
@609   SH: pic_order_cnt_lsb                                  00000100 (  4) 
@617   SH: num_ref_idx_override_flag                                 0 (  0) 
@618   SH: ref_pic_list_reordering_flag_l0                           0 (  0) 
@619   SH: adaptive_ref_pic_buffering_flag                           0 (  0) 
@620   SH: slice_qp_delta                                      0001001 ( -4) 
@627   SH: disable_deblocking_filter_idc                             1 (  0) 
@628   SH: slice_alpha_c0_offset_div2                                1 (  0) 
@629   SH: slice_beta_offset_div2                                    1 (  0)

Each NAL contains 300 macroblocks.

Thanks! I was looking for long NAL start codes (00 00 00 01), but only the first slice starts with the long start code–subsequent slices start with 00 00 01.