use*_*126 6 python streaming opencv rtp gstreamer
我正在尝试使用我在这里找到的示例脚本来获取 OpenCV 图像并将其转换为 rtp/rtsp 流:
https://github.com/madams1337/python-opencv-gstreamer-examples/blob/master/gst_device_to_rtp .py
这是脚本的描述:
“gst_device_to_rtp 抓取 VideoCapture(0),对帧进行编码并将其流式传输到 rtp://localhost:5000”
这是我尝试使用的代码
# Cam properties
fps = 30.
frame_width = 1920
frame_height = 1080
# Create capture
#cap = cv2.VideoCapture(0)
# Set camera properties
cap.set(cv2.CAP_PROP_FRAME_WIDTH, frame_width)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, frame_height)
cap.set(cv2.CAP_PROP_FPS, fps)
# Define the gstreamer sink
gst_str_rtp = "appsrc ! videoconvert ! x264enc noise-reduction=10000 tune=zerolatency byte-stream=true threads=4 " \
" ! h264parse ! mpegtsmux ! rtpmp2tpay ! udpsink host=127.0.0.1 port=5000"
# Create videowriter as a SHM sink
out = cv2.VideoWriter(gst_str_rtp, 0, fps, (frame_width, frame_height), True)
# Loop it
while True:
# Get the frame
ret, frame = cap.read()
# Check
if ret is True:
# Flip frame
frame = cv2.flip(frame, 1)
# Write to SHM
out.write(frame)
else:
print "Camera error."
time.sleep(10)
cap.release()
Run Code Online (Sandbox Code Playgroud)
主要是这段代码,它指定了gstreamer管道配置:
# Define the gstreamer sink
gst_str_rtp = "appsrc ! videoconvert ! x264enc noise-reduction=10000 tune=zerolatency byte-stream=true threads=4 " \
" ! h264parse ! mpegtsmux ! rtpmp2tpay ! udpsink host=127.0.0.1 port=5000"
# Create videowriter as a SHM sink
out = cv2.VideoWriter(gst_str_rtp, 0, fps, (frame_width, frame_height), True)
Run Code Online (Sandbox Code Playgroud)
据我了解,它将 OpenCV 视频图像发送到“rtp://localhost:5000”
但是,每当我在脚本运行时尝试在终端中执行此终端命令时:
ffplay 'rtp://localhost:5000'
Run Code Online (Sandbox Code Playgroud)
它就像这样永远挂着:
我无法真正确定这到底意味着什么。这是否意味着它可以连接到该端口的本地主机,但在那里什么也没找到?我真的不知道。如果有另一个具有其他 rtsp url 的命令,该命令似乎可以工作,但这个命令不行。
如果我尝试“ffplay 'rtsp://localhost:5000'”,那么我只会收到连接拒绝错误(也许该流中没有生成任何内容)
该脚本是否真的将 rtp 流输出到 localhost:5000?或者我机器上的ffplay有问题?或者我应该执行一个特殊的 ffplay 命令?我应该怎么办?
| 归档时间: |
|
| 查看次数: |
3440 次 |
| 最近记录: |