Wednesday, 9 October 2019

Writing into GStreamer pipeline from OpenCV does not work

I wrote an RTSP server using the gst-rtsp-server library that is using the following pipeline:

udpsrc port=8553 ! application/x-rtp, payload=96 ! rtpjitterbuffer ! rtph264depay ! avdec_h264 ! x264enc tune=zerolatency ! rtph264pay name=pay0 pt=96

This outputs just fine in VLC media player when I feed the UDP source through command line:

gst-launch-1.0 -v videotestsrc ! video/x-raw,width=800,height=600,codec=h264,type=video ! videoscale ! videoconvert ! x264enc tune=zerolatency ! rtph264pay ! udpsink host=127.0.0.1 port=8553

Instead of using the videotestsrc I want to read from webcam and process the image using OpenCV with GStreamer in Python. I have built OpenCV from source with GStreamer support.

Unfortunately this does not work:

import cv2
import numpy

capture = cv2.VideoCapture(0)

# Identical to command line pipeline but using appsrc
output = cv2.VideoWriter('appsrc ! video/x-raw,width=800,height=600,codec=h264,type=video ! videoscale ! videoconvert ! x264enc tune=zerolatency ! rtph264pay ! udpsink host=127.0.0.1 port=8553', 0, 30, (800, 600))

while capture.isOpened():
    retval, frame = capture.read()

    if retval:
        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        output.write(frame)

        if cv2.waitKey(1):
            break
    else:
        break

capture.release()
output.release()

I am not getting any errors, but VLC does not display anything either. What am I doing wrong?



from Writing into GStreamer pipeline from OpenCV does not work

No comments:

Post a Comment