Windows 10上基于Microsoft DirectShow的虚拟网络摄像头应用程序的项目和构建结构 [英] Project and build structure for Microsoft DirectShow based virtual webcam application on Window 10

查看:138
本文介绍了Windows 10上基于Microsoft DirectShow的虚拟网络摄像头应用程序的项目和构建结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建最简单的虚拟网络摄像头应用程序,该应用程序可以在本地文件系统上显示图像文件.

在对 stackoverflow链接进行初步研究后,看到了 Microsoft DirectShow .

  • 我需要使用 .dll文件,则需要使用 regsvr32.exe
    注册如 https://docs.microsoft.com/en-us/windows/win32/directshow/building-directshow-filters

  • 我需要创建过滤器图解决方案

  • 我想创建最简单的虚拟网络摄像头应用程序,该应用程序可以将任何图像或视频输出到虚拟照相机.该虚拟摄像机应在Google Meeting或zoom等在线会议中作为视频设备可见.

    在Windows中,不存在将虚拟网络摄像机作为统一API的支持,并且通常来说,您要实现的目标是实现,但要比设置问题复杂得多.

    任务可以分解为三个部分,您将能够找到过去阐述了所有三个问题的StackOverflow问题(以下提供了一些参考).

    首先,您需要解决将虚拟摄像机集成到第三方软件中的问题.根据我开始的陈述,就OS扩展点而言,OS API没有提供通用虚拟摄像机接口的方法,该接口使第三方应用参见".新的摄像头设备.

    将伪造的相机设备注入应用程序的一种流行方法是虚拟DirectShow视频源(分别是将网络视频流注册为虚拟摄像机的图描述了应用程序用于与摄像机和说明了虚拟DirectShow摄像机的局限性,特别是为什么Windows中每个启用视频的应用程序都看不到它们的原因.

    另请参阅问题浏览器无法识别虚拟驱动程序凸轮如何实现源过滤器"要基于Vivek的vcam分割摄像机视频?,然后读取USB摄像机的输入编辑并将输出发送到虚拟摄像机Windows 如何创建Directshow过滤器?.

    总而言之,这不是项目设置的问题.相反,这是一组需要解决的非常复杂的问题(尽管这是可行的,我们看到了这样的示例).

    I am trying to create simplest virtual webcam application which can display image file on my local filesystem.

    After initial research on stackoverflow links and seeing OBS Studio source code I got some idea how can I achieve this.

    1. I would need to use Microsoft DirectShow.

    2. I would need to develop one source filter that would work as capture filter using IBaseFilter

    3. I would need to develop another source filter that would work as output filter or virtual webcam filter. I would need to compile this filter as .dll file and will need to register using regsvr32.exe
      As given on https://docs.microsoft.com/en-us/windows/win32/directshow/building-directshow-filters

    4. I would need to create Filter Graph and Capture Filter Graph using CoCreateInstance like

      hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IFilterGraph, (void **)&graph);

      hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2, (void **)&builder);

    5. Then I would need to add these filters to Filter Graph

    6. Then I would set Filter Graph to Capture Filter Graph like hr = builder->SetFiltergraph(graph);

    Here is my confusion now:
    After these steps I am not sure if I have to wrap these Graph Filters and Capture Graph Filter in one application which would be having main method and compile it to get .exe file or I need to compile as another .dll file.

    Or How should I wrap these steps to create final application?

    解决方案

    I want to create simplest virtual webcam application which can output any image or video to virtual camera. That virtual camera should be visible as video device in online meetings like Google meet or zoom.

    There is no support for virtual web cameras in Windows as a unified API and what you are trying to achieve is, generally speaking, possible but far more complicated than a question of setup.

    The task can be decomposed into three parts, and you will be able to find past StackOverflow questions that elaborate all of the three (some references are given below).

    First, you need to resolve the problem of integration of a virtual camera into third party software. Per the statement I started from, the OS API offers no way for a generic virtual camera interface in terms of OS extensibility point that enables third party application "see" a new camera device.

    A popular way to inject a fake camera device into applications is virtual DirectShow video source (and respectively Vivek's VCam source code).

    The diagram from Registering a network video stream as a virtual camera describes the APIs used by applications to work with cameras and illustrates limitations of virtual DirectShow cameras, specifically why they are not visible by every video-enabled application in Windows.

    See also questions Virtual Driver Cam not recognized by browser and DirectShow filter is not shown as input capture device.

    All in all, to develop a virtual webcam for all and any application in Windows you would need to develop a driver, something few are ready to deal with.

    Newer Media Foundation API offers nothing to help with functionality of virtual webcam.

    Second, you need to define a method of injection of video frames into whatever virtual camera you develop. There is no need to use DirectShow or Media Foundation because in the end of the day all you need is to submit video frames to the back end of your virtual camera implementation and you are free to use any convenient method.

    Use of DirectShow for this task make sense overall, but you don't need to. If you are not familiar with the API and you are starting with basics of creation of a filter graph, then it is quite likely that it is easier to go with a non-DirectShow solution. If you need to mix a real webcam image into your feed, you can capture it with Media Foundation in particular. If you plan to use GPU services of sorts, Media Foundation would be a better API to use again. DirectShow still remains good option as API to build your pipeline on.

    Third, there is often a question of interprocess communication to connect the virtual camera implementation and the source of the video. In some cases it is not necessary, but more often it is just overlooked.

    A virtual DirectShow camera (or virtual Media Foundation camera if you, for example, will be detouring) is running in context of camera consuming process, and cameras in general might be accessed from multiple applications including simultaneously. Quite so often you expect to produce video from another [single] application, including the case of application of unlatching bitness/architecture, so you are to take care of the challenge of passing data between the processes. If you are in an attempt to develop a driver for virtual camera you will have the same task too.

    I mentioned aspects of this in MSDN question there: How to implement a "source filter" for splitting camera video based on Vivek's vcam?, then there Read USB camera's input edit and send the output to a virtual camera on Windows and also there How to create Directshow filter?.

    All in all, it is not a question of project setup. Instead, it is a set of quite sophisticated problems to solve (which are doable though, and we see examples of this).

    这篇关于Windows 10上基于Microsoft DirectShow的虚拟网络摄像头应用程序的项目和构建结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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