Reputation: 451
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?
Upvotes: 2
Views: 2463
Reputation: 1794
Your caps for appsrc
are:
appsrc ! video/x-raw,width=800,height=600,codec=h264,type=video !
Which means you are pushing appsrc
to output a h264 video. In OpenCv appsrc
only outputs raw BGR frames. Taking out this caps would be sufficient to make it work.
'appsrc ! videoconvert ! x264enc tune=zerolatency ! rtph264pay ! udpsink host=127.0.0.1 port=8553'
Hint: Gstreamer has verbosity levels. You can see the errors produced by gstreamer by changing the verbosity level of gstreamer.
You can do this with as such:
GST_DEBUG=3 python my_script.py
Upvotes: 1