Skip to content

Instantly share code, notes, and snippets.

@juanger
Created July 25, 2010 17:53
Show Gist options
  • Save juanger/489722 to your computer and use it in GitHub Desktop.
Save juanger/489722 to your computer and use it in GitHub Desktop.
require 'osx/cocoa'
include OSX
require_framework 'QTKit'
class Screen
def self.capture
screenshot = OSX::CGWindowListCreateImage(OSX::NSScreen.mainScreen.frame, OSX::KCGWindowListOptionOnScreenOnly, OSX::KCGNullWindowID, OSX::KCGWindowImageDefault)
screenshot.retain
end
def self.to_nsimage(cgimage)
bitmapRep = NSBitmapImageRep.alloc.initWithCGImage(cgimage)
blob = bitmapRep.representationUsingType_properties(NSJPEGFileType, nil)
nsimage = NSImage.alloc.initWithData(blob)
nsimage
end
end
error = nil
mMovie = QTMovie.alloc.initToWritableData_error(NSMutableData.data, error)
images = []
80.times {
images << Screen.capture
}
puts "Now encoding..."
images.each do |img|
mMovie.objc_send :addImage, Screen.to_nsimage(img),
:forDuration, QTMakeTime(1,20),
:withAttributes, {:QTAddImageCodecType => "mp4v"}
img.release
end
mMovie.objc_send :writeToFile, "screencast.mov",
:withAttributes, {:QTMovieFlatten => true}
puts "Done!!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment