Ask Your Question

Revision history [back]

Streaming data to OpenCV from GStreamer

I've got two embedded cameras that can stream data and I want to use OpenCV to do stereo calibration and depth measurements. I can display the video from a camera using:

gst-launch-1.0 rtpbin name=rtpbin udpsrc caps='application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264' port=5004 ! rtpbin.recv_rtp_sink_0 rtpbin. ! rtph264depay ! decodebin ! videoconvert ! autovideosink

The second camera is on port 5005 so I can display both at once. I've built OpenCV 3.4.6 using this script https://github.com/milq/milq/blob/master/scripts/bash/install-opencv.sh and created an SDP file to open:

c=IN IP4 127.0.0.1
m=video 5004 RTP/AVP 96
a=rtpmap:96 H264/90000

But I get the errors:

GStreamer-CRITICAL **: 15:26:57.855: gst_element_get_state: assertion 'GST_IS_ELEMENT (element)' failed
VIDIOC_REQBUFS: Inappropriate ioctl for device

I changed the build script to add:

-DWITH_GSTREAMER=ON -DWITH_OPENEXR=OFF

then tried:

    VideoCapture vid0("udpsrc caps = \"application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, port=5004, payload=(int)96\" ! rtph264depay ! decodebin ! videoconvert ! autovideosink", CAP_GSTREAMER);

But I get:

GStreamer-CRITICAL **: 15:25:54.893: gst_element_get_state: assertion 'GST_IS_ELEMENT (element)' failed

What am I doing wrong?

Streaming data to OpenCV from GStreamer

I've got two embedded cameras that can stream data and I want to use OpenCV to do stereo calibration and depth measurements. I can display the video from a camera using:

gst-launch-1.0 rtpbin name=rtpbin udpsrc caps='application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264' port=5004 ! rtpbin.recv_rtp_sink_0 rtpbin. ! rtph264depay ! decodebin ! videoconvert ! autovideosink

The second camera is on port 5005 so I can display both at once. I've built OpenCV 3.4.6 using this script https://github.com/milq/milq/blob/master/scripts/bash/install-opencv.sh and created an SDP file to open:

c=IN IP4 127.0.0.1
m=video 5004 RTP/AVP 96
a=rtpmap:96 H264/90000

But I get the errors:

GStreamer-CRITICAL **: 15:26:57.855: gst_element_get_state: assertion 'GST_IS_ELEMENT (element)' failed
VIDIOC_REQBUFS: Inappropriate ioctl for device

I changed the build script to add:

-DWITH_GSTREAMER=ON -DWITH_OPENEXR=OFF

then tried:

    VideoCapture vid0("udpsrc caps = \"application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, port=5004, payload=(int)96\" ! rtph264depay ! decodebin ! videoconvert ! autovideosink", CAP_GSTREAMER);

But I get:

GStreamer-CRITICAL **: 15:25:54.893: gst_element_get_state: assertion 'GST_IS_ELEMENT (element)' failed

Update: I rebuilt with OpenCV 4.1.1. With the SDP file I get:

[h264 @ 0x55c6ed66f840] non-existing PPS 0 referenced
[h264 @ 0x55c6ed66f840] non-existing PPS 0 referenced
[h264 @ 0x55c6ed66f840] decode_slice_header error
[h264 @ 0x55c6ed66f840] no frame!
[h264 @ 0x55c6ed66f840] non-existing PPS 0 referenced
[h264 @ 0x55c6ed66f840] non-existing PPS 0 referenced
[h264 @ 0x55c6ed66f840] decode_slice_header error
[h264 @ 0x55c6ed66f840] no frame!

With the GStreamer command I get:

[ WARN:0] global /home/tom/Documents/opencv/OpenCV/modules/videoio/src/cap_gstreamer.cpp (801) open OpenCV | GStreamer warning: cannot find appsink in manual pipeline
[ WARN:0] global /home/tom/Documents/opencv/OpenCV/modules/videoio/src/cap_gstreamer.cpp (480) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created

What am I doing wrong?