gstreamer opencv assertion 'GST_IS_ELEMENT (element)' failed

Hi. I’m trying to send stream to my application using opencv in the next way:

Send from console:

gst-launch-1.0 -v nvcamerasrc fpsRange='30.0 30.0' ! "video/x-raw(memory:NVMM), width=(int)1280, height=(int)720, format=(string)I420, framerate=(fraction)30/1" ! nvvidconv ! "video/x-raw, width=(int)1280, height=(int)720, format=(string)I420, framerate=(fraction)30/1" ! jpegenc ! rtpjpegpay ! udpsink host=127.0.0.1 port=5000

Receive in my app using opencv:

VideoCapture cap("udpsrc port=5000 ! application/x-rtp,media=video,payload=26, encoding-name=JPEG,framerate=30/1 ! rtpjpegdepay ! jpegdec ! video/x-raw, format=(string)BGR ! appsink"
                 , cv::CAP_GSTREAMER);

But it gives me next errors on receiver side:

0:00:00.123412181 23829       0x7c9b70 WARN                GST_PADS gstpad.c:4092:gst_pad_peer_query:<jpegdec0:src> could not send sticky events
0:00:00.130739356 23829       0x7c9b70 WARN                 basesrc gstbasesrc.c:2948:gst_base_src_loop:<udpsrc0> error: Internal data flow error.
0:00:00.130769532 23829       0x7c9b70 WARN                 basesrc gstbasesrc.c:2948:gst_base_src_loop:<udpsrc0> error: streaming task paused, reason not-negotiated (-4)
(opencv_test_2:23829): GStreamer-CRITICAL **: gst_element_get_state: assertion 'GST_IS_ELEMENT (element)' failed

The problem seems to be related to jpegdec outputting in BGR.

You may try one of these pipelines in opencv:

VideoCapture cap("udpsrc port=5000 ! application/x-rtp,media=video,payload=26,encoding-name=JPEG,framerate=30/1 ! queue ! rtpjpegdepay ! jpegdec ! video/x-raw,format=I420 ! queue ! videoconvert ! video/x-raw,format=BGR ! appsink")

# Or this one, but be aware that nvjpegdec may not be appropriate for video:
VideoCapture cap("udpsrc port=5000 ! application/x-rtp,media=video,payload=26,encoding-name=JPEG,framerate=30/1 ! queue ! rtpjpegdepay ! nvjpegdec ! video/x-raw(memory:NVMM),format=I420 ! nvvidconv ! video/x-raw,format=BGRx ! queue ! videoconvert ! video/x-raw,format=BGR ! appsink

The jpegdec element is not able to convert the incoming I420 buffers to BGR buffers even though you are fixing in source pad side. So the capsfilter fails because of the video format incompatibility. Despite this, you still want to keep BGR format, you can add videoconvert after jpegdec.

gst-launch-1.0 udpsrc address=10.251.101.15 port=5000 ! "application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)JPEG,a-framerate=(string)30.000000,payload=(int)26" ! rtpjpegdepay ! jpegdec ! videoconvert ! "video/x-raw,format=(string)BGR" ! appsink sync=false