python - OpenCV VideoCapture 无法从流中读取

标签 python opencv ffmpeg

我可以在 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 中可用的二进制文件)。

  • 我正在使用更新到最新版本的 AWS Deeplens。
  • 安装ffmpeg,最新版本。

  • 然后,在/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
  • 在我的 Windows 机器上,我使用 WSL 并打开一个 SSH 隧道到 AWS Deeplens ssh -L 8090:localhost:8090 aws_cam@192.168.0.10
  • 此时,在我的 Windows 机器上,我可以打开 VLC,如果我指向 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/

    相关文章:

    python - ffmpeg:使用脚本获取持续时间:无法为 '2>&1 | grep "持续时间找到合适的输出格式“”

    python - 仅在可用时在 python 套接字中接收数据

    c++ - 基于图的图像分割

    c++ - 错误:(-215:断言失败)m.dims <= 2 in function 'FormattedImpl' in cv::dnn

    php - FFmpeg infile 路径,我的域

    带有 Axis P1347 的 ffmpeg 返回 400 Bad Request,但 Axis 1357 有效

    python - Mongodb 或 Couchdb 与 django 构建类似于顶级编码器的应用程序?

    python - 如何在 App Engine 上使用 Python 加载 .html 页面

    python - 终端关闭时应用程序关闭,如何停止?

    iphone - OpenCV iOS 阻止 Crash