Questions on NVIDIA Jetson Xavier NX decoded video output format

您好!
我阅读了NAVIDIA的官网
https://docs.nvidia.com/jetson/l4t-multimedia/l4t_mm_00_video_decode.html。
上面提到 :
The Capture Plane transfer decoded frames to the application in YUV format.

疑问: NVIDIA Jetson Xavier NX把H264的视频解码后只能输出YUV格式的视频数据吗?是否可以直接解码输出RGB格式的视频数据???

Hi,
No, it cannot output RGB/RGBA directly. We have hardware VIC engine for converting YUV420 to RGBA. And you can call NvBufferTransform() to do the conversion. 24-bit RGB is not supported. Please convert to 32-bit RGBA(or BGRx).

您好!
我按照你的建议,运行如下的命令:
export DISPLAY=:1
./video_decode H264 /home/working-video/working-video-dec/700818_023723.h264

可以成功实现了把H264文件解码显示出图像出来了。

但是NVIDIA的这个测试例子中,好像没有统计硬件解码一帧所耗费的时间是多少毫秒的。但是我们用过瑞芯微公司的GPU芯片,瑞芯微公司的GPU芯片给出的视频测试例子,是有统计硬件解码一帧所耗费的时间的。

请问:这个例子
./video_decode H264 /home/working-video/working-video-dec/700818_023723.h264是否可以显示硬件解码一帧统计所耗费的时间???

Hi,
You can set the options –stats --disable-rendering like:

00_video_decode$ ./video_decode H264 --disable-rendering --stats …/…/data/Video/sample_outdoor_car_1080p_10fps.h264

您好!
我想在NVIDIA Jetson Xavier NX硬件平台上,使用NvBufferTransform()函数,把H264视频解码后的YUV420视频数据转换为BGRA格式的数据,但是我查看了NvBufferTransform()函数的参数,找不到应该在NvBufferTransformParams结构体的哪个字段中设置转换后输出的视频格式为BGRA的。

