dideler
3/28/2012 - 4:20 AM

ruby-processing: video capture to a file

ruby-processing: video capture to a file

#!/usr/bin/env ruby

# this is a test of ruby-processing (https://github.com/jashkenas/ruby-processing) where
# captured video is written to a QuickTime file

# use "rp5 unpack library" at a command line to install the video library if you haven't

# tested with Ruby 1.9.2 on OSX with built in web cam

class VideoCaptureToFileTest < Processing::App

  load_library :video
  include_package "processing.video"
  import 'processing.video.MovieMaker'
  
  def setup    
    smooth
    size(720, 576, P2D)
    @input = Capture.new(self, width, height, 30)    
    output_file = "output_#{Time.now.to_i.to_s}.mov"
    @output = MovieMaker.new(self, width, height, output_file, 30, MovieMaker::JPEG, MovieMaker::HIGH ) 
  end

  def draw    
    @input.read if @input.available?
    image(@input, 0, 0)
    @output.addFrame
  end
  
  def key_pressed
    if (key == ' ')
      @output.finish 
      exit
    end
  end
  
end