Git Product home page Git Product logo

softcam's Introduction

Softcam

Build and Test CodeQL

This is a library to make a virtual webcam on Windows.

How it works

This software is a DLL which implements a DirectShow filter of Video Input Device category. Once it is installed to the system, any camera application which is using DirectShow API will recognize the filter as a camera-like device attached to the system. And thankfully many of camera applications running on Windows use DirectShow API to access camera devices.

This DLL provides Softcam Sender API too. Using this API, your application can create a virtual webcam instance and send arbitrary images as a video stream to the camera application.

Your code will look like this:

scCamera cam = scCreateCamera(320, 240, 60);
for (;;)
{
    uint8_t image[320 * 240 * 3];
    DrawSomething(image);
    scSendFrame(cam, image);
}

. Architecture

How to build the library

Following software is required.

  • Visual Studio 2022 (installed with Desktop development with C++ and Windows 10 SDK)

Open softcam.sln, choose the configuration Release and the platform x64, and build the solution.

If it successfully builds, you will get the DLL softcam.dll in the dist/bin/x64 directory. The header and the import libraries will also be put into the dist directory.

Note: The DLL softcam.dll built above is a 64-bit DLL file. In order to support 32-bit camera applications as well, you should build 32-bit softcam.dll too by choosing the platform Win32. The 32-bit DLL file will be put in the dist/bin/Win32 directory.

Note: You can use Visual Studio 2019 instead. The project files to use with Visual Studio 2019 have a name with the common suffix _vs2019. So your starting point is softcam_vs2019.sln.

Demo

There are two essential example programs in the examples directory. One is a demo (named sender) for simple usage of this library. The other is a program (named softcam_installer) for installation/uninstallation of this library to user's systems.

Before running the demo you need to install the library to your system so that camera applications can detect it. So you need to build and run both of the two examples. The steps are as follows.

  1. Open examples/softcam_installer/softcam_installer.sln, choose configuration Release and the platform x64, and build the solution.
    • You will get softcam_installer.exe in examples/softcam_installer/x64/Release directory.
  2. Then you register the DLL softcam.dll to your system by double-clicking the RegisterSoftcam.bat which is in the examples/softcam_installer directory.
    • This batch file simply launches softcam_installer.exe with the path of the DLL as a command line option.
    • This step, in other words installing this software, does not actually copy any files, instead, it writes the absolute path of the DLL on the registry using appropriate API.
    • Note since this process requires administrator permissions, softcam_installer.exe will request the permissions to the user through UAC.
    • Note: Again, in order to support 32-bit camera applications as well, you should build the 32-bit version of softcam_installer.exe too by choosing the platform Win32 in above step 1. And then run RegisterSoftcam32.bat as well to register the 32-bit DLL.
    • You can also unregister the DLL using UnregisterSoftcam.bat (and UnregisterSoftcam32.bat for 32-bit) in the same manner.
  3. Open examples/sender/sender.sln, choose configuration Release and platform x64 (or Win32 for 32-bit), and build the solution.
    • Then you get sender.exe in examples/sender/x64/Release (or examples/sender/Win32/Release) directory.
  4. Run sender.exe.
    • If it runs successfully, you will see a message 'Ok, Softcam is now active.' in the console. Now you've got a new virtual webcam running on your system.

To see the video stream which is being produced by the sender.exe, you can use any camera application. If you don't have a preference at this moment, I recommend you to try my web application Compare (https://tshino.github.io/compare/compare.html). This is an image comparison tool written in JavaScript, and it has the capability of taking a capture from a webcam. Open the above link, find the camera icon appears on the sidebar, and click it. If it shows a different camera image or fails to connect to the camera, you may need to look at the settings of your browser. In most browsers, a camera icon appears on the address bar, which is a shortcut to the camera settings. Make sure to let the browser use the virtual camera named 'DirectShow Softcam'. If it doesn't appear in the list of available cameras, try to reboot the browser (or Windows).

Note: To support both 32-bit and 64-bit camera applications, each of the DLL softcam.dll of both modes must be built and installed. Once both DLLs are installed in a system, no matter which one your application links to or which one the camera application accesses to, they can communicate and the images are streamed between them correctly.

Examples

Following examples are available:

  • sender
    • This is the demo app explained above. You should look at this one first.
  • softcam_installer
    • Installer/uninstaller implementation of this library.
  • python_binding
    • Python binding of this library.

License

MIT.

Note that the Base Classes library (in src/baseclasses directory) is a part of Microsft Windows Samples (Base Classes is in Samples/Win7Samples/multimedia/directshow/baseclasses directory) which is also provided under MIT license.

softcam's People

Contributors

dependabot[bot] avatar tshino avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

softcam's Issues

Add hardware ID into device info?

Heyy, wanted to ask, if it's possible to add HW camera ID into this camera. I mean that ID inside brackets.. As you can see, it's not part of camera name, but it's being printed with device.label

real_cam

Thanks in advance!

