AVCaptureScreenInput and kCGWindowListOptionOnScreenBelowWindow

I am doing screen capture using AVCaptureScreenInput. The application has a window with configuration parameters.

I want to record a screen but not record a window in the recorder application. Quicktime does this if you are recording on the screen as an example.

I think I found that this will do, but I'm not sure how or if they can be used together.

kCGWindowListOptionOnScreenBelowWindow is located in CGWindow.h in the Core Graphics structure. AVCaptureScreenInput is part of AVCaptureInput.h in the AVFoundation structure.

If you take a single screenshot, you can pass kCGWindowListOptionOnScreenBelowWindow and windowID so that only windows below this window level are captured. I can accomplish my task by setting the capture application window to a very high level if this works.

I'm relatively new to Objective-c, and its not clear if you can use kCGWindowListOptionOnScreenBelowWindow with AVCaptureScreenInput. If so, can someone give some advice on how the code should look?

How to access NSWindow pixel buffer in OSX?

+6
source share
1 answer

As far as I know, there is no way to exclude certain windows from OS X's built-in write APIs:

  • AVFoundation AVCaptureScreenInput (10.7 +)
  • Core Graphics CGDisplayStream (10.8+)

Both of the above methods seem to capture the contents of the screen after the layout, when the final screen output has already been compiled together.
Thus, excluding your recording window, you will need to use an API that allows you to compose windows yourself, and then add these custom frames to AVAssetWriterInput.

Quartz Window Services allows you to take snapshots of single windows through CGWindowListCreateImage. A good sample project that also shows how to combine several window shots together, Son of robbery .

After extracting the stitched image together, you will have to add it to AVAssetWriterInput. AVFoundation provides a convenience class for adding custom pixel buffers to a movie: AVAssetWriterInputPixelBufferAdaptor .

In particular, part of AVFoundation can become very frustrating, and you may run into performance issues, as composition is more likely to be slower than the OS X built-in linker, but overall you can achieve what you want.

+8
source

Source: https://habr.com/ru/post/951441/


All Articles