Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocoa screen capturing?

How do you capture an NSImage of the screen in Cocoa? I need to know the fastest way, because I'm trying to make a screencasting app.

like image 800
nonpolynomial237 Avatar asked Aug 25 '26 12:08

nonpolynomial237


1 Answers

See the OpenGLCaptureToMovie sample. I'd add that you should use Quartz Display Services' refresh-notification APIs instead of a timer.

Note that the OpenGL example doesn't produce NSImage objects. There's no point in doing so, since you can't put those into a movie. Well, I guess you could assign an NSImage at a specified frame time, but I don't know how well that would work with compression.

Speaking of compression, use the Animation codec at maximum quality for your recording. This provides decent enough compression to not overwhelm the disk, and certainly won't overwhelm the processors. You can then offer conversion options, such as H.264, H.264 for iPhone, and H.264 for iPod. You should also allow the user to keep the original file; some sites, such as Vimeo, will accept it and allow visitors to download it.

like image 195
Peter Hosey Avatar answered Aug 28 '26 05:08

Peter Hosey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!