I have been searching everywhere and tested what seems to be everything in order to get OpenCV in python to accept a video stream through gst-launch-1.0 from a RPi camera connected to a RPi. So far, I have nothing but failed. Here is my code, which works in terminal:

On Ubuntu 16.04:

gst-launch-1.0 tcpclientsrc host= port=5600  ! gdpdepay ! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink  sync=false

On RPi3b:

raspivid --nopreview \
     --mode 5 \
     -w 300 \
     -h 300\
     --bitrate 15000000 \
     -fl \
     --timeout 0 \
     --output - | \
     gst-launch-1.0 -q fdsrc ! h264parse ! rtph264pay config-interval=1 pt=96 ! gdppay ! tcpserversink host= port=5600

This is what I try to do in OpenCV: OpenCV v.3.3.0 in Python

import numpy as np
import cv2
pipeStr = "gst-launch-1.0 tcpclientsrc host= port=5600  ! gdpdepay ! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink  sync=false"
cap = cv2.VideoCapture(pipeStr)


I have tried various strings for both the RPi3b and as the argument in VideoCapture, but I cannot seem to find the correct one. cap.isOpened() always returns false. I believe that gstreamer is working with openCV, as I can import gstreamer libs like python-gi without problems, and I compiled openCV from source with gstreamer flags in the cmakefiles ON, which was confirmed in the output from cmake.

The RPi video is streaming through an ethernet cable to my computer, and I can get the video in gstreamer in terminal with about 200ms delay. The problem is that I would like to do some video manipulation on my topside computer, and hence, I would like to have it streamed to openCV in python.

Does anyone know anything about this or how this can be done?

  • Maybe this will help you. – Kreumz Mar 1 '18 at 8:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.