Copying YUV420 buffer using NvBufferTransform cause pixel value change

Hi,
I want composite several image using NvBufferTransform.
Firstly I wrote simple program copying buffer.

Each plane of input buffer were filled with ‘Y’(0x59) for plane[0], ‘U’(0x55) for plane[1] and ‘V’(0x56) for plane[2].
But each plane of output buffer filled with 0x54, 0x58 and 0x4E.

Here is outline of source code.

I use JetPack 4.6.2 and /etc/nv_tegra_release is following.

# R32 (release), REVISION: 7.2, GCID: 30192233, BOARD: t186ref, EABI: aarch64, DATE: Sun Apr 17 09:53:50 UTC 2022

Attached file is source and Makefile.
nvbuf_transform_test.zip (28.0 KB)

regards.

I’m sorry, I forgot fill buffer.
Here is fixed source code.

But output is still strange.

U plane of output was filled V.

nvbuf_transform_test_2.zip (72.6 KB)

regards

Hi,
Please apply this prebuilt lib and give it a try:
Video convert sample results are missing? - #12 by DaneLLL

Hi,

libnvbuf_utils.so already has been linked. Here is ldd output.

$ ldd nvbuf_trasform_test
        linux-vdso.so.1 (0x0000007f87444000)
        libnvbuf_utils.so.1.0.0 => /usr/lib/aarch64-linux-gnu/tegra/libnvbuf_utils.so.1.0.0 (0x0000007f873c5000)
        libstdc++.so.6 => /usr/lib/aarch64-linux-gnu/libstdc++.so.6 (0x0000007f87231000)
        libgcc_s.so.1 => /lib/aarch64-linux-gnu/libgcc_s.so.1 (0x0000007f8720d000)
        libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000007f870b4000)
        /lib/ld-linux-aarch64.so.1 (0x0000007f87418000)
        libnvrm.so => /usr/lib/aarch64-linux-gnu/tegra/libnvrm.so (0x0000007f87080000)
        libnvrm_graphics.so => /usr/lib/aarch64-linux-gnu/tegra/libnvrm_graphics.so (0x0000007f87060000)
        libEGL.so.1 => /usr/lib/aarch64-linux-gnu/libEGL.so.1 (0x0000007f8703f000)
        libnvddk_vic.so => /usr/lib/aarch64-linux-gnu/tegra/libnvddk_vic.so (0x0000007f87021000)
        libnvbuf_fdmap.so.1.0.0 => /usr/lib/aarch64-linux-gnu/tegra/libnvbuf_fdmap.so.1.0.0 (0x0000007f8700e000)
        libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x0000007f86f55000)
        libnvos.so => /usr/lib/aarch64-linux-gnu/tegra/libnvos.so (0x0000007f86f37000)
        libpthread.so.0 => /lib/aarch64-linux-gnu/libpthread.so.0 (0x0000007f86f0b000)
        libGLdispatch.so.0 => /usr/lib/aarch64-linux-gnu/libGLdispatch.so.0 (0x0000007f86ddf000)
        libdl.so.2 => /lib/aarch64-linux-gnu/libdl.so.2 (0x0000007f86dca000)
        librt.so.1 => /lib/aarch64-linux-gnu/librt.so.1 (0x0000007f86db3000)

Hi,
Please replace the default libnvbuf_utils.so with the attached one and give it a try. You may also refer to the sample for development:

/usr/src/jetson_multimedia_api/samples/07_video_convert/

To ensure your application is correct.

Hi,

I seems same result with prebuilt library.
And I also got same result with 07_video_convert sample.

Here is reproduction steps.

# replace library
$ sudo mv /usr/lib/aarch64-linux-gnu/tegra/libnvbuf_utils.so.1.0.0 \
          /usr/lib/aarch64-linux-gnu/tegra/libnvbuf_utils.so.1.0.0.bak
$ sudo cp libnvbuf_utils.so /usr/lib/aarch64-linux-gnu/tegra/libnvbuf_utils.so.1.0.0

Reproduction steps.

$ hexdump -C yuv420.bin
00000000  59 59 59 59 59 59 59 59  59 59 59 59 59 59 59 59  |YYYYYYYYYYYYYYYY|
*
000e1000  55 55 55 55 55 55 55 55  55 55 55 55 55 55 55 55  |UUUUUUUUUUUUUUUU|
*
00119400  56 56 56 56 56 56 56 56  56 56 56 56 56 56 56 56  |VVVVVVVVVVVVVVVV|
*
00151800
$ ./video_convert yuv420.bin 1280 720 YUV420 output 1280 720 YUV420
End of File
File read complete.
App run was successful
$ hexdump -C output0
00000000  59 59 59 59 59 59 59 59  59 59 59 59 59 59 59 59  |YYYYYYYYYYYYYYYY|
*
000e1000  56 56 56 56 56 56 56 56  56 56 56 56 56 56 56 56  |VVVVVVVVVVVVVVVV|
*
00151800

