我正在尝试设置一个rtsp服务器,用于编辑OpenCV处理后的IP摄像头的rtsp流并重新传输。捕获rtsp流并编辑帧可以正常工作,但我无法使rtsp服务器正常工作。我收到以下错误消息:
[ WARN:0] global /home/pi/opencv/opencv-4.1.1/modules/videoio/src/cap_gstreamer.cpp (896) open OpenCV | GStreamer warning: unable to query duration of stream
[ WARN:0] global /home/pi/opencv/opencv-4.1.1/modules/videoio/src/cap_gstreamer.cpp (933) open OpenCV | GStreamer warning: Cannot query video position: status=1, value=0, duration=-1
[ WARN:0] global /home/pi/opencv/opencv-4.1.1/modules/videoio/src/cap_gstreamer.cpp (1757) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module appsrc0 reported: Internal data stream error.
[ WARN:0] global /home/pi/opencv/opencv-4.1.1/modules/videoio/src/cap_gstreamer.cpp (1663) writeFrame OpenCV | GStreamer warning: Error pushing buffer to GStreamer pipeline
我已经尝试了两个不同的管道,如下代码所示,但两者都收到相同的错误消息。
我试图通过rtsp://192.168.y.y:8554/test在VLC播放器中访问rtsp流,但无法建立连接。
我的错误在哪里?有没有调试建议?我对GStreamer没有经验。
我正在使用 Python:3.7.3, OpenCV:4.1.1, GStreamer:1.14.4.0
import time
import cv2
import sys
print("Python: {}".format(sys.version))
print("OpenCV: {}".format(cv2.__version__))
import gi
gi.require_version('Gst', '1.0')
gi.require_version('GstRtspServer', '1.0')
gi.require_version('GstApp', '1.0')
from gi.repository import Gst, GLib, GstApp, GstRtspServer, GObject
print("Gst: {}.{}.{}.{}".format(*Gst.version()))
_ = GstApp
__ = GstRtspServer
Gst.init()
camSet_h265 = 'rtspsrc location=rtsp://192.168.x.x:8554/12 latency=0 buffer-mode=auto ! queue ! rtph265depay ! h265parse ! avdec_h265 ! videoconvert ! video/x-raw, format=BGR ! appsink drop=1'
camSet = camSet_h265
pipe_out = 'appsrc ! video/x-raw, format=BGR ! queue ! videoconvert ! video/x-raw, format=BGRx ! videoconvert ! x264enc speed-preset=veryfast tune=zerolatency bitrate=800 ! h264parse ! rtph264pay name=pay0 pt=96 config-interval=1'
# pipe_out = ' appsrc ! videoconvert ! x264enc tune=zerolatency bitrate=500 speed-preset=superfast ! h264parse ! rtph264pay name=pay0 pt=96 config-interval=1'
cam= cv2.VideoCapture(camSet, cv2.CAP_GSTREAMER)
time.sleep(2)
ret, frame = cam.read()
frame_num = int(cam.get(cv2.CAP_PROP_FRAME_COUNT))
frame_width = int(cam.get(cv2.CAP_PROP_FRAME_WIDTH))
frame_height = int(cam.get(cv2.CAP_PROP_FRAME_HEIGHT))
frame_fps = int(cam.get(cv2.CAP_PROP_FPS))
fourcc_fmt = cv2.VideoWriter_fourcc(*'X264')
out = cv2.VideoWriter(pipe_out, fourcc=fourcc_fmt, apiPreference=cv2.CAP_GSTREAMER, fps=frame_fps, frameSize=(frame_width, frame_height), isColor=True)
time.sleep(2)
while 1:
ret, frame = cam.read()
cv2.rectangle(frame,(20,100),(200,300),(0,255,0),8)
# cv2.imshow('nanoCam',frame)
out.write(frame)
if cv2.waitKey(1)==ord('q'):
break
cam.release()
cv2.destroyAllWindows()
..., fps=float(frame_fps), ...
- SeB