我可以在 VLC 中打开一个流,但在 OpenCV 中我无法捕获帧。 (Python 2.7、OpenCV 3.4.3 二进制分发版 x86、Windows 10)。我一直在关注本指南:https://medium.com/@tomgrek/hackers-guide-to-the-aws-deeplens-1b8281bc6e24但我似乎无法从在线随机流中读取(不确定我是否应该能够,我看到了这个问题 opencv videocapture can't open MJPEG stream 关于使用 ffmpeg 进行编译,但我刚刚下载了 Sourceforge 中可用的二进制文件)。
然后,在/etc/ffserver.conf 我添加了:
<Stream camera.h264>
File "/opt/awscam/out/ch1_out.h264"
VideoFrameRate 6
VideoSize 320x240
NoAudio
</Stream>
<Stream camera.mjpeg>
File "/opt/awscam/out/ch2_out.mjpeg"
VideoFrameRate 3
VideoSize 640x480
Format mjpeg
NoAudio
</Stream>
ffserver -f /etc/ffserver.conf
ssh -L 8090:localhost:8090 aws_cam@192.168.0.10
http://localhost:8090/camera.mjpeg
我可以看到来自摄像机的流。 但是,如果我运行以下代码:
cam = cv2.VideoCapture("http://localhost:8090/camera.mjpeg")
success, frame = cam.read()
opened = cam.isOpened()
success, frame, opened
我得到:
False, None, False
如果我浏览到
http://localhost:8090/stat.html
, 我懂了:Available Streams
Path Served Conns bytes Format Bit rate kbits/s Video kbits/s Codec Audio kbits/s Codec Feed
test1.mpg 0 0 mpeg 96 64 mpeg1video 32 mp2 feed1.ffm
test.asf 0 0 asf_stream 320 256 msmpeg4 64 wmav2 feed1.ffm
stat.html 17 42150 - - - -
index.html 0 0 - - - -
camera.h264 3 6805k h264 0 0 libx264 0 /opt/awscam/out/ch1_out.h264
camera.mjpeg 12 41073k mjpeg 0 0 mjpeg 0 /opt/awscam/out/ch2_out.mjpeg
每次我调用
VideoCapture()
我看看Served
的数量如何对于camera.mjpeg
流增加了 2 或 3 并且 bytes
,增加了几兆字节,但我在 OpenCV 中看不到任何内容。我没有在我的 Windows 10 中尝试过任何其他视频设备,但我可以毫无问题地读取图像。我还尝试了一个在线随机流,也在 VLC 中打开但在 OpenCV 中没有打开,尝试了这个:http://136.176.70.200/mjpg/video.mjpg有任何想法吗?
最佳答案
看起来我需要自己编译 OpenCV 并支持 ffmpeg。
关于python - OpenCV VideoCapture 无法从流中读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53830209/