Hardware accelerated gstreamer/nvvidconv convert from YUV* to RGB*?

Hi,

I have a GMSL2 camera and it’s working as /dev/video0:

v4l2-ctl -d /dev/video0 -V
Format Video Capture:
	Width/Height      : 3840/2160
	Pixel Format      : 'YUYV'
	Field             : None
	Bytes per Line    : 7680
	Size Image        : 16588800
	Colorspace        : sRGB
	Transfer Function : Default (maps to sRGB)
	YCbCr/HSV Encoding: Default (maps to ITU-R 601)
	Quantization      : Default (maps to Limited Range)
	Flags             : 

Can I say its raw format is YUYV? (I’m not sure)

If I tested it with videoconvert like this, it works:

gst-launch-1.0 -v v4l2src device=/dev/video0 ! 
'video/x-raw, width=3840, height=2160, format=YUY2, framerate=30/1' ! 
videoconvert ! 
'video/x-raw, width=3840, height=2160, format=BGRx, framerate=30/1' ! 
appsink caps='video/x-raw,format=BGRx' max-buffers=1

Please note that the first cap filter format is YUY2 because the test result show that YUYV does not work, which seems to conflicts with v4l2-ctl -d /dev/video0 -V result.

from the -v log below, I can see it’s converted to BGRx.

/GstPipeline:pipeline0/GstAppSink:appsink0.GstPad:sink: caps = video/x-raw, width=(int)3840, height=(int)2160, framerate=(fraction)30/1, interlace-mode=(string)progressive, format=(string)BGRx

Now I want to use nvvidconv to do the format convert to RGB/BGR or similar format, to use the hardware acceleration.

I replaced videoconvert by nvvidconv, but it does not work

gst-launch-1.0 -v v4l2src device=/dev/video0 ! 
'video/x-raw, width=3840, height=2160, format=YUY2, framerate=30/1' ! 
nvvidconv ! 
'video/x-raw, width=3840, height=2160, format=BGRx, framerate=30/1' ! 
appsink caps='video/x-raw,format=BGRx' max-buffers=1

I have run gst-inspect-1.0 nvvidconv and verified that nvvidconv supports YUY2 as source format and BGRx as sink format.
I don’t know why nvvidconv can’t replace videoconvert.

Any mistake I have made?

Hi,
Please try this sample and see if you can run it successfully:
V4l2src using OpenCV Gstreamer is not working in Jetson Xavier NX - #3 by DaneLLL

that example uses videoconvert, which is working fine here,
but I want to use nvvidconv.

Hi,
You have to use software converter in this use-case. Hardware converter does not support BGR. Here’s a similar topic for reference:
[Gstreamer] nvvidconv, BGR as INPUT - #2 by DaneLLL

what if I convert to BGRx ? I see it’s supported, but I can’t make it work

How do I force the conversion from YUY2 to BGRx?

Hi,
OpenCV doesn’t support BGRx, so we cannot send frame data in BGRx to appsink

I’m not useing full opencv’s gstreamer wrap, but GitHub - Myzhar/opencv_gstreamer_appsink: An useful class to acquire frame from a gstreamer pipeline and use them with OpenCV

the pipeline is open directly by gst_parse_launch( mPipelineStr.c_str(), &error );, and the appsink’s callback is handled by g_signal_connect( mSink, "new-sample", G_CALLBACK(on_new_sample_from_sink), this );, so OpenCV’s limitation doesnot apply in my case.

On the contrary, I have sucessfully got BGRx data from the callback (for videoconvert pipeline).

What I want now is to embed nvvidconv into my pipeline (to replace videoconvert)

Hi,
Please try

gst-launch-1.0 -v v4l2src device=/dev/video0 ! 
'video/x-raw, width=3840, height=2160, format=YUY2, framerate=30/1' ! 
nvvidconv ! 'video/x-raw(memory:NVMM),format=RGBx' ! nvvidconv ! 
'video/x-raw, width=3840, height=2160, format=BGRx, framerate=30/1' ! 
appsink caps='video/x-raw,format=BGRx' max-buffers=1

The nvvidconv supports

video/x-raw ! nvvidconv ! video/x-raw(memory:NVMM)
video/x-raw(memory:NVMM) ! nvvidconv ! video/x-raw

Does not support

video/x-raw ! nvvidconv ! video/x-raw

You may also try this patch:
Macrosilicon USB - #5 by DaneLLL
So that you can run like:

nvv4l2camerasrc ! 'video/x-raw(memory:NVMM),format=YUY2' ! nvvidconv ! video/x-raw,format=BGRx ! appsink
1 Like

Never knew that! indeed, it’s my first time to hear about it!

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