Jetson multimedia API sample 01 video_encode

Hi all developers,
I’m trying to use the ROI encoding of multimedia API. I’m trying to figure out some concepts.

According to the doc of video_encode sample application, it needs to provide a file where each row is <no. of roi regions>
one of the samples is: 2 -2 34 33 16 19 -3 68 68 16 16
What does this qp delta mean? It looks like it’s a relative offset from the lowest qp 51, but I’m not very sure. Is my understanding correct?
thanks in advance!

Which Jetson platform and which JetPack SW you’re using?

I use Jetson nano, jetpack4.5

It is offset to the qp value. The algorithm will decide a qp value for each frame and the ROI will be encoded with the offset. For example, if the frame has qp value=20, the first ROI will have qp value=18(20-2) and second ROI is 17(20-3).

Thanks for your help!

I have one more question. Is it possible for me to choose the baseline qp value for each frame? And the use the qp offset value for different ROI. I found it’s only possible to choose the MaxQP and Min QP for I or P or B frames

Maybe I can control the MaxQP and Min QP to the same?

You can set min and max QP to cap the value in the range, and enable ROI. See if the setting fits requirements of the use-case.

I try to cap the Max and Min QP to the same value (26) and enable the ROI. I foudn even I give the offset (10), the ROI is not taking effect. It seems that the qp after adding offset is still limited by the MaxQP. The report metadatas shows the MaxQp within the frame is still under the MaxQP

Do you have any idea or if it’s possible that I encode parital of the frames with a fixed QP, and some ROI with an offset?
Thanks in advance

If you set min and max QP, the QP value will be in the range. Please set min and max QP to different values and have the ROI offset in the range.

Really appreciate for your help.
I try the tegra_multimedia_api/samples/01_video_encode.
I run the code as:

./video_encode 2002YUV/1600x900/000001.yuv 1600 900 H264 test.qp --eroi -roi ./qp.txt -MinQpP 26 -MaxQpP 46 -MinQpI 26 -MaxQpI 46 -MaxQpB 26 -MinQpB 46 -rc cbr --input-metadata --report-metadata

The 000001.yuv file is stacked with 30 frames with yuv format. And the roi qp.txt is as follows:
1 20 0 0 1600 900

However, I got the result:

Creating Encoder in blocking mode
NvMMLiteOpen : Block : BlockType = 4
===== NVMEDIA: NVENC =====
NvMMLiteBlockCreate : Block : BlockType = 4
NVMEDIA: NvMMAttributeVideoEnc_QPRange Get Parameter
H264: Profile = 66, Level = 51
NVMEDIA_ENC: bBlitMode is set to TRUE
EOF of ROI_param_file & rewind
Frame 0: isKeyFrame=1 AvgQP=28 MinQP=28 MaxQP=28 EncodedBits=419456
EOF of ROI_param_file & rewind
Frame 1: isKeyFrame=0 AvgQP=29 MinQP=27 MaxQP=30 EncodedBits=112072
Frame 2: isKeyFrame=0 AvgQP=29 MinQP=29 MaxQP=30 EncodedBits=86496
EOF of ROI_param_file & rewind
Frame 3: isKeyFrame=0 AvgQP=30 MinQP=30 MaxQP=30 EncodedBits=101280
Frame 4: isKeyFrame=0 AvgQP=30 MinQP=30 MaxQP=30 EncodedBits=95320
EOF of ROI_param_file & rewind
Frame 5: isKeyFrame=0 AvgQP=30 MinQP=30 MaxQP=30 EncodedBits=104904
Frame 6: isKeyFrame=0 AvgQP=29 MinQP=29 MaxQP=29 EncodedBits=106184
EOF of ROI_param_file & rewind
Frame 7: isKeyFrame=0 AvgQP=29 MinQP=29 MaxQP=29 EncodedBits=122912
Frame 8: isKeyFrame=0 AvgQP=29 MinQP=29 MaxQP=29 EncodedBits=102920
Frame 9: isKeyFrame=0 AvgQP=28 MinQP=28 MaxQP=29 EncodedBits=155688
EOF of ROI_param_file & rewind
Frame 10: isKeyFrame=0 AvgQP=28 MinQP=28 MaxQP=29 EncodedBits=131672
Frame 11: isKeyFrame=0 AvgQP=28 MinQP=28 MaxQP=29 EncodedBits=151904
Frame 12: isKeyFrame=0 AvgQP=28 MinQP=28 MaxQP=29 EncodedBits=119088
EOF of ROI_param_file & rewind
Frame 13: isKeyFrame=0 AvgQP=28 MinQP=28 MaxQP=29 EncodedBits=159968
Frame 14: isKeyFrame=0 AvgQP=28 MinQP=28 MaxQP=29 EncodedBits=129352
Frame 15: isKeyFrame=0 AvgQP=28 MinQP=28 MaxQP=29 EncodedBits=102408
EOF of ROI_param_file & rewind
Frame 16: isKeyFrame=0 AvgQP=28 MinQP=28 MaxQP=29 EncodedBits=140752
Frame 17: isKeyFrame=0 AvgQP=27 MinQP=27 MaxQP=29 EncodedBits=145336
EOF of ROI_param_file & rewind
Frame 18: isKeyFrame=0 AvgQP=27 MinQP=27 MaxQP=28 EncodedBits=163024
Frame 19: isKeyFrame=0 AvgQP=27 MinQP=27 MaxQP=28 EncodedBits=139472
EOF of ROI_param_file & rewind
Could not read complete frame from input file
Frame 20: isKeyFrame=0 AvgQP=28 MinQP=28 MaxQP=28 EncodedBits=139632
File read complete.
Frame 21: isKeyFrame=0 AvgQP=27 MinQP=27 MaxQP=28 EncodedBits=138152
Frame 22: isKeyFrame=0 AvgQP=28 MinQP=28 MaxQP=28 EncodedBits=150776
Frame 23: isKeyFrame=0 AvgQP=27 MinQP=27 MaxQP=28 EncodedBits=148224
Frame 24: isKeyFrame=0 AvgQP=28 MinQP=28 MaxQP=28 EncodedBits=147120
Frame 25: isKeyFrame=0 AvgQP=28 MinQP=28 MaxQP=28 EncodedBits=111976
Frame 26: isKeyFrame=0 AvgQP=28 MinQP=28 MaxQP=28 EncodedBits=165976
Frame 27: isKeyFrame=0 AvgQP=28 MinQP=28 MaxQP=28 EncodedBits=128504
Frame 28: isKeyFrame=0 AvgQP=28 MinQP=28 MaxQP=28 EncodedBits=127064
Frame 29: isKeyFrame=0 AvgQP=28 MinQP=28 MaxQP=28 EncodedBits=121480
Got 0 size buffer in capture

