Setting NUM_REFERENCE_FRAMES or VIRTUALBUFFER_SIZE crashes video encoder on Jetson Xavier

Hey, I’m trying to use some additional controls to tweak the video encoder output on Jetson Xavier. (H265) However, setting some parameters appears to segfault the process. Is there more documentation or more information about using V4L2_CID_MPEG_VIDEOENC_NUM_REFERENCE_FRAMES or V4L2_CID_MPEG_VIDEOENC_VIRTUALBUFFER_SIZE ?

 struct v4l2_ext_control ctrls[] = {
            // Generic controls
            { .id = V4L2_CID_MPEG_VIDEO_BITRATE, .value = bitrate },
            { .id = V4L2_CID_MPEG_VIDEO_BITRATE_PEAK, .value = bitrate * 2},
            { .id = V4L2_CID_MPEG_VIDEO_BITRATE_MODE, .value = V4L2_MPEG_VIDEO_BITRATE_MODE_VBR },
            { .id = V4L2_CID_MPEG_VIDEO_GOP_SIZE, .value = fps },

            // NVIDIA Specific controls
            { .id = V4L2_CID_MPEG_VIDEO_H265_PROFILE, .value = V4L2_MPEG_VIDEO_H265_PROFILE_MAIN },
            { .id = V4L2_CID_MPEG_VIDEOENC_NUM_BFRAMES, .value = 0 },
            { .id = V4L2_CID_MPEG_VIDEO_IDR_INTERVAL, .value = fps },
            { .id = V4L2_CID_MPEG_VIDEOENC_INSERT_SPS_PPS_AT_IDR, .value = true },

            { .id = V4L2_CID_MPEG_VIDEOENC_NUM_REFERENCE_FRAMES, .value = 4},
            // Causes segfault
            //{ .id = V4L2_CID_MPEG_VIDEOENC_VIRTUALBUFFER_SIZE, .value = 2'000'000 },
            
            // Doesn't seem to do anything
            //{ .id = V4L2_CID_MPEG_VIDEOENC_H265_LEVEL, .value =  V4L2_MPEG_VIDEO_H265_LEVEL_5_0_HIGH_TIER },

            // Works, but creates huge files
            //{ .id = V4L2_CID_MPEG_VIDEOENC_ENABLE_LOSSLESS, .value = true },
        };

        v4l2_ext_controls ctrl_data {};
        ctrl_data.ctrl_class = V4L2_CTRL_CLASS_MPEG;
        ctrl_data.count = std::size(ctrls);
        ctrl_data.controls = ctrls;

        checked_v4l2_ioctl(fd, VIDIOC_S_EXT_CTRLS, &ctrl_data);

Hi,
For video encoding, we have 01_video_encode sample. Please check if you can run the sample to reproduce the issue.

Is there a sample YUV file to use as input? I did not see one with the samples, and I am unsure of the required input format.

Never mind, I was able to create the required input format by decoding a sample video with the 00_video_decode sample. It does appear not to crash when setting those parameters in the sample.

Is there more documentation somewhere on what those two parameters control, and what ranges they should be in?

Hi,
The document is
Jetson Linux API Reference: 01_video_encode (video encode) | NVIDIA Docs

There is brief introduction to the samples. Still need to refer to the samples. Please follow the call sequence in the sample for setting the parameters.

Thanks, got it figured out from the samples. Both of those calls take pointers to objects as parameters, not the raw values like in my original code.

Is there any documentation on best practices for tuning the encoder?