regards.

Hi,
Please apply the prebuilt lib and try again.
r32_7_TEST_libnvbuf_utils.zip (18.7 KB)

Hi,

I works for YUV420 data.

# Copying data
$ ./video_convert yuv420.bin 1280 720 YUV420 yuv420_yuv420 1280 720 YUV420
$ hexdump -C yuv420_yuv4200
00000000  59 59 59 59 59 59 59 59  59 59 59 59 59 59 59 59  |YYYYYYYYYYYYYYYY|
*
000e1000  55 55 55 55 55 55 55 55  55 55 55 55 55 55 55 55  |UUUUUUUUUUUUUUUU|
*
00119400  56 56 56 56 56 56 56 56  56 56 56 56 56 56 56 56  |VVVVVVVVVVVVVVVV|
*
00151800

# from planar to semi-planar
$ ./video_convert yuv420.bin 1280 720 YUV420 yuv420_nv12 1280 720 NV12
$ hexdump -C yuv420_nv120
00000000  59 59 59 59 59 59 59 59  59 59 59 59 59 59 59 59  |YYYYYYYYYYYYYYYY|
*
000e1000  55 56 55 56 55 56 55 56  55 56 55 56 55 56 55 56  |UVUVUVUVUVUVUVUV|
*
00151800

But I got similar issue for Packed YUV422 data.
I tried to convert from UYVY to YUV420, but ‘U’ data has been disappeared.

$ printf UYVY"%.s" {1..460800} > uyvy.bin # 1280x720 UYVY data
$ ./video_convert uyvy.bin 1280 720 UYVY uyvy_yuv420 1280 720 YUV420
$ hexdump -C uyvy_yuv4200
00000000  59 59 59 59 59 59 59 59  59 59 59 59 59 59 59 59  |YYYYYYYYYYYYYYYY|
*
000e1000  56 56 56 56 56 56 56 56  56 56 56 56 56 56 56 56  |VVVVVVVVVVVVVVVV|
*
00151800

regards.

Hi,
For UYVY to YUV420, it is a format conversion and certain points may be rounded to nearby value. This looks expected.

Hi,

video_convert select bilinear interpolation by default. so I understand chroma values
are different between input and output.
But in this case, Cr an Cb are filled with ‘U’ and ‘V’, so I think Cr and Cb values don’t change
regardless of the interpolation algorithm.
I also test with nearest neighbor interpolation using -im 0 option, but ‘U’ values was also disappeared.
I think it meens that Cr were not sampled and Cb value were sampled when Cr plane interpolation.

regards.

From UYVY to YUYV conversion gots similar issue.

$ ./video_convert uyvy.bin 1280 720 UYVY uyvy_yuyv 1280 720 YUYV
$ hexdump -C uyvy_yuyv0
00000000  59 56 59 56 59 56 59 56  59 56 59 56 59 56 59 56  |YVYVYVYVYVYVYVYV|
*
001c2000

Hi,
Please try this prebuilt lib.
r32_7_TEST_libnvbuf_utils.zip (18.8 KB)

If there is still failure cases, please share the steps.

1 Like

Hi,

It seems that works fine. Thank you for your helps.
Is these fixes will included in JetPack 4.6.x and JetPack 5.0.x?

Hi
For Jetpack 4, please apply the attached lib. For Jetpack 5, we switch to NvBufSurface and the cases can be different. Will do further check on Jetpack 5.

Hi,
Sorry for the late reply.

For Jetpack 4, please apply the attached lib. For Jetpack 5, we switch to NvBufSurface and the cases can be different. Will do further check on Jetpack 5.

I’ ve seen NvBufSurface API reference. It seems nicer design.
Does NvBufSurface API work with multimedia API on Jetson 4 platform?
If is that true, I’ll consider to switch API.

regards.

Hi,
On Jetpack 4, NvBufSurface is used only in DeepStream SDK. If you can use DeepStream SDK in your use-case, can switch to NvBufSurface APIs. If your use-case is based on jetson_multimedia_api, have to use NvBuffer APIs.

On Jetpack 5, we have deprecated NvBuffer and unified to NvBufSurface APIs.

Hi,

Thank you for explanation.
I’m developing with Jetpack 4. So, I’ll use modified libnvbuf_utils.so for now.

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