Issues with the 32 bit support

HI tsihon!

Great library, I have a project in unreal in which I integrated this library. The 64bit version works flawlessly, I can stream to Discord (from browser) or to Google Meet. But I've realized that the standalone version of discord is still 32bit, so I've tried to add support for as that well.

But it just doesn't work and I'm not sure why. I can see the virtual camera option in the discord camera combobox and I checked the registry for the COM object and the path is correct.
There might be some kind of race condition with the initialization, because sometimes 1 out of 10 it starts working if I attach my VS to both of my running instances and debug it step by step. (Unreal and Discord)

Do you have any idea what could go wrong? Because I have no issues with the 64bit version. And I could even manage to run the 32bit version, but only if I debug it in VS.

Default image when there is no input

Hi,

Is there a way to set a default image when the sender app is not open?

For example, this is what OBS default virtual camera placeholder image is:
image

Thanks for all your hard work.

Is it possible to set resolution for the output?

Is it possible to set resolution for the output?

I'd like to set aspect ratio manually, doesn't matter if I have to keep updating the registry until I get the one that suits me.

I'm having trouble getting my camera settings to run in Bluestacks as it is, so I'm going to try your dll solution wondering if their app is going to take the dll in.

Also, is this code capable of changing the Win10 native dll settings?

Thanks in advance and sorry if my questions are stupid.

Camera not recognized by Zoom

I got this to work locally via my chrome browser, but Zoom doesn't recognize my virtual camera. Any idea on how to fix?

Changing dll name that is searched for

I keep getting an error saying softcam.dll isn't found as I want to change the name of the dll.
I have installed the dll under a different name. It's just when I run the sender exe, it is looking for the wrong name.

Where is the piece of code to tell it to look for a different name, for example cam.dll

Thanks in advance.

could it add a convert function() which make input is a Mat format

could it add a convert function() which make input is a Mat format ?
a convert function() which make input is a Mat format as :

void Mat2DWimage( Mat matImage, vector &directShowImage )
{
int width = matImage.cols;
int height = matImage.rows;
int channels = matImage.channels();
std::vector directShowImage(width * height * 3);
if (matImage.isContinuous()) {
memcpy(directShowImage.data(), matImage.data, directShowImage.size());
} else {
// If the image is not stored continuously in memory, copy row by row
for (int row = 0; row < height; ++row) {
memcpy(&directShowImage[row * width * 3], matImage.ptr(row), width * 3);
}
}
}

VS2022 Build Error

Hi, I cloned main repo and latest release and tried to build them with VS2022 17.8.4.
I used Release x64 build type but I got these errors.

Desktop development environment with C++
.NET desktop development
Universal Windows Platform development

packages installed and I am using them with Unreal Engine without problem.

v1.7 Release Error

4>   Creating library E:\Github\C++\WebCam\softcam\x64\Release\softcam.lib and object E:\Github\C++\WebCam\softcam\x64\Release\softcam.exp
4>softcam.vcxproj -> E:\Github\C++\WebCam\softcam\x64\Release\softcam.dll
3>core_tests.vcxproj -> E:\Github\C++\WebCam\softcam\x64\Release\core_tests.exe
4>Creating dist directory and copying the header and binaries into it.
4>softcam.h -> ...dist\include\softcam\
4>The system cannot find the file specified.
4>softcam.lib -> ...dist\lib\x64\
4>The system cannot find the file specified.
4>softcam.dll -> ...dist\bin\x64\
4>The system cannot find the file specified.
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: The command "@if not exist E:\Github\C++\WebCam\softcam\dist mkdir E:\Github\C++\WebCam\softcam\dist
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: @if not exist E:\Github\C++\WebCam\softcam\dist\include mkdir E:\Github\C++\WebCam\softcam\dist\include
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: @if not exist E:\Github\C++\WebCam\softcam\dist\include\softcam mkdir E:\Github\C++\WebCam\softcam\dist\include\softcam
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: @if not exist E:\Github\C++\WebCam\softcam\dist\lib mkdir E:\Github\C++\WebCam\softcam\dist\lib
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: @if not exist E:\Github\C++\WebCam\softcam\dist\lib\x64 mkdir E:\Github\C++\WebCam\softcam\dist\lib\x64
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: @if not exist E:\Github\C++\WebCam\softcam\dist\bin mkdir E:\Github\C++\WebCam\softcam\dist\bin
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: @if not exist E:\Github\C++\WebCam\softcam\dist\bin\x64 mkdir E:\Github\C++\WebCam\softcam\dist\bin\x64
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: @echo softcam.h -^> ...dist\include\softcam\
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: @copy /y E:\Github\C++\WebCam\softcam\src\softcam\softcam.h E:\Github\C++\WebCam\softcam\dist\include\softcam
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: @echo softcam.lib -^> ...dist\lib\x64\
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: @copy /y E:\Github\C++\WebCam\softcam\x64\Release\softcam.lib E:\Github\C++\WebCam\softcam\dist\lib\x64
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: @echo softcam.dll -^> ...dist\bin\x64\
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: @copy /y E:\Github\C++\WebCam\softcam\x64\Release\softcam.dll E:\Github\C++\WebCam\softcam\dist\bin\x64
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: 
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: :VCEnd" exited with code 1.
4>Done building project "softcam.vcxproj" -- FAILED.
5>------ Build started: Project: dll_tests, Configuration: Release x64 ------
5>raw_api_test.cpp
5>dll_tests.vcxproj -> E:\Github\C++\WebCam\softcam\x64\Release\dll_tests.exe
========== Build: 4 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Main Errors:

