Changing gstreamer pipeline to opencv in python[SOLVED]

asked 2019-07-21 21:18:26 -0600

frenchy gravatar image

updated 2019-07-23 03:46:52 -0600

supra56 gravatar image

Trying to change this gstreamer pipline to python for opencv but having a few issues

gst-launch-1.0 -v playbin uri=rtsp://admin:[email protected]:554/Streaming/Channels/400 uridecodebin0::source::latency=10

This is the script I've referenced and managed to write, however I keep on getting this error

import cv2
import numpy as np

pipe = '"rtspsrc location=\"rtsp://admin:[email protected]:554/Streaming/Channels/400" latency=10 ! appsink'

cap = cv2.VideoCapture(pipe)

if not cap.isOpened():
    print('VideoCapture not opened')
    exit(0)

while True:
    ret, frame = cap.read()

    if not ret:
        print('empty frame')
        break

    cv2.imshow('display', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
    cap.release()

cv2.destroyAllWindows()

Error:

GStreamer-CRITICAL **: 09:06:55.638: gst_element_get_state: assertion 'GST_IS_ELEMENT (element)' failed
edit retag flag offensive close merge delete

Comments

Remove slash location=\"rtsp to location="rtsp

supra56 gravatar imagesupra56 ( 2019-07-22 21:32:26 -0600 )edit

Thanks man! I figured it had something to do with the backward slash.

I am in a predicament at the moment as to why the gstreamer pipeline for VideoCapture doesn't work with latency in it..

  def open_cam_rtsp(uri, width, height, latency):
    gst_str = ('rtspsrc location={} latency={} ! '
               'rtph264depay ! h264parse ! avdec_h264 ! '
               ' autovideoconvert ! autovideosink ').format(uri, latency)
    return cv2.VideoCapture(gst_str, cv2.CAP_GSTREAMER)

When i change autovideoconvert and autovideosinkto videoconvert and appsink respectively. I have to omit the latency in order for it to work. Do you have any ideas on how improve on it?

Edit: Found a way! I had to change avdec_h264 to decodebin then it works with latency.

frenchy gravatar imagefrenchy ( 2019-07-22 21:47:54 -0600 )edit

Good job, frenchy.

supra56 gravatar imagesupra56 ( 2019-07-23 03:46:23 -0600 )edit