gpt4 book ai didi

python - 使用 opencv 流式传输 m3u8 文件

转载 作者:太空狗 更新时间:2023-10-29 20:22:58 26 4
gpt4 key购买 nike

我正在尝试使用以下代码在 python 中使用 cv2 从 GoPro 捕获实时流:

VIDEO_URL = "http://10.5.5.9:8080/live/amba.m3u8"
cam = cv2.VideoCapture(VIDEO_URL)
cv2.namedWindow("GoPro",cv2.CV_WINDOW_AUTOSIZE)
while True:
f, im = cam.read()
cv2.imshow("GoPro",im)
if cv2.waitKey(5) == 27:
break
cam.release()
cv2.destroyAllWindows()

但收到以下错误:

WARNING: Couldn't read movie file http://10.5.5.9:8080/live/amba.m3u8
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /tmp/opencv-MRl1/opencv-2.4.7.1/modules/highgui/src/window.cpp, line 261
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "gopro_simple.py", line 167, in live_stream
cv2.imshow("GoPro",im)
cv2.error: /tmp/opencv-MRl1/opencv-2.4.7.1/modules/highgui/src/window.cpp:261: error: (-215) size.width>0 && size.height>0 in function imshow

流在 vlc 中工作,代码在网络摄像头上工作,所以看起来问题是 opencv 不喜欢 .m3u8 格式。任何有关如何解决此问题的想法/建议将不胜感激。谢谢。

最佳答案

找到一个调用 ffmpeg here 的解决方案- 效果很好(对 ffmpeg 选项进行了一些小改动):

VIDEO_URL = WEBURL + "live/amba.m3u8"

cv2.namedWindow("GoPro",cv2.CV_WINDOW_AUTOSIZE)

pipe = sp.Popen([ FFMPEG_BIN, "-i", VIDEO_URL,
"-loglevel", "quiet", # no text output
"-an", # disable audio
"-f", "image2pipe",
"-pix_fmt", "bgr24",
"-vcodec", "rawvideo", "-"],
stdin = sp.PIPE, stdout = sp.PIPE)
while True:
raw_image = pipe.stdout.read(432*240*3) # read 432*240*3 bytes (= 1 frame)
image = numpy.fromstring(raw_image, dtype='uint8').reshape((240,432,3))
cv2.imshow("GoPro",image)
if cv2.waitKey(5) == 27:
break
cv2.destroyAllWindows()

仍在修改代码,欢迎提出任何建议。

关于python - 使用 opencv 流式传输 m3u8 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22003441/

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