流视频从ffmpeg和捕获与OpenCV [英] Stream video from ffmpeg and capture with OpenCV

查看:562
本文介绍了流视频从ffmpeg和捕获与OpenCV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视频流进入rtp到ffmpeg,我想管道这个到我的OpenCV工具进行实时流处理。 rtp链接是工作,因为我能够发送传入的数据到一个文件,并播放它(或播放,如果通过ffplay)。我的OpenCV实现也是功能,因为我能够从文件和网络摄像头捕获视频。



问题是流到OpenCV。我听说这可以使用命名管道。首先我可以将ffmpeg输出流传输到管道,然后让OpenCV打开这个管道并开始处理。



我试过的:



我在cygwin bash中创建一个命名管道:

  $ mkfifo stream_pipe 

接下来我使用我的ffmpeg命令从rtp拉取流并将其发送到管道:

  $ ffmpeg -f avi -i rtp://xxx.xxx.xxx.xxx:1234 -f avi -y out.avi> stream_pipe 

我不知道这是否正确的方式去发送流到命名管道但它似乎是接受命令和工作,因为ffmpeg的输出给我的比特率,fps等。



接下来我使用命名管道在我的OpenCV捕获函数:

  $ ./cvcap.exe stream_pipe 

其中cvcap.cpp的代码归结为:

  cv: :VideoCapture * pIns = new cv :: VideoCapture(argv [1]); 

程序在到达这一行时似乎挂起,所以,我想知道这是否正确这样做的方式。我从来没有使用过命名管道,我不知道这是否正确的用法。另外,我不知道我是否需要在OpenCV中以不同的方式处理命名管道 - 更改代码以接受这种输入。像我说的,我的代码已经接受文件和摄像机输入,我只是挂在一个流进来。我只听说命名管道可以用于OpenCV - 我还没有看到任何实际的代码或命令! / p>

感谢任何帮助或见解。



UPDATE: b
$ b

我相信命名管道可能不会按照我的意图工作。如 this cygwin论坛帖子所示:


问题是Cygwin的fifos实现非常麻烦。我不建议使用fifos作为最简单的应用程序。


我可能需要找到另一种方法。我试图管道ffmpeg输出到一个正常的文件,然后有OpenCV读它在同一时间。这在一定程度上工作,但我想在一个文件中同时读写可能是危险的 - 谁知道会发生什么!

解决方案

希望它不是太晚了,但我已经尝试过同样的事情前一段时间,这里是我是如何做到的。



OpenCV的视频解码后端实际上是ffmpeg,所以它的所有功能在OpenCV中也可用。并不是所有的界面都是暴露的,这增加了一些困难,但你可以发送rtp流地址到OpenCV。

  cap。 open(rtp://xxx.xxx.xxx.xxx:1234); 

重要:OpenCV无法访问受密码保护的rtp流。要做到这一点,你需要提供用户名和密码,没有暴露的API。


I have a video stream coming in on rtp to ffmpeg and I want to pipe this to my OpenCV tools for live streaming processing. The rtp linkage is working because I am able to send the incoming data to a file and play it (or play if via ffplay). My OpenCV implementation is functional as well because I am able to capture video from a file and also a webcam.

The problem is the streaming to OpenCV. I have heard that this may be done using a named pipe. First I could stream the ffmpeg output to the pipe and then have OpenCV open this pipe and begin processing.

What I've tried:

I make a named-pipe in my cygwin bash by:

    $ mkfifo stream_pipe

Next I use my ffmpeg command to pull the stream from rtp and send it to the pipe:

    $ ffmpeg -f avi -i rtp://xxx.xxx.xxx.xxx:1234 -f avi -y out.avi > stream_pipe

I am not sure if this is the right way to go about sending the stream to the named pipe but it seems to be accepting the command and work because of the output from ffmpeg gives me bitrates, fps, and such.

Next I use the named pipe in my OpenCV capture function:

    $ ./cvcap.exe stream_pipe

where the code for cvcap.cpp boils down to this:

    cv::VideoCapture *pIns = new cv::VideoCapture(argv[1]);

The program seems to hang when reaching this one line, so, I am wondering if this is the right way of going about this. I have never used named pipes before and I am not sure if this is the correct usage. In addition, I don't know if I need to handle the named pipe differently in OpenCV--change code around to accept this kind of input. Like I said, my code already accepts files and camera inputs, I am just hung up on a stream coming in. I have only heard that named pipes can be used for OpenCV--I haven't seen any actual code or commands!

Any help or insights are appreciated!

UPDATE :

I believe named pipes may not be working in the way I intended. As seen on this cygwin forum post:

The problem is that Cygwin's implementation of fifos is very buggy. I wouldn't recommend using fifos for anything but the simplest of applications.

I may need to find another way to do this. I have tried to pipe the ffmpeg output into a normal file and then have OpenCV read it at the same time. This works to some extent, but I imagine in can be dangerous to read and write from a file concurrently--who knows what would happen!

解决方案

hope it's not too late to answer, but I have tried the same thing some time ago, and here is how I did it.

The video-decoding backend for OpenCV is actually ffmpeg, so all its facitilites are available in OpenCV as well. Not all the interface is exposed, and that adds some difficulties, but you can send the rtp stream address to OpenCV.

cap.open("rtp://xxx.xxx.xxx.xxx:1234");

Important: OpenCV is not able to access password-protected rtp streams. To do that, you would need to provide the username and the password, there is no API exposed for it.

这篇关于流视频从ffmpeg和捕获与OpenCV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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