Monday, November 26, 2007

Code for capture and then record video at processing

import processing.video.*;
Capture cam;
MovieMaker mm; // Declare MovieMaker object

void setup() {
size(320, 240);
cam = new Capture(this, 320, 240);
// Create MovieMaker object with size, filename,
// compression codec and quality, framerate
mm = new MovieMaker(this, width, height, "drawing.mov",
30, MovieMaker.H263, MovieMaker.HIGH);
background(204);

}

void draw() {
if (cam.available() == true) {
cam.read();
image(cam, 160, 100);
// The following does the same, and is faster when just drawing
the image
// without any additional resizing, transformations, or tint.
//set(160, 100, cam);
}

mm.addFrame(); // Add window's pixels to movie

}

void keyPressed() {
if (key == ' ') {
mm.finish(); // Finish the movie if space bar is pressed!
}

No comments: