ldenoue / cameraextension

sample camera extension using coremedia io
MIT License
63 stars 11 forks source link

Can I use cameraextension with C++? #1

Closed halill1 closed 1 year ago

halill1 commented 1 year ago

Hi,

From my understanding cameraextension , as its name suggests, is the one that handles low level stuff and I don't need to make changes on this part. My problem is I simply want to read a video frame by frame and push them to virtual camera. However, I need to do this because in C++ because I will do some operations on the frame and my framework is written in C++. I have a few questions, just to confirm:

1) Does cameraextension creates a virtual camera such as width, height, format etc. and has nothing to do with client side(zoom etc). It just creates a virtual camera and sends the incoming frame to whatever app wants at that moment.

2) The way you push the frame to virtual camera from samplecamera. Should I call enqueue function for each frame? Assume I successfully converted the code in C++ read frames from hardware camera, then after reading and operation I will call enqueue function with my result frame and it will call virtual camera and frame will be shown on the screen, cycle completed. Am I right?

3) I had tried several virtual cameras, the problem was they are too slow. Writing one frame takes 500ms so around 2FPS, which is terrible. Have you made any test to estimate performance..

Thanks a lot! Halil

ldenoue commented 1 year ago

Hi @halilkarab The performance is good (I use this exact code for my macOS app Screegle)

  1. yes the camera extension can be called to create a virtual camera. at the moment these parameters are fixed in Config
  2. in your main code (not the extension), you create the virtual camera, see here
  3. you then connect to this camera using code from connectToCamera
  4. In that code you'll see initSink called. This is where we create the sink queue, used by our main code to enqueue the frames.
  5. In the same code, a timer fires at 30 FPS to enqueue frames. Notice that it checks the readyToEnqueue flag because we don't want to enqueue too many frames. This logic could probably be changed since more than one frame could potentially be enqueued.

Hope this helps.

halill1 commented 1 year ago

Thanks a lot! Also do you think that can camerasample example be written in C++? I think that I don't need to convert cameraextension itself to C++, but will I be able to communicate with the virtual camera from C++?

ldenoue commented 1 year ago

I believe so because the Swift version uses the low level APIs to access the camera sink anyway.

halill1 commented 1 year ago

okey. i almost done it, the only problem is how should i deactivate all the virtual cameras? for example now i have 1 activaetd camera and 1 physical usb cam, but it seems i have 3 cameras on the extension. (my computer crashed during a test and i couldnt deactivate it had to turn off by pressing power button)

ldenoue commented 1 year ago

Hi! You might need to reset your virtual cameras following these steps https://gist.github.com/ldenoue/ec4f1b5d2196835ba89de2020fd4ed7a

halill1 commented 1 year ago

Thanks!