Home:ALL Converter>How to setup pipeline for gstreamer in opencv?

How to setup pipeline for gstreamer in opencv?

Ask Time:2016-11-18T09:53:42         Author:B Chow

Json Formatter

Background introduction: I am using gstreamer (version 1.8.2) to connect the rtsp video stream from an IP camera and feed it to opencv (version 3.1). The video stream is 640x480 at 10fps. URL as below: rtsp://192.168.0.200:554/1/h264minor

When I use gst-launch to test the video stream, the latency is very low ~300ms. command as below. I am pretty sure "latency=0" is the most important factor to achieve this low latency. gst-launch-1.0 -v rtspsrc location=rtsp://192.168.0.200:554/1/h264minor latency=0 ! decodebin ! autovideosink

In opencv, when I use below code to open rtsp stream, the latency is very large ~2.35s. In this way, I understand gstreamer will setup pipeline automatically with default latency. VideoCapture cap; cap.open("rtsp://192.168.0.200:554/1/h264minor")

After studied the code in opencv - cap_gstreamer.cpp, I found we can setup a manual pipeline for gstreamer that is similar with the one I used for gst-launch. In this way, I can control latency setting. So I changed my code as below. According to the comments in cap_gstreamer.cpp, the name of appsink could be "appsink0" or "opencvsink". But it always failed to setup this pipeline and I cannot get the video stream.

VideoCapture cap;
cap.open("rtspsrc location=rtsp://192.168.0.200:554/1/h264minor latency=0 ! decodebin ! appsink name = appsink0")`

The error messages as below:

GStreamer Plugin: Embedded video playback halted; module udpsrc1 reported: Internal data flow error. OpenCV Error: Unspecified error (GStreamer: unable to start pipeline ) in cvCaptureFromCAM_GStreamer, file /opencv-3.1.0/modules/videoio/src/cap_gstreamer.cpp, line 826

My question is:

  1. what is the proper gstreamer pipeline to get rtsp stream in opencv?
  2. or any alternative method to pass "latency" parameters from opencv to gstreamer?

I've spent four days to understand how opencv utilizes gstreamer and I know It's not enough. However, I would like to get some guide from opencv/gstreamer experts. Any hints/suggestions are welcome. Thanks in advance!

Author:B Chow,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/40668159/how-to-setup-pipeline-for-gstreamer-in-opencv
yy