4>The system cannot find the file specified.
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: The command "@if not exist E:\Github\C++\WebCam\softcam\dist mkdir E:\Github\C++\WebCam\softcam\dist
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: @if not exist E:\Github\C++\WebCam\softcam\dist\include mkdir E:\Github\C++\WebCam\softcam\dist\include
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: @if not exist E:\Github\C++\WebCam\softcam\dist\include\softcam mkdir E:\Github\C++\WebCam\softcam\dist\include\softcam
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: @if not exist E:\Github\C++\WebCam\softcam\dist\lib mkdir E:\Github\C++\WebCam\softcam\dist\lib
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: @if not exist E:\Github\C++\WebCam\softcam\dist\lib\x64 mkdir E:\Github\C++\WebCam\softcam\dist\lib\x64
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: @if not exist E:\Github\C++\WebCam\softcam\dist\bin mkdir E:\Github\C++\WebCam\softcam\dist\bin
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: @if not exist E:\Github\C++\WebCam\softcam\dist\bin\x64 mkdir E:\Github\C++\WebCam\softcam\dist\bin\x64
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: @echo softcam.h -^> ...dist\include\softcam\
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: @copy /y E:\Github\C++\WebCam\softcam\src\softcam\softcam.h E:\Github\C++\WebCam\softcam\dist\include\softcam
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: @echo softcam.lib -^> ...dist\lib\x64\
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: @copy /y E:\Github\C++\WebCam\softcam\x64\Release\softcam.lib E:\Github\C++\WebCam\softcam\dist\lib\x64
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: @echo softcam.dll -^> ...dist\bin\x64\
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: @copy /y E:\Github\C++\WebCam\softcam\x64\Release\softcam.dll E:\Github\C++\WebCam\softcam\dist\bin\x64
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: 
4>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(166,5): error MSB3073: :VCEnd" exited with code 1.
4>Done building project "softcam.vcxproj" -- FAILED.
5>------ Build started: Project: dll_tests, Configuration: Release x64 ------
5>raw_api_test.cpp
5>dll_tests.vcxproj -> E:\Github\C++\WebCam\softcam\x64\Release\dll_tests.exe
========== Build: 4 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Image colors are not correct

Hi, I tried loading an image in Python and sending it.

It works, but the image appears very blue.

Here is my code:

from PIL import Image
from x64.Release import softcam

def main():
    dt = 1/60
    cam = softcam.camera(1920, 1280, 60)
    image = Image.open('./test.jpg')
    image = image.convert('RGB')

    # Here, you can wait for an application to connect to this camera.
    while not cam.wait_for_connection(timeout=1):
        pass

    while True:
        # send the image
        cam.send_frame(image)


if __name__ == '__main__':
    main()

Original image:
https://images.unsplash.com/photo-1542500186-6edb30855637?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1740&q=80

What shows up in Zoom (virtual camera):
https://i.imgur.com/3ljVlsU.jpg

Any idea why? Is it related to the color table of the image? I tried converting to RGB, not sure what else I should do.

Thanks

Different Video Formats?

Hello. I understand that currently you can only use BGR24 format. It would be great if you could expand to ABGR32 (or a different layout) and or any YUV format. Other than that, it's a great wrapper.

Edit: Is it possible to choose between Progressive and Interlaced?

Add 32-bit support

Thanks to issue #2 and the nice reporter, now it is clear that to build 32-bit softcam.dll is required to support 32-bit camera applications.

  • Adding 32-bit configurations to all projects and solutions is a relatively easy task.
  • Study/investigating and design are required for the following issues:
    • Naming of DLL and LIB. Good practice? Adding '32' suffix?
    • dist directory layout.
    • Installing process. Require running the installer once for each mode?
    • Class ID/name. Should they be different?
    • Use cases with a mix of 32-bit and 64-bit for the DLL and app. Is it possible? Does it work properly?

Mac version? Example problem

Hi, I have tried this project and it was so simple to setup! This is an amazing project, I am currently making an application that will be used by a few of my colleagues, one of them has a Mac, I was wondering whether there will ever be a plugin version of this, also could you give me an example on making it use an image for the camera as I am going to use OpenCV with it.

Add audio pin?

Any plans to support audio? If not, any hints on where I should get started to try to implement it myself?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.