如何通过OpenCV处理VLC UDP流 [英] How to process VLC UDP stream over OpenCV

查看:926
本文介绍了如何通过OpenCV处理VLC UDP流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够通过VLC命令行接收/查看UDP h264数据包(即VLC --network-caching 0 --demux h264 udp://...)

I was able to receive/view UDP h264 packets through VLC command line (i.e. VLC --network-caching 0 --demux h264 udp://...)

我打算通过OpenCV算法处理那些帧.但是,我似乎找不到找到将VLC帧发送到我的Python OpenCV脚本的方法.

I am planning on processing those frames through OpenCV algorithms. However, I can't seem to find a way to send the VLC frames over to my Python OpenCV script.

是否可以在单独的脚本中通过Numpy传递要处理的VLC流输出?

Is it possible to pipe VLC stream output to be processed through Numpy in a separate script?

我以前曾尝试使用其VideoCapture功能直接将视频流传输到OpenCV,但是由于某些原因,视频停顿并停止在失真的黑色图像上.就目前而言,似乎只有VLC才是唯一的解决方案(尽管我不确定为什么VLC可以替代其他方法).

I have previously tried directly streaming to OpenCV by using its VideoCapture function, but for some reason, the video stalls and stops at a distorted black image. For now, it seems like incorporating VLC is the only solution (even though I am not totally sure why VLC works over other methods).

谢谢.

以下是终端上的错误消息的摘要.前几帧似乎有问题,但我不知道为什么该流在VLC上有效.从客户端,我首先发送了默认关键帧数据,然后发送了视频供稿h264数据.

The following is a snippet of the error message on the terminal. It seems like there are problems with the first few frames, but I don't know why the stream works on VLC. From the client, I first sent a default key frame data, and then sent video feed h264 data.

[h264 @ 0x7f9c50020200] top block unavailable for requested intra mode -1
[h264 @ 0x7f9c50020200] error while decoding MB 7 0, bytestream 7208
[h264 @ 0x7f9c50020200] top block unavailable for requested intra mode -1
[h264 @ 0x7f9c50020200] error while decoding MB 8 9, bytestream 7381

推荐答案

您可以使用 ffmpeg 用于流式传输.

You can use ffmpeg for streaming.

首先在终端中测试ffmpeg流.在linux中,我们使用v4l2从摄像头抓取帧.

First test ffmpeg streaming in terminal. In linux, we use v4l2 to grab frames from camera.

服务器:

ffmpeg -f v4l2 -i /dev/video0 -preset ultrafast -vcodec libx264 -tune zerolatency -b 900k -f h264 udp://127.0.0.1:5000

客户:

ffplay udp://127.0.0.1:5000

如果您能够在客户端上查看流,那么我们可以使用OpenCV进行图像处理. OpenCV必须具有ffmepg支持.请参阅此链接以获取ffmpeg支持检查.

If you're able to view the stream on the client side, then we can use OpenCV for image processing. OpenCV must have ffmepg support. See this link for ffmpeg support check.

    cap = cv2.VideoCapture('udp://127.0.0.1:5000',cv2.CAP_FFMPEG)
    if not cap.isOpened():
        print('VideoCapture not opened')
        exit(-1)

    while True:
        ret, frame = cap.read()

        if not ret:
            print('frame empty')
            break

        cv2.imshow('image', frame)

        if cv2.waitKey(1)&0XFF == ord('q'):
            break

    cap.release()
    cv2.destroyAllWindows()

这篇关于如何通过OpenCV处理VLC UDP流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