gpt4 book ai didi

python - 无法从 OpenCV Gstreamer 接收 gstreamer UDP 流

转载 作者:太空宇宙 更新时间:2023-11-03 20:10:02 24 4
gpt4 key购买 nike

我正在开发 Gazebo Sim,它使用“Gstreamer 插件”通过 UDP 流式传输相机视频。在Ubuntu 18.04上开始模拟。

有一些资源可以帮助您了解此结构的后端。 Gazebo Simulation PX4 Guide

他们提到了如何创建管道:

The video from Gazebo should then display in QGroundControl just as it would from a real camera.

It is also possible to view the video using the Gstreamer Pipeline. Simply enter the following terminal command:

gst-launch-1.0  -v udpsrc port=5600 caps='application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264' \
! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink fps-update-interval=1000 sync=false

并且它在终端上运行良好。我读了这些问题:

using gstreamer with python opencv to capture live stream?

Write in Gstreamer pipeline from opencv in python

然后,我尝试使用以下几行将此管道实现到 opencv 中:

video = cv2.VideoCapture('udpsrc port=5600 caps = "application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264" ! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink fps-update-interval=1000 sync=false', cv2.CAP_GSTREAMER)
#video.set(cv2.CAP_PROP_BUFFERSIZE,3)
# Exit if video not opened.
if not video.isOpened():
print("Could not open video")
sys.exit()

# Read first frame.
ok, frame = video.read()
if not ok:
print('Cannot read video file')
sys.exit()

但它只是给出错误:

无法打开视频

我在 opencv 中尝试了该管道的不同变体,但没有一个对我有帮助。

最佳答案

目前,您的管道无法让 OpenCV 从管道中提取解码的视频帧。这是因为所有帧都会转到最后的 autovideosink 元素,该元素负责在屏幕上显示帧。相反,您应该使用 appsink 元素,该元素专门用于允许应用程序从管道接收视频帧。

video = cv2.VideoCapture(
'udpsrc port=5600 caps = "application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264"'
' ! rtph264depay'
' ! avdec_h264'
' ! videoconvert'
' ! appsink', cv2.CAP_GSTREAMER)

关于python - 无法从 OpenCV Gstreamer 接收 gstreamer UDP 流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58765770/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com