4

I would like to emulate video input from a webcam for testing purposes.

So I need to be able to emulate a software video capture device in Windows and be able to dynamically generate its output.

How can I achieve this?

I would prefer a solution in C# or C++.

GEOCHET
  • 21,119
  • 15
  • 74
  • 98
Kamil Zadora
  • 2,367
  • 6
  • 34
  • 43

3 Answers3

3

You can use a Virtual Webcam (old link, but there are others) it will take a video/images file and will display it in a webcam device. Your system will think that its a normal device.

Then you will need to create something that will generate the video/images, if you need static image then its pretty easy to generate a bmp.

Shay Erlichmen
  • 31,691
  • 7
  • 68
  • 87
  • He said dynamic not live, I imagine that in dynamic you have some model that you want to visualize at runtime but not necessarily in real time. – Shay Erlichmen May 27 '09 at 18:43
2

Old (no selected answer) question.... actually probably one of the oldest I've ever seen... but I came across this looking for an answer myself, I remembered the day when "Virtual Webcam" still existed (now just a chinese ad site).

Fear not! There are new sources to solve your decade long quest: First of all, checkout OBS, open source does a LOT with video streams:

Second, checkout this virtual webcam plugin for it. Does exactly what you're talking about, and does use @qbeuek's suggestion of DirectDraw:

It is written in C++, so grabbing the bits you need and rewriting to C# is left as an exercise to the reader, but the capability is there.

CenterOrbit
  • 6,446
  • 1
  • 28
  • 34
  • Very cool! Would you happen to know if there is a way to turn on audio on the virtual cam? Video is working but audio maybe not part of the scope? – Miguel Sep 12 '20 at 01:28
  • Sorry @Miguel, I've never actually used the code from it, just the final product. OBS does have many audio capture capabilities though, so take a look at what it is able to accomplish outside of that plugin. – CenterOrbit Sep 12 '20 at 18:14
0

As far as I know, there is a set of COM interfaces that govern the recording and playback of audio and video in Windows. It used to be called DirectShow, but maybe in the meantime the name has been changed. Those interfaces are used to construct a graph of audio and video filters, to encode / decode the data stream.

The way to go: - read about the Microsoft DirectShow API, - implement a COM object that implements the video source interface,

qbeuek
  • 4,156
  • 4
  • 19
  • 17