21

I need to create a virtual webcam that poses as a webcam, but takes as input a set of images that it plays. I have seen solutions like ManyCam, and Fake Webcam, but they all seem to one limitation or the other (resolution, max file size, fps etc.) I am working on Windows XP SP3.

I understand that I have to write a WIA interface for this task, but being a Python programmer, I have never written drivers or interfaces to devices. What are the main tasks in writing this interface ? What would the flow look like ?

4
  • 6
    unrelated advice: "don't say that you are a Python programmer", you're a programmer that prefers (or only knows) Python... yet.
    – Javier
    Commented Jun 5, 2011 at 15:47
  • 1
    May be s/he's a core developer of cpython... :-)
    – 6502
    Commented Jun 5, 2011 at 17:02
  • @Javier great advice ! though it may be more of a cultural thing. @6502 just thinking about that made me go crazy. if I were a developer of cpython, wouldn't I be a C programmer? or I could be a python programmer because I program python
    – aloogobi
    Commented Jun 7, 2011 at 12:12
  • See also stackoverflow.com/questions/4214786/…
    – rogerdpack
    Commented May 27, 2016 at 11:59

2 Answers 2

27

You need to write DirectShow filter which is a COM server that implements an IPin, IAMStreamConfig and IKsPropertySet interfaces. For the IPin part you'd better to start by inheriting the CSourceStream class, for that you need to get the Windows SDK, having the SDK installed there would be a DirectShow Base Classes sources in samples\multimedia\directshow folder, there you'll find the CSourceStream (among many others). DllRegisterServer function of the COM server should register your filter within CLSID_VideoInputDeviceCategory category using filter mapper.

After building the COM-server, you register it with regsvr32 tool, and your virtual webcam should appear in the web cam lists.

Also check the samples\multimedia\directshow\filters\ball sample that can be improved and used as a starting point for your task.

3
  • Thanks you very much for detailing the flow. I will look at the samples and learn. Thanks again :)
    – aloogobi
    Commented Jun 7, 2011 at 12:13
  • @n0rd please help in stackoverflow.com/questions/65839449/…
    – Alok
    Commented Jan 23, 2021 at 11:26
  • Thanks @n0rd. I know this question/answer is old, but would you have a minimal example of such code? Ideally it would be a single .c or .cpp file :) PS: does the solution you describe create a virtual webcam, that can be used as a webcam in the browser?
    – Basj
    Commented Oct 6, 2022 at 10:00
1

Read this first
https://learn.microsoft.com/en-us/windows/win32/directshow/writing-source-filters

Then you can adopt
https://github.com/roman380/tmhare.mvps.org-vcam

You can work on top of this sample virtual camera.

This implements IAMStreamConfig and IKsPropertySet interfaces
This is built using CSourceStream and CSource class which implements IPin and IBaseFilter

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.