Building a virtual camera for OS X

2020-05-27 07:35发布

问题:

I need to get a synthetic generated video stream in a program like skype. The audio part is easy. There is a project called Soundflower which is an adapter. It presents a virtual audio destination device on the one side and a video source on the other side. I am searching for the same solution for OSX. Except I only need the part how to present it as a virtual camera. Do not misunderstood, I do not need a "ready to use" tool, I need the way how to develop it. So a ready to use tool is only helpful with the source code.

In the Windows world, where I came from, I already programmed such a Virtual Camera using DirectShow. Now I am searching for a similar solution in the OSX world.

回答1:

This depends to some extent on the application with which you wish to interface. If it is an old-school QuickTime app (32-bit, 10.8 or earlier), you would need to write a QuickTime vdig (video digitiser) component. This is basically a plugin that provides a certain interface that can be dynamically enumerated and invoked by any QT-compatible app. However, this is all now deprecated (as of 10.9)!

The modern approach is to use the Core Media I/O Framework. Unfortunately, it isn't as thoroughly documented as most of the other frameworks, as it is used by only a fraction of the developer base (who need to create hardware interfaces).

There's an SDK project available, which contains the CoreMedia framework plus some example code:

  • ADC CoreMediaIO SDK

Take a look specifically at IOVideoSampleDevice.

You probably won't need a kext (kernel extension) as you won't be interfacing with real hardware. So hopefully you will just be able to get by with implementing the required CMIO interfaces and registering your device type.

There's a great book available which covers driver development for OS X and iOS:

  • OS X and iOS Kernel Programming

(Disclaimer: the authors are colleges and friends of mine.)

QuickTime used to be the DirectShow equivalent. Now, CoreMedia and friends have superseded it, with a far more modern and flexible API.