如何使用 OpenCV C API 捕获 ffmpeg 流?

发布于 2025-01-13 19:43:36 字数 666 浏览 1 评论 0原文

我想从 OpenCV C API 读取 ffmpeg 流。

我想要捕获的流媒体是使用 ffmpeg -f avfoundation -i "1" -pix_fmt uyvy422 -f mpegts udp://192.168.1.110:5000 生成的

我尝试使用以下代码读取流

#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <opencv2/videoio/videoio_c.h> //C API VideoCapture()

CvCapture* cap = cvCreateFileCaptureWithPreference("udp://192.168.1.110:5000", CV_CAP_FFMPEG);

cvGrabFrame(stream->cap);
IplImage* frame = cvRetrieveFrame(stream->cap, 0);

问题是框​​架被设置为NULL并且实际上没有检索到任何内容。

使用C++ API 会很简单,但我无法在我的项目中使用它,我需要C API。

关于如何实施这个有什么想法吗?

I would like to read an ffmpeg stream from OpenCV C API.

The streamer I want to catch is generate using ffmpeg -f avfoundation -i "1" -pix_fmt uyvy422 -f mpegts udp://192.168.1.110:5000

I try to read the stream with the following code

#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <opencv2/videoio/videoio_c.h> //C API VideoCapture()

CvCapture* cap = cvCreateFileCaptureWithPreference("udp://192.168.1.110:5000", CV_CAP_FFMPEG);

cvGrabFrame(stream->cap);
IplImage* frame = cvRetrieveFrame(stream->cap, 0);

The problem is that frame is set to NULL and nothing is actually retrieved.

It will be straightforward using C++ API, but I cannot use it in my project, I need the C API.

Any idea on how to implement this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文