Error when resize by using NvBufferTransform()

Hi,
I am testing a small application on Jetson Nano (Jetpack 4.6.6) and Jetson Xavier (Jetpack 5.1.4). In some cases where the Input IP camera (RTPS) Resolution is set to 2688*1520, I get an error after decoding and sending the packet to NvBufferTransform() (ie. error: Failed to generate thumbnail). But in the case where the camera Resolution is set to 1920*1080, it does not get an error and works fine.

Below is some code that I implemented:

int _fd;
void *_bufY;
void *_bufCbCr;
NvBufferParams _bufParam;
struct Buffer
{
	struct v4l2_buffer buf;
	struct v4l2_plane planes[MAX_NUM_PLANES];

	size_t length[MAX_NUM_PLANES];
	void* data[MAX_NUM_PLANES];

	int fd[MAX_NUM_PLANES];
};

...
...
(some init() ...)
...
...

void resize(Buffer* buffer)
{
	assert(buffer->fd[0] >= 0); 
	int srcfd = buffer->fd[0];

	NvBufferParams inparam;
	if (NvBufferGetParams(srcfd, &inparam) != 0)
		throw exception(literal("Failed to get input parameter"));

	NvBufferTransformParams transformParam = {};
	transformParam.src_rect.width = inparam.width[0];
	transformParam.src_rect.height = inparam.height[0];

	transformParam.dst_rect.width = _bufParam.width[0];
	transformParam.dst_rect.height = _bufParam.height[0];

	transformParam.transform_flip = NvBufferTransform_None;
	transformParam.transform_filter = NvBufferTransform_Filter_Nearest;
	transformParam.transform_flag = NVBUFFER_TRANSFORM_FILTER;

	if (NvBufferTransform(srcfd, _fd, &transformParam) != 0)
		throw exception(literal("Failed to generate thumbnail"));

	NvBufferMemSyncForCpu(_fd, 0, &_bufY);
	NvBufferMemSyncForCpu(_fd, 1, &_bufCbCr);

	return;
}

Is there any limit here on width*height of inparam when given to NvBufferTransform()? Can you give me any comment or advice to solve this error?

Thanks so much!

Hi,
We would need to reproduce the error and check. Please save h264/h265 stream from the IP camera and see if it can be decoded successfully through 00_video_decode sample. If you can run 00_video_decode sample to replicate the issue, please share us the h264/h265 stream and the command. We will set up developer kit and check.

Hi,
Issue related to NvBufferTransform() (not Decoder), in 00_video_decode sample there is no place using NvBufferTransform().
In your experience/Nvidia doc is there any limit to width*height of inparam?

Thanks so much!

Hi,
I found this topic, maybe it will be relevant

Thanks!

Hi,
I tried with Resolution 2560x1440, it seems 2560 is divisible by 256, but the issue still occurs, is there any limitation here or do you have any recommendation for setting to solve the problem that input Resolution (ie. width*height) higher than 1920x1080 will not work with NvBufferTransform()?

Thanks!

Hi,
Here are patches of using NvBuffer APIs:
How to scale video using NvBufferTransform function? - #4 by DaneLLL
How to crop frame use VIC? - #8 by DaneLLL

Please take a look. If you still cannot find out any clue, please share a patch to 00_video_decode sample. So that we can set up and check.

Hi,
I found the reason for NvBufferTransform(), please refer to the code below, when set setOutputSize(128x72) then when Resolution Input (ie Input width*height) is greater than 1920x1080 then it will error.

int _fd;
NvBufferParams _bufParam;
void *_bufY;
void *_bufCbCr;

void setOutputSize(uint width, uint height)
{
	NvBufferCreateParams cparm = {};
	cparm.width = width;
	cparm.height = height;
	cparm.layout = NvBufferLayout_Pitch;
	cparm.colorFormat = NvBufferColorFormat_NV12;
	cparm.nvbuf_tag = NvBufferTag_VIDEO_CONVERT;

	if (NvBufferCreateEx(&_fd, &cparm) != 0 ||
	    NvBufferMemMap(_fd, 0, NvBufferMem_Read, &_bufY) != 0 ||
	    NvBufferMemMap(_fd, 1, NvBufferMem_Read, &_bufCbCr) != 0 ||
	    NvBufferGetParams(_fd, &_bufParam) != 0)
		throw exception(literal("Failed to initialize for new size"));
}

So I tried increasing setOutputSize(256, 144) then the issue is resolved.
Can you explain to me why, Is there any limit on the distance between 128x72 (Output Resolution) and greater than 1920x1080 (Input Resolution) Or minimum of Output Resolution?

Thanks!

Hi,
You are right. This is constraint of hardware engine. Please check the posts:
nvvidconv video cropping fails - #2 by DaneLLL
Issue with NvBufSurfTransform - #2 by miguel.taylor

You may combine to use hardware converter and software converter to avoid hitting the constraint.

1 Like

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