Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVCaptureScreenInput and kCGWindowListOptionOnScreenBelowWindow

I am doing screen capture with AVCaptureScreenInput. The app has a window with configuration options.

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

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

kCGWindowListOptionOnScreenBelowWindow is found in CGWindow.h in the Core Graphics framework. AVCaptureScreenInput is part of AVCaptureInput.h in the AVFoundation framework.

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

I'm relatively new to Objective-c ands its not clear to me if its possible to use the kCGWindowListOptionOnScreenBelowWindow with AVCaptureScreenInput. If it is, could someone provide tips on what the resulting code needs to look like?

How to access the pixel buffer of an NSWindow in OSX?

like image 355
Geuis Avatar asked Aug 10 '13 03:08

Geuis


1 Answers

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

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

Both above methods seem to grab the screen content after compositing, when the final screen output has already been composited together.
So excluding your recording window would require you to use an API that allows you to composite the windows yourself and later append those custom frames to an AVAssetWriterInput.

Quartz Window Services allow you to take snapshots of single windows via CGWindowListCreateImage. A good sample project that also shows how to composite multiple window shots together is Son of Grab.

After retrieving the stitched together shot, you'd have to append it to an AVAssetWriterInput. AVFoundation provides a convenience class to append custom pixel buffers to a movie: AVAssetWriterInputPixelBufferAdaptor.

Especially the AVFoundation part could become very frustrating and you might run into performance problems as the compositing is very likely to be slower than OS X's built-in compositor, but overall it should be possible to to achieve what you want.

like image 151
Thomas Zoechling Avatar answered Oct 01 '22 07:10

Thomas Zoechling