【发布时间】:2021-02-13 10:33:54
【问题描述】:
我们正在开发一种软件,用于使用 GStreamer 使用 RTSP 从两个不同的摄像机流式传输视频。为了简化采集过程,我们将 OpenCV 与 Python 3 结合使用。
问题是:我们想将流推送到 UDP 接收器,通过 LAN 将其作为 RTSP 流重新发布,然后在另一台 PC 中读取。但我们无法让它发挥作用。
这是获取相机图像并使用udpsink 开始流式传输的 Python 代码。在这种情况下,我们将访问我们的本地网络摄像头,以便任何人都可以直接测试代码。
import cv2
import time
from multiprocessing import Process
def send():
video_writer = cv2.VideoWriter(
'appsrc ! '
'videoconvert ! '
'x264enc tune=zerolatency speed-preset=superfast ! '
'rtph264pay ! '
'udpsink host=127.0.0.1 port=5000',
cv2.CAP_GSTREAMER, 0, 1, (640, 480), True)
video_getter = cv2.VideoCapture(0)
while True:
if video_getter.isOpened():
ret, frame = video_getter.read()
video_writer.write(frame)
# cv2.imshow('send', data_to_stream)
time.sleep(0.1)
if __name__ == '__main__':
s = Process(target=send)
s.start()
s.join()
cv2.destroyAllWindows()
运行时,我们只会收到一个警告:
[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (935) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
然后我们尝试使用来自 GStreamer 的examples/test-launch 将流通过我们的 LAN 重新发布为 RTSP
./test-launch " udpsrc port=5000 ! h264parse ! rtph264pay name=pay0 pt=96"
这给我们没有错误,但默认消息
stream ready at rtsp://127.0.0.1:8554/test
然后VLC无法打开这个地址的流。
~$ vlc -v rtsp://127.0.0.1:8554/test
VLC media player 3.0.11 Vetinari (revision 3.0.11-0-gdc0c5ced72)
[000055f5dacf3b10] main libvlc: Running vlc with the default interface. Use 'cvlc' to use vlc without interface.
Qt: Session management error: None of the authentication protocols specified are supported
[00007f5ea40010f0] live555 demux error: Failed to connect with rtsp://127.0.0.1:8554/test
[00007f5ea4003120] satip stream error: Failed to setup RTSP session
我想这与我们的管道有关,但我真的不明白它可能是什么。 任何帮助将不胜感激。提前致谢。
【问题讨论】:
标签: python-3.x opencv video-streaming gstreamer rtsp