Giter Club home page Giter Club logo

Comments (12)

hipersayanX avatar hipersayanX commented on May 29, 2024

If this is your first time playing with the vcam, you should first learn how to use and manage it from the command line tool, all the setup and streaming is made from there. For the easy path:

Then learn how to compile and install it, the vcam won't never work unless you properly install and setup it.
Then just call the manager from C++ using ShellExecute, CreateProcess or similar functions, here is an example for streaming.
And all you need to know is explained in the wiki.

from akvirtualcamera.

hipersayanX avatar hipersayanX commented on May 29, 2024

???
Did you deleted the comment? can you post it again?

from akvirtualcamera.

KaiH-0 avatar KaiH-0 commented on May 29, 2024

from akvirtualcamera.

hipersayanX avatar hipersayanX commented on May 29, 2024

Oh, ok. Just in case remember that you can turn on debugging and trace in which part the error was throw.

from akvirtualcamera.

KaiH-0 avatar KaiH-0 commented on May 29, 2024

I managed to fix VirtualCamera not working in cmd but the problem now is, using your example of streaming has caused this error, this is a brand new project, just a copy and paste to test if it all works, The video output (AkVCamVideoDevice0) is the correct one as well. Not sure what is going wrong here.

Here is the error:
[build] E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\main.cpp(51,25): error C2734: 'cmd': 'const' object must be initialized if not 'extern' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
[build] E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\main.cpp(55,5): error C2664: 'int snprintf(char *const ,const size_t,const char *const ,...)': cannot convert argument 1 from 'const char [1024]' to 'char *const ' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
[build] E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\main.cpp(55,14): message : Conversion loses qualifiers [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
[build] E:\Windows Kits\10\Include\10.0.19041.0\ucrt\stdio.h(1919,37): message : see declaration of 'snprintf' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
[build] E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\main.cpp(68,76): error C2027: use of undefined type 'main::SECURITY_ATTRIBUTES' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
[build] E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\main.cpp(68): message : see declaration of 'main::SECURITY_ATTRIBUTES' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
[build] E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\main.cpp(69,74): error C2027: use of undefined type 'main::SECURITY_ATTRIBUTES' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
[build] E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\main.cpp(68): message : see declaration of 'main::SECURITY_ATTRIBUTES' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
[build] E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\main.cpp(80,25): error C2079: 'startupInfo' uses undefined struct 'main::STARTUPINFOA' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
[build] E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\main.cpp(81,55): error C2027: use of undefined type 'main::STARTUPINFOA' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
[build] E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\main.cpp(80): message : see declaration of 'main::STARTUPINFOA' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
[build] E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\main.cpp(82,48): error C2027: use of undefined type 'main::STARTUPINFOA' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
[build] E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\main.cpp(80): message : see declaration of 'main::STARTUPINFOA' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
[build] E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\main.cpp(87,32): error C2079: 'procInfo' uses undefined struct 'main::PROCESS_INFORMATION' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
[build] E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\main.cpp(88,59): error C2027: use of undefined type 'main::PROCESS_INFORMATION' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
[build] E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\main.cpp(87): message : see declaration of 'main::PROCESS_INFORMATION' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
[build] E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\main.cpp(91,5): error C2664: 'BOOL CreateProcessA(LPCSTR,LPSTR,LPSECURITY_ATTRIBUTES,LPSECURITY_ATTRIBUTES,BOOL,DWORD,LPVOID,LPCSTR,LPSTARTUPINFOA,LPPROCESS_INFORMATION)': cannot convert argument 2 from 'const char [1024]' to 'LPSTR' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
[build] E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\main.cpp(92,20): message : Conversion loses qualifiers [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
[build] E:\Windows Kits\10\Include\10.0.19041.0\um\processthreadsapi.h(361,1): message : see declaration of 'CreateProcessA' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
[build] E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\main.cpp(104,39): error C2440: 'initializing': cannot convert from 'void *' to 'char ' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
[build] E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\main.cpp(104,18): message : Conversion from 'void
' to pointer to non-'void' requires an explicit cast [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
[build] E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\main.cpp(107,11): error C3861: 'time': identifier not found [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
[build] Build finished with exit code 1

Also how would I input a opencv frame into the cam.

from akvirtualcamera.

hipersayanX avatar hipersayanX commented on May 29, 2024

But those errors are related to your own code, I can't help you with that.

Also how would I input a opencv frame into the cam.

As I said before

Then just call the manager from C++ using ShellExecute, CreateProcess or similar functions, here is an example for streaming.

from akvirtualcamera.

KaiH-0 avatar KaiH-0 commented on May 29, 2024

I made a whole new project and copy and paste the code from the example. All the code is from the example.

Here is a screenshot of the code:
https://s9.gifyu.com/images/image8295f6ea1f71609a.png

from akvirtualcamera.

hipersayanX avatar hipersayanX commented on May 29, 2024

Oh ok, I understand now, you did copied the example code to main.c, I thought that the codes was from your project. I've fixed the code, try again.

from akvirtualcamera.

KaiH-0 avatar KaiH-0 commented on May 29, 2024

Hi, I'm still getting some errors but a lot less:
'StreamProcess::pipeAttributes' uses undefined struct 'SECURITY_ATTRIBUTES' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
'StreamProcess::startupInfo' uses undefined struct 'STARTUPINFOA' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
'StreamProcess::procInfo' uses undefined struct 'PROCESS_INFORMATION' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
use of undefined type 'SECURITY_ATTRIBUTES' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
use of undefined type 'SECURITY_ATTRIBUTES' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
'BOOL CreatePipe(PHANDLE,PHANDLE,LPSECURITY_ATTRIBUTES,DWORD)': cannot convert argument 3 from 'int *' to 'LPSECURITY_ATTRIBUTES' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
'startupInfo' uses undefined struct 'STARTUPINFOA' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
use of undefined type 'STARTUPINFOA' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
'procInfo' uses undefined struct 'PROCESS_INFORMATION' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
use of undefined type 'PROCESS_INFORMATION' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
'BOOL CreateProcessA(LPCSTR,LPSTR,LPSECURITY_ATTRIBUTES,LPSECURITY_ATTRIBUTES,BOOL,DWORD,LPVOID,LPCSTR,LPSTARTUPINFOA,LPPROCESS_INFORMATION)': cannot convert argument 9 from 'int *' to 'LPSTARTUPINFOA' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
'initializing': cannot convert from 'void *' to 'char' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
'time': identifier not found [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
subscript requires array or pointer type [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
'BOOL WriteFile(HANDLE,LPCVOID,DWORD,LPDWORD,LPOVERLAPPED)': cannot convert argument 2 from 'char' to 'LPCVOID' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]
'void free(void *)': cannot convert argument 1 from 'char' to 'void *' [E:\Users\kaiha\OneDrive\Desktop\New folder - Copy\build\opencv.vcxproj]

from akvirtualcamera.

hipersayanX avatar hipersayanX commented on May 29, 2024

Dis you copied to code as-is? because SECURITY_ATTRIBUTES is defined in windows.h, you can check it in Microsoft's official documentation.

from akvirtualcamera.

KaiH-0 avatar KaiH-0 commented on May 29, 2024

Yeah I did, I'll take a look at the Microsoft documentation and managed to make it work, no more errors! But I'm not quite sure how I would put a opencv frame into it.

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <time.h>

/* For the sake of simplicity, the program won't print anything to the terminal,

  • or do any validation check, you are adviced the check every single value
  • returned by each function.
  • This program shows the very minimum code required to write frames to the
  • plugin.
    */

// We'll assume this is a valid akvcam output device.
#define VIDEO_OUTPUT "AkVCamVideoDevice0"

// Send frames for about 30 seconds in a 30 FPS stream.
#define FPS 30
#define DURATION_SECONDS 30
#define N_FRAMES (FPS * DURATION_SECONDS)

int main()
{
struct StreamProcess
{
HANDLE stdinReadPipe;
HANDLE stdinWritePipe;
SECURITY_ATTRIBUTES pipeAttributes;
STARTUPINFOA startupInfo;
PROCESS_INFORMATION procInfo;
};
typedef struct _SECURITY_ATTRIBUTES { // sa
DWORD nLength;
LPVOID lpSecurityDescriptor;
BOOL bInheritHandle;
} SECURITY_ATTRIBUTES;
// Set the parameters of the stream.
char cmd[1024];
const char format[] = "RGB24";
int width = 640;
int height = 480;
memset(cmd, 0, 1024);
snprintf(cmd,
1024,
"AkVCamManager stream %s %s %d %d",
VIDEO_OUTPUT,
format,
width,
height);

// Get the handles to the standard input and standard output.
struct StreamProcess streamProc;
memset(&streamProc, 0, sizeof(struct StreamProcess));
streamProc.stdinReadPipe = NULL;
streamProc.stdinWritePipe = NULL;
memset(&streamProc.pipeAttributes, 0, sizeof(SECURITY_ATTRIBUTES));
streamProc.pipeAttributes.nLength = sizeof(SECURITY_ATTRIBUTES);
streamProc.pipeAttributes.bInheritHandle = true;
streamProc.pipeAttributes.lpSecurityDescriptor = NULL;
CreatePipe(&streamProc.stdinReadPipe,
           &streamProc.stdinWritePipe,
           &streamProc.pipeAttributes,
           0);
SetHandleInformation(streamProc.stdinWritePipe,
                     HANDLE_FLAG_INHERIT,
                     0);

STARTUPINFOA startupInfo;
memset(&startupInfo, 0, sizeof(STARTUPINFOA));
startupInfo.cb = sizeof(STARTUPINFOA);
startupInfo.hStdInput = streamProc.stdinReadPipe;
startupInfo.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
startupInfo.wShowWindow = SW_HIDE;

PROCESS_INFORMATION procInfo;
memset(&procInfo, 0, sizeof(PROCESS_INFORMATION));

// Start the stream.
CreateProcessA(NULL,
               cmd,
               NULL,
               NULL,
               true,
               0,
               NULL,
               NULL,
               &startupInfo,
               &procInfo);

// Allocate the frame buffer.
size_t buffer_size = 3 * width;
char *buffer = (char*)malloc(buffer_size);

// Generate some random noise frames.
srand(time(0));

for (int i = 0; i < N_FRAMES; i++) {
    // Write the frame line by line.
    for (int y = 0; y < height; y++) {
        for (size_t byte = 0; byte < buffer_size; byte++)
            buffer[byte] = rand() & 0xff;

        // Write the frame data to the buffer.
        DWORD bytesWritten = 0;
        WriteFile(streamProc.stdinWritePipe,
                  buffer,
                  DWORD(buffer_size),
                  &bytesWritten,
                  NULL);
    }

    Sleep(1000 / FPS);
}

// Release the frame buffer.
free(buffer);

// Close the standard input and standard output handles.
CloseHandle(streamProc.stdinWritePipe);
CloseHandle(streamProc.stdinReadPipe);

// Stop the stream.
WaitForSingleObject(streamProc.procInfo.hProcess, INFINITE);
CloseHandle(streamProc.procInfo.hProcess);
CloseHandle(streamProc.procInfo.hThread);

return 0;

}

from akvirtualcamera.

hipersayanX avatar hipersayanX commented on May 29, 2024

Sorry for being late, I was busy with other things.

But I'm not quite sure how I would put a opencv frame into it.

There is a very long time since I've used OpenCV, so I don't remember how to work with frames, but you basically must read a 24 bits RGB frame (8 bits for red, 8 bits for green, and 8 bits for blue), from the top left corner to the bottom right corner of the picture, and you write it line by line using WriteFile.

from akvirtualcamera.

Related Issues (20)

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.