下面的是你们提供的jetson_multimedia_api/samples/00_video_decode/video_decode_main.cpp中的源代码例子:
static void *
dec_capture_loop_fcn(void *arg)
{

NvBufferRect src_rect, dest_rect;
src_rect.top = 0;
src_rect.left = 0;
src_rect.width = ctx->display_width;
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;

            NvBufferTransformParams transform_params;
            memset(&transform_params,0,sizeof(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_Nearest;
            transform_params.src_rect = src_rect;
            transform_params.dst_rect = dest_rect;

            if(ctx->capture_plane_mem_type == V4L2_MEMORY_DMABUF)
                dec_buffer->planes[0].fd = ctx->dmabuff_fd[v4l2_buf.index];
            /* Perform Blocklinear to PitchLinear conversion. */
            ret = NvBufferTransform(dec_buffer->planes[0].fd, ctx->dst_dma_fd, &transform_params);
 .......................................................

}

请问:应该在NvBufferTransformParams结构体的哪个字段中设置转换后输出的视频格式为BGRA的???

Hi,
ctx->dst_dma_fd is created in

    /* Create PitchLinear output buffer for transform. */
    input_params.payloadType = NvBufferPayload_SurfArray;
    input_params.width = crop.c.width;
    input_params.height = crop.c.height;
    input_params.layout = NvBufferLayout_Pitch;
    if (ctx->out_pixfmt == 1)
      input_params.colorFormat = NvBufferColorFormat_NV12;
    else if (ctx->out_pixfmt == 2)
      input_params.colorFormat = NvBufferColorFormat_YUV420;
    else if (ctx->out_pixfmt == 3)
      input_params.colorFormat = NvBufferColorFormat_NV16;
    else if (ctx->out_pixfmt == 4)
      input_params.colorFormat = NvBufferColorFormat_NV24;

    input_params.nvbuf_tag = NvBufferTag_VIDEO_CONVERT;

    ret = NvBufferCreateWithChromaLoc (&ctx->dst_dma_fd, &input_params, &outChromaSubsampling);

Please change colorFormat to RGBA and then call NvBufferCreateEx() to create RGBA NvBuffer.

您好:
非常感谢您的及时回复。

有个问题:我查看了源代码:jetson_multimedia_api/nvbuf_utils.h的
typedef enum
{

/** Non-linear RGB BT.709 colorspace - RGBA-10-10-10-2 planar. /
NvBufferColorFormat_RGBA_10_10_10_2_709,
/
* Non-linear RGB BT.2020 colorspace - RGBA-10-10-10-2 planar. /
NvBufferColorFormat_RGBA_10_10_10_2_2020,
/
* Non-linear RGB BT.709 colorspace - BGRA-10-10-10-2 planar. /
NvBufferColorFormat_BGRA_10_10_10_2_709,
/
* Non-linear RGB BT.2020 colorspace - BGRA-10-10-10-2 planar. /
NvBufferColorFormat_BGRA_10_10_10_2_2020,
/
* Invalid color format. */
NvBufferColorFormat_Invalid,
} NvBufferColorFormat;

我们的AI识别需要的是BGRA8888或者RGBA8888的,不是BGR101010或者RGB101010的。
难道不支持BGRA8888或者RGBA8888的吗?

Hi,
Please try the formats:

  NvBufferColorFormat_ABGR32,
  NvBufferColorFormat_XRGB32,
  NvBufferColorFormat_ARGB32,

您好!

 我修改代码,测试下面的三种视频输出格式,

NvBufferColorFormat_ABGR32,
NvBufferColorFormat_XRGB32,
NvBufferColorFormat_ARGB32,

运行后都是返回如下的错误:
PosixMemMap (48) failed
nvbuf_utils: NvBufferMemMap function failed… Exiting…
NvBufferMap failed

请问这个错误是什么原因? 如何解决这个问题???

您好!
我把原来的ret = NvBufferCreateEx (&ctx->dst_dma_fd, &input_params);更换为
ret = NvBufferCreateWithChromaLoc (&ctx->dst_dma_fd, &input_params, &outChromaSubsampling);

就可以支持
NvBufferColorFormat_ABGR32,
NvBufferColorFormat_XRGB32,
NvBufferColorFormat_ARGB32,

程序可以正常运行了。

现在有个问题:刚才跟我们项目组的其他同事沟通了,我们项目组中的AI识别只需要BRG24的,我怎样在解码后的NvBufferColorFormat_ABGR32中只拷贝BGR24的数据???

您好!

  我把原来的ret = NvBufferCreateEx (&ctx->dst_dma_fd, &input_params);更换为

ret = NvBufferCreateWithChromaLoc (&ctx->dst_dma_fd, &input_params, &outChromaSubsampling);
然后经过多次测试,测试下面的三种视频输出格式,
NvBufferColorFormat_ABGR32,
NvBufferColorFormat_XRGB32,
NvBufferColorFormat_ARGB32,

运行后都是返回如下的错误:
PosixMemMap (48) failed
nvbuf_utils: NvBufferMemMap function failed… Exiting…
NvBufferMap failed

请问这个错误是什么原因? 如何解决这个问题???
NVIDIA Jetson Xavier NX硬件平台是不是不支持把H264视频转换如下的三种格式
NvBufferColorFormat_ABGR32,
NvBufferColorFormat_XRGB32,
NvBufferColorFormat_ARGB32,

Hi,
BGR24 is not supported. Please convert to RGBA or BGRx.

Not sure why you cannot convert to RGBA. It should work by allocating ctx->dst_dma_fd like:

input_params.colorFormat = NvBufferColorFormat_ABGR32;
ret = NvBufferCreateEx (&ctx->dst_dma_fd, &input_params);

您好!

 我已经多次测试了下面的设置了:

input_params.colorFormat = NvBufferColorFormat_ABGR32;
ret = NvBufferCreateEx (&ctx->dst_dma_fd, &input_params);

运行后都是返回如下的错误:
PosixMemMap (48) failed
nvbuf_utils: NvBufferMemMap function failed… Exiting…
NvBufferMap failed

请问:

  1. 上面的这个错误打印信息表示什么意思?
    2, 如何解决这个问题???

Hi,
Do you use Jetpack 4 or Jetpack 5? Nvbuffer APIs are deprecated on Jetpack 5. If your release is 5.02, you would need to use NvBufSurface APIs.

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