It seems that the ROI encoding doesn’t take effect. Do you have any advice on how to solve it? I also found some related solution in the forum which suggests to make the ROI region slightly smaller than the raw frame. I tried. But it still occurs this problem.

But I check the compressed video file, it does have some effect but according to the log, it seems not working properly. I’m confused about this report-metadata. What is the meaning of these showing results?

You would need to use a tool to parse QP value of each macroblock in the frame. The printed value is the QP value of whole frame. It doesn’t print out the specific ROI.

Please refer to the post about how ROI works:
How to use setROIParams function on Jetson to set dynamic RoI encoding? - #11 by DaneLLL

And I don’t understand what you mean by “the value is the qp of the whole frame”. Does it mean the showed qp is the areas except the ROI areas? It’s quite confusing for me.

Thanks for your help.


Yes, it is QP value of all macroblocks except ROI areas. There are certain tools for showing information of each macroblock in one frame. Would suggest use the tool for analysis.

1 Like

I analyze the qp and only when the ROI area is slightly smaller than the whole image, it can work.

And I also test to encode 1/4 of the image with qp 46 and rest of the image with qp 26. Compared with the whole image encoded with qp 26. The former has larger encoded bitstream. It looks so strange, do you also observe this problem?

For the same video, I encode 1/4 of all frames with qp 46, rest of it is qp 26
here qp is 26, and in the roi file I make a largest offset to assure the right bottom 1/4 of the video’s qp is 46, and rest of it are 26.

./video_encode "$FILE" "$width" "$height" H264 "$DES_DIR/$rs/$qp/$filename.h264" -br 4000000 --eroi -roi "1713/${width}_${qp}.txt" -MinQpP $qp -MaxQpP 46 -MinQpI $qp -MaxQpI 46 -MinQpB $qp -MaxQpB 46 -rc cbr --report-metadata --input-metadata -vbs 450000 -ifi 15

Then, I encode the same video with a uniform qp:

here $qp is 26

./video_encode "$FILE" "$width" "$height" H264 "$DES_DIR/$rs/$qp/$filename.h264" -br 4000000 -ifi 15 -fps 30 1 -vbs 450000 -MinQpP $qp -MaxQpP $qp -MinQpI $qp -MaxQpI $qp -MinQpB $qp -MaxQpB $qp -rc cbr --report-metadata --input-metadata

But the result shows, the first one is 1.1M and the second is 934K.

Do I make anything wrong? I also check the forum and found someone also face this problem.


Do you check qp value of each macroblock and see if it is expected? It looks like the qp value may not be expected. Probably it does not work properly if you set offset to a large value.

It works. I check the QP value of each frame. I use streamEye to check the qp value
The first is I frame, the second is p frame, only the right bottom 1/4 's qp is 46.

The following is assign uniform qp for the whole frame:

I’m confused