Created
August 23, 2010 18:07
-
-
Save smparkes/545987 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env macruby | |
framework 'AppKit' | |
framework 'QTKit' | |
framework 'QuartzCore' | |
framework 'CoreVideo' | |
class AppDelegate | |
def applicationDidFinishLaunching(notification) | |
@window = NSWindow.alloc.initWithContentRect([200, 300, 640, 480], | |
styleMask:NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask, | |
backing:NSBackingStoreBuffered, | |
defer:false) | |
@window.title = 'MacRuby: The Definitive Guide' | |
@window.level = 3 | |
@window.delegate = self | |
@window.display | |
@window.orderFrontRegardless | |
@window.makeMainWindow | |
@window.makeKeyWindow | |
@session = QTCaptureSession.alloc.init | |
device = QTCaptureDevice.defaultInputDeviceWithMediaType QTMediaTypeVideo | |
device.open nil | |
input = QTCaptureDeviceInput.deviceInputWithDevice device | |
@session.addInput input, error:nil | |
output = QTCaptureDecompressedVideoOutput.alloc.init | |
output.automaticallyDropsLateVideoFrames = true | |
output.delegate = self | |
key = KCVPixelBufferPixelFormatTypeKey | |
value = NSNumber.numberWithUnsignedInt KCVPixelFormatType_32BGRA | |
pixelBufferAttributes = NSDictionary.dictionaryWithObject value, forKey:key | |
pixelBufferAttributes = {KCVPixelBufferPixelFormatTypeKey:KCVPixelFormatType_32BGRA} | |
output.pixelBufferAttributes = pixelBufferAttributes | |
@session.addOutput output, error:nil | |
main = CALayer.layer | |
main.frame = @window.contentView.frame | |
@window.contentView.layer = main | |
@window.contentView.wantsLayer = true | |
capture = QTCaptureLayer.alloc.initWithSession @session | |
capture.frame = @window.contentView.frame | |
mirror = CGAffineTransformMakeScale -1, 1 | |
capture.affineTransform = mirror | |
main.addSublayer capture | |
@session.startRunning | |
end | |
def captureOutput captureOutput, | |
didOutputVideoFrame:videoFrame, | |
withSampleBuffer:sampleBuffer, | |
fromConnection:connection | |
p captureOutput, videoFrame, sampleBuffer,connection | |
p CVPixelBufferGetWidth videoFrame | |
end | |
end | |
app = NSApplication.sharedApplication | |
app.delegate = AppDelegate.new | |
app.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment