|
【技术讨论】
Gstreamer+python+opencv解码rtsp流失败
发表于 2023-5-8 10:17:47
浏览:4661
|
回复:2
打印
只看该作者
[复制链接]
楼主
本帖最后由 spp 于 2023-5-8 10:30 编辑
如题,我打算用Gstreamer+python+opencv解码rtsp流,查看并提取摄像头的画面,但是一直失败。
板子:AIO3588JQ
系统:Ubuntu20.04
固件:firefly AIO3588JQ的官方Ubuntu固件
Gstreamer:官方预安装的版本1.16.3
python:3.7.2
oepncv:4.5.0和4.x和4.3.0都用源码编译试过,gstreamer选项也编译进去了
下面是用oepncv获取rtsp流解码的代码
- import cv2
- import numpy as np
- import time
- import os
- def videocapture():
- video_stream_path = 'rtspsrc location=rtsp://admin:Admin123@192.168.8.114//Streaming/Channels/1 latency=0 ! rtph264depay ! queue ! decodebin ! videoconvert ! appsink drop=true'
- cap = cv2.VideoCapture(video_stream_path,cv2.CAP_GSTREAMER) # 生成读取摄像头对象
- out_gst = 'appsrc is-live=true caps=video/x-raw,format=(string)BGR,framerate=(fraction)30/1 ! videoconvert ! ximagesink sync=false'
- cap_out = cv2.VideoWriter(out_gst, cv2.VideoWriter_fourcc(*'H264'), 25, (1280, 720), True)
- a = time.time()
- while cap.isOpened():
- ret, frame = cap.read() # 读取摄像头画面
- print(frame.shape)
- cv2.imshow('video', frame) # 显示画面
- key = cv2.waitKey(1)
- cap_out.write(frame) # 视频保存
- # 按Q退出
- if key == ord('q'): # or count >=75:
- break
- cap.release() # 释放摄像头
- cap_out.release()
- cv2.destroyAllWindows() # 释放所有显示图像窗口
- if __name__ == '__main__':
- videocapture()
复制代码
报错信息
- python test_save_capture_rtsp.py
- [ WARN:0] global /home/firefly/Downloads/opencv-4.3.0/modules/videoio/src/cap_gstreamer.cpp (898) open OpenCV | GStreamer warning: unable to query duration of stream
- [ WARN:0] global /home/firefly/Downloads/opencv-4.3.0/modules/videoio/src/cap_gstreamer.cpp (935) open OpenCV | GStreamer warning: Cannot query video position: status=1, value=0, duration=-1
- (724, 1280, 3)
复制代码 图像的高多了4个像素,而且图像值都是0,画面一片黑色,也许是解码器的原因,但是我在终端用gstreamer命令行,又能够正常调用mppvideodec和decodebin插件解码,有正常的图像显示,放在opencv里又不行。
在opencv里用avdec_h264解码器解码,又是能正常显示的,但是用的软件解码,使用mppvideodec和decodebin硬件解码会报错
|
|