如何在 c++ 中获取网络摄像头视频流字节

发布于 2024-09-05 05:14:04 字数 206 浏览 7 评论 0原文

我的目标是 Windows 机器。我需要访问指向描述来自附加 USB 网络摄像头的各个流帧的字节数组的指针。我从 Windows sdk 中看到了 playcap directshow 示例,但我不知道如何获取原始数据,坦率地说,我不明白视频实际上是如何到达窗口的。因为除了视频捕获之外我不需要任何东西,所以我不想使用 opencv。

Visual Studio 2008 C++

I am targeting windows machines. I need to get access to the pointer to the byte array describing the individual streaming frames from an attached usb webcam. I saw the playcap directshow sample from the windows sdk, but I dont see how to get to raw data, frankly, I don't understand how the video actually gets to the window. Since I don't really need anything other than the video capture I would prefer not to use opencv.

Visual Studio 2008 c++

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黄昏下泛黄的笔记 2024-09-12 05:14:05

插入样品采集过滤器。将相机源连接到样本采集器,然后连接到空渲染器。样本采集器是一个转换,因此您需要将输出提供给某个地方,但如果您不需要渲染它,则空渲染器是一个不错的选择。

您可以使用 ISampleGrabber 配置样本采集器。您可以为每个帧安排对应用程序的回调,为您提供指向位本身的指针,或指向 IMediaSample 对象的指针,该对象也将为您提供元数据。

你需要在你的对象上实现ISampleGrabberCB,然后你需要这样的东西(伪代码)

IFilterInfoPtr      m_pFilterInfo;
ISampleGrabberPtr   m_pGrabber;

m_pGrabber = pFilter;

m_pGrabber->SetBufferSamples(false);
m_pGrabber->SetOneShot(false);

// force to 24-bit mode
AM_MEDIA_TYPE mt;
ZeroMemory(&mt, sizeof(mt));
mt.majortype = MEDIATYPE_Video;
mt.subtype = MEDIASUBTYPE_RGB24;
m_pGrabber->SetMediaType(&mt);

m_pGrabber->SetCallback(this, 0);
// SetCallback increments a refcount on ourselves,
// but we own the grabber so this is recursive
/// -- must addref before SetCallback(NULL)
Release();

Insert the sample grabber filter. Connect the camera source to the sample grabber and then to the null renderer. The sample grabber is a transform, so you need to feed the output somewhere, but if you don't need to render it, the null renderer is a good choice.

You can configure the sample grabber using ISampleGrabber. You can arrange a callback to your app for each frame, giving you either a pointer to the bits themselves, or a pointer to the IMediaSample object which will also give you the metadata.

You need to implement ISampleGrabberCB on your object, and then you need something like this (pseudo code)

IFilterInfoPtr      m_pFilterInfo;
ISampleGrabberPtr   m_pGrabber;

m_pGrabber = pFilter;

m_pGrabber->SetBufferSamples(false);
m_pGrabber->SetOneShot(false);

// force to 24-bit mode
AM_MEDIA_TYPE mt;
ZeroMemory(&mt, sizeof(mt));
mt.majortype = MEDIATYPE_Video;
mt.subtype = MEDIASUBTYPE_RGB24;
m_pGrabber->SetMediaType(&mt);

m_pGrabber->SetCallback(this, 0);
// SetCallback increments a refcount on ourselves,
// but we own the grabber so this is recursive
/// -- must addref before SetCallback(NULL)
Release();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文