Virtual Webcam in C++ - c++

I want to write a new virtual webcam driver, which for example will take an AVI or live stream for example for screen and stream it as webcam source.
I'll not have webcam really, I want to add a virtual webcam which streams desktop screen.
I should write a webcam in kernel mode to do so ? If so, could you guide me to a sample webcam driver?
If I should do it in DirectShow, how can I add a webcam device to list in webcams list in Control panel, so for example in Yahoo messenger, I can choose that device as webcam and stream my desktop as webcam images.
How can I get started?

You need to write a DirectShow source filter. The Windows SDK contains a library called baseclasses which helps you developing such a filter. See CSourceStream for a good starting point.
To get the device to show up under the other Video Streaming Devices, you have to register your filter with the DirectShow API under the CLSID_VideoInputCategory. You don't need to/shouldn't write a kernel driver.

You can get start with the sample "amcap" under DirectShow package, it is a excellent sample for beginner. If you want to list webcam devices, go to ChooseDevices() method.

You would need to develop DirectShow Source Filter for creating Virtual camera, 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

Related

How to access USB camera through Qt c++ gui application

I am new to Qt GUI development. I have installed Qt GUI on windows platform. I need to setup a Qt C++ based GUI application to run connected USB camera. I tried to find out the related example but mostly based on webcam application. Is there any suggested example for accessing USB camera via Qt C++ GUI, I can go through?
There is no essential difference between "webcam" and "usb camera". A webcam is a video camera that feeds or streams an image or video in real time. This means that your USB camera can be a webcam if it supports such a function.
To accomplish your task, use the qt documentation and it's perfect examples, like this camera example.
Also, could be useful:
Recording Video from USB Cam with Qt5
Camera Overview

Hide camera device name from windows applications with MS Media Foundation?

Context
I am trying to build an image filter application where, the application will get the user's selected camera frames, apply some filters on the frames, create a virtual camera device and send the frame to that virtual camera. I am successful in doing all of these except I have to hide the actual camera device because it is being used by my application and other applications (suppose zoom/meet) should see my virtual camera instead of the actual camera device.
I have become able to create a virtual camera and send frames there with the help of obs-virtual-cam's obs-virtualsource.dll.
Desired Outcome
I need to create some kind of wrapper for device enumeration DLL from Microsoft. Once my wrapper is registered, it will modify the list of devices returning by the system to the applications. The settings can be saved in Registry and invoked in the context of other processes.
Answer I want
I am proficient at C/C++ but newbie in COM and MS Media Foundation API. So, even if the problem cannot be solved right here in the answer, I welcome and link or guidance to get started in the right direction to solve this specific problem.
Microsoft Media Foundation API does not offer you means to hide cameras for applications. Neither for application that use Media Foundation to access the cameras, nor specifically for applications that access cameras without Media Foundation.

Windows media foundation use raw image to encode video

I'm working on a project that requires me to record webcam, microphone, and the screen. I have webcam recording, audio is a work in progress, and I stumbled across CMonitor wrapper (which I did some minor modifications to) to grab RGB images of the desktop on a specified monitor (if there are multiple monitors).
How do I go about pushing my raw RGB frames into windows media foundation to encode into a video file? My current video encoding is using a slightly modified version of this msdn sample, if that's easier to modify than it is to write a new class handler.
Or, perhaps there is some sort of media foundation route to recording the screen that I don't know of (which is possible, I'm not that great of a win32 programmer)?
Found PushSource in the Windows SDK samples, which does this.
Check Desktop Duplication API for capture desktop. Media Foundation provides two solution for encoding, MF Sink Writer for simple encoding, Media Session for a more flexible control of the media pipeline. Read this overview page first.

C++ DirectShow Video and Audio capture - beginning

I have finally managed to drop working with VFW after several problems I have encountered during the application development.
Thanks to StackOverflow, I am now aware that VFW is obsolete and wish to switch to DShow, to let my application work with Vista/W7.
Unfortunately, the work has been made and application has been shipped to the client, but as soon as we realized we have troubles with frame rates on Vista / W7 - we decided to rewrite the video class and use DirectShow to establish a good audio/video capture engine for webcameras.
This will be tricky, as we never coded with DShow, and right now we are looking for few specific examples of how to:
Connect to a selected webcamera
similar to: capDriverConnect
Set camera resolution to 640x480 and RGB24 format ( we need to do RGB24 to YUV420 for each frame )
similar to: capSetVideoFormat / capCaptureSetSetup
Set audio capturing for this webcamera
similar to: capSetAudioFormat
Register two callbacks:
One for video frame ( we will pass frames to video encoder )
similar to: capSetCallbackOnVideoStream
One for wave buffer ( we will pass wave buffer to audio encoder )
similar to: capSetCallbackOnWaveStream
Be able to show a preview window somewhere on parent window
similar to: capPreview
Perform Start/Stop operation when needed
Start - would mean, connect and start capturing audio/video frames
Disconnect - would mean, stop capturing audio video frames
Perform drawing to the actual frame
similar to:
SetBitmapBits(CameraInput.GetFrameBitmap(),w*h*3,vdhdr->lpData);
// draw something with gdi+
GetBitmapBits(CameraInput.GetFrameBitmap(),w*h*3,vdhdr->lpData);//set back the frame with data
All of the above was already made with VFW, but as I wrote before we unfortunately need to switch do Direct Show.
Is there anyone who could help us out achieving a class that could rescue us from months of studying Direct Show ?
Your best bet for examples will be the ones from Microsoft.
Your questions are still phrased in terms of VFW so it's hard to answer them as written. For example, in DirectShow you wouldn't register a callback for to encode a video frame. Instead, you'd develop an encoder filter that would receive data from the capture source.
As an alternative, if you're only targeting Vista and later, there is the Microsoft Media Foundation. I have no experience with it so I don't know how the learning curve compares to DirectShow.
I'd suggest you to build a graph on GraphEdit using FFDshow filters.
EditGraph is making a demonstration of building a graph on DirectShow
I don't think you need you build the filter class by your own. After you'll build the graph and you'd be able to watch the video using GraphEdit. Implementing the graph is a very simple task.

simpest way to get audio/video data from directshow

I compiled the DirectShow sample player (from the Windows SDK's "Samples\multimedia\directshow\players\dshowplayer" folder).
Everything works well but it renders directly to the screen and the audio goes directly to directsound. I need to be able to grab the data and write out images to BMPs and write out the audio to .wav.
Am I using the wrong sample as a starting point? If not, what is the easiest way to modify the sample so I can get access to the video and audio data?
Thanks!
You can insert a SampleGrabber filter before the renderer, and use the ISampleGrabberCB Interface to access the data. You can still render the video to the screen, and output the audio. If you don't want that, use a NullRenderer instead. See also this example on codeproject.