The following Gstreamer Receiver command works fine when I run it on the terminal.
gst-launch-1.0 -v udpsrc port=5004 ! 'application/x-rtp,payload=96,encoding-name=H264' ! rtpjitterbuffer mode=1 ! rtph264depay ! h264parse ! decodebin ! videoconvert ! autovideosink
I need to do capture these frames and do some processing using OpenCV's Gstreamer API. I used the exact pipeline in my C++ code but the VideoCapture is failing to start. The code is as follows:
#include <opencv2/opencv.hpp>
#include <opencv2/videoio.hpp>
using namespace cv;
#include <iostream>
using namespace std;
int main()
{
VideoCapture cap("udpsrc port=5004 ! application/x-rtp,payload=96,encoding-name=H264 ! rtpjitterbuffer mode=1 ! rtph264depay ! h264parse ! decodebin ! videoconvert ! autovideosink", CAP_GSTREAMER);
if (!cap.isOpened()) {
cerr <<"VideoCapture not opened"<<endl;
exit(-1);
}
while (true) {
Mat frame;
cap.read(frame);
imshow("receiver", frame);
// Process the frame.
if (waitKey(1) == 27) {
break;
}
}
return 0;
}
When I try to compile and run I receive:
(Receiver_Teal:2292): GStreamer-CRITICAL **: gst_element_get_state: assertion 'GST_IS_ELEMENT (element)' failed
VideoCapture not opened