如何将视频流到虚拟相机

发布于 2025-01-19 00:08:51 字数 1871 浏览 1 评论 0原文

我查了一些资料,似乎可以使用 DirectShow VCam 构建虚拟相机

但请原谅我的无知,我完全不知道如何在我的项目中使用它。

具体来说,我的C++程序使用opencv捕获来自相机的输入,然后对输入进行一些处理。我希望处理后的视频流“输出到虚拟摄像机”。 我不确定这个描述是否准确。无论如何,我希望其他应用程序(例如从相机获取输入的缩放)选择虚拟摄像头作为输入来获取我处理过的视频流。

我可以使用 DirectShow VCam 执行此操作吗?又如何呢?

我是初学者,我的母语不是英语。所以我不确定我的表述是否清楚。请给我一些回复,谢谢!

目前的情况

我发现 这个问题 和我的一模一样,但还没有收到任何评论。

vcam 项目 有一个 <填充数据的 code>fillbuffer() 方法:

//////////////////////////////////////////////////////////////////////////
//  This is the routine where we create the data being output by the Virtual
//  Camera device.
//////////////////////////////////////////////////////////////////////////
HRESULT CVCamStream::FillBuffer(IMediaSample *pms)
{
    REFERENCE_TIME rtNow;
    
    REFERENCE_TIME avgFrameTime = ((VIDEOINFOHEADER*)m_mt.pbFormat)->AvgTimePerFrame;

    rtNow = m_rtLastTime;
    m_rtLastTime += avgFrameTime;
    pms->SetTime(&rtNow, &m_rtLastTime);
    pms->SetSyncPoint(TRUE);

    BYTE *pData;
    long lDataLen;
    pms->GetPointer(&pData);
    lDataLen = pms->GetSize();
    for(int i = 0; i < lDataLen; ++i)
        pData[i] = rand();

    return NOERROR;
} // FillBuffer

这里用随机数 pData[i]=rand() 填充缓冲区。那么如果我用我的图像数据来填充,是否可以达到我想要的效果呢?但是

  • 如何确定缓冲区的大小和图像的大小匹配呢?
  • 如果我想不断更新每一帧的数据怎么办?
  • ...

另外,我尝试用常量 pData[i]=255 填充缓冲区,它确实有效。当我使用虚拟摄像头进行变焦时,它全是白色的。但它导致缩放过程冻结并且CPU和GPU满载。我不知道为什么。

I looked up some sources and it seems that it is possible to build a virtual camera using DirectShow VCam.

But please forgive my ignorance, I have absolutely no idea how to use it in my project.

Specifically, my C++ program uses opencv to capture input from the camera, and then does some processing on the input. I want the processed video stream to be "output to a virtual camera".
I'm not sure if this description is accurate. Anyway, I want other apps (such as zoom that get input from the camera) to select the Virtual Cam as input to get my processed video stream.

Can I do this with DirectShow VCam? And how?

I am a beginner and my native language is not English. So I'm not sure if my formulation is clear. Please give me some replies, thanks!

Current situation

I found this question is exactly the same as mine, but haven't gotten any comments yet.

The vcam project has a fillbuffer() method from where the data is filled:

//////////////////////////////////////////////////////////////////////////
//  This is the routine where we create the data being output by the Virtual
//  Camera device.
//////////////////////////////////////////////////////////////////////////
HRESULT CVCamStream::FillBuffer(IMediaSample *pms)
{
    REFERENCE_TIME rtNow;
    
    REFERENCE_TIME avgFrameTime = ((VIDEOINFOHEADER*)m_mt.pbFormat)->AvgTimePerFrame;

    rtNow = m_rtLastTime;
    m_rtLastTime += avgFrameTime;
    pms->SetTime(&rtNow, &m_rtLastTime);
    pms->SetSyncPoint(TRUE);

    BYTE *pData;
    long lDataLen;
    pms->GetPointer(&pData);
    lDataLen = pms->GetSize();
    for(int i = 0; i < lDataLen; ++i)
        pData[i] = rand();

    return NOERROR;
} // FillBuffer

Here it fills the buffer with random numbers pData[i]=rand(). So if I use my image data to fill, can I achieve what I want? but

  • How can I determine that the size of the buffer and the size of the image match?
  • What can I do if I want to keep updating the data of each frame?
  • ...

Also, I tried filling the buffer with a constant pData[i]=255 and it did work. When I use the Virtual Cam on zoom it's all white. But it caused the zoom process to freeze and the CPU and GPU to be fully loaded. I do not know why.

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

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

发布评论

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

评论(1

迷迭香的记忆 2025-01-26 00:08:51

微软的“PowerToys for Windows”具有用于视频会议的“视频静音”功能。它就是这么做的。它创建一个“虚拟摄像头”设备,并将视频从实际摄像头设备路由到“虚拟摄像头” - 除非用户使用系统范围的热键来“静音”视频源。

这听起来正是您想要做的。因此,您可能想查看“PowerToys”github 存储库: https://github.com/microsoft/动力玩具

Microsofts "PowerToys for Windows" has a "Video Mute" for video conferencing. It does just that. It creates a "virtual camera" device and routes video from the actual camera device to the "virtual camera" - unless the user uses a system-wide hotkey to "mute" the video feed.

This sounds exactly what you want to do. So you might want to have a look at the "PowerToys" github repository: https://github.com/microsoft/PowerToys

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文