How to scale video using NvBufferTransform function?

How to scale video using NvBufferTransform function?
The comment in nvbuf_utils is as follows:
/**

  • Transforms one DMA buffer to another DMA buffer.
  • This function can support transforms for copying, scaling, fliping, rotating, and cropping.
  • @param[in] src_dmabuf_fd DMABUF FD of source buffer
  • @param[in] dst_dmabuf_fd DMABUF FD of destination buffer
  • @param[in] transform_params transform parameters
  • @return 0 for sucess, -1 for failure.
    */
    int NvBufferTransform (int src_dmabuf_fd, int dst_dmabuf_fd, NvBufferTransformParams *transform_params);

But i don’t know how to scale video using this fuction.
For example,the input video is 1280x720,the output is 1920x1080.
But the pitch output is 1280 not 2048.

Anybody who know this can tell me?
Thank you very much!

I use EGLImage to get the pitch,
My code is as follows:

		NvBufferRect src_rect;
		src_rect.top = 0;
		src_rect.left = 0;
		src_rect.width = ctx->display_width;
		src_rect.height = ctx->display_height;
		
		NvBufferRect dst_rect;
		dst_rect.top = 0;
		dst_rect.left = 0;
		dst_rect.width = pthis->m_video_para.width;
		dst_rect.height = pthis->m_video_para.height;
					printf("~~~~~~~~~~~~~~ctx->display_width %d,ctx->display_height %d\n",ctx->display_width,ctx->display_height);

		printf("~~~~~~~~~~~~~~m_video_para.width %d,m_video_para.height %d\n",pthis->m_video_para.width,pthis->m_video_para.height);

		NvBufferTransformParams transform_params;
		/* Indicates which of the transform parameters are valid */
		transform_params.transform_flag = NVBUFFER_TRANSFORM_FILTER;
		transform_params.transform_flip = NvBufferTransform_None;
		transform_params.transform_filter = NvBufferTransform_Filter_Smart;
		transform_params.src_rect = src_rect;
		transform_params.dst_rect = dst_rect;

		// Convert Blocklinear to PitchLinear
	ret = NvBufferTransform(dec_buffer->planes[0].fd, ctx->dst_dma_fd, &transform_params);

I want to scale it and get the correct pitch using cuGraphicsResourceGetMappedEglFrame as follows:
CUresult status;
CUeglFrame eglFrame;
CUgraphicsResource pResource = NULL;
cudaFree(0);
status = cuGraphicsEGLRegisterImage(&pResource, ctx->egl_image, CU_GRAPHICS_MAP_RESOURCE_FLAGS_NONE);
if (status != CUDA_SUCCESS)
{
printf(“cuGraphicsEGLRegisterImage failed : %d \n”, status);
return -1;
}
status = cuGraphicsResourceGetMappedEglFrame(&eglFrame, pResource, 0, 0);
if (status != CUDA_SUCCESS)
{
printf(“cuGraphicsSubResourceGetMappedArray failed\n”);
}

status = cuCtxSynchronize();
if (status != CUDA_SUCCESS)
{
	printf("cuCtxSynchronize failed \n");
}

printf(“~~~~~~~~~~~~~~pitch %d\n”,eglFrame.pitch);
But the pitch i get is 1280,not the value after scaling,i donot konw why.

Hi,
Please apply below patch to 00_video_decode

@@ -554,8 +554,8 @@ query_and_set_capture(context_t * ctx)
     }
 
     input_params.payloadType = NvBufferPayload_SurfArray;
-    input_params.width = crop.c.width;
-    input_params.height = crop.c.height;
+    input_params.width = 1920;
+    input_params.height = 1080;
     input_params.layout = NvBufferLayout_Pitch;
     input_params.colorFormat = ctx->out_pixfmt == 1 ? NvBufferColorFormat_NV12 : NvBufferColorFormat_YUV420;
     input_params.nvbuf_tag = NvBufferTag_VIDEO_DEC;
@@ -1019,8 +1019,8 @@ dec_capture_loop_fcn(void *arg)
                 src_rect.height = ctx->display_height;
                 dest_rect.top = 0;
                 dest_rect.left = 0;
-                dest_rect.width = ctx->display_width;
-                dest_rect.height = ctx->display_height;
+                dest_rect.width = 1920;
+                dest_rect.height = 1080;
 
                 NvBufferTransformParams transform_params;
                 memset(&transform_params,0,sizeof(transform_params));
@@ -1040,6 +1040,11 @@ dec_capture_loop_fcn(void *arg)
                     cerr << "Transform failed" << endl;
                     break;
                 }
+                {
+                    NvBufferParams par;
+                    NvBufferGetParams (ctx->dst_dma_fd, &par);
+                    cout << "dst pitch = " << par.pitch[0] << endl;
+                }
 
                 // Write raw video frame to file
                 if (!ctx->stats && ctx->out_file)

and run

$ ./video_decode H264 -ww 1920 -wh 1080 /home/nvidia/videoplayback1_track1.h264

4

That’s works for me.
Thank U!