Processing’s official reference has a good example of how to record a movie file. And for most cases it works fine. After you finish your sketch, just add a little code and voila, you get a movie. But sometimes, I like to record my progress when I’m developing a sketch. To do that, I sort of added a couple features to make the process easier. That way I can record a sketch at anytime during the sketch, and have it output a different movie file.
Step 01 – Setup Library, and Global Variables for Recording Process
import processing.video.*; boolean RECORDVIDEO = false; // Keyboard Letter "R" MovieMaker mm;
Step 02 – Establish a way to Turn On and Off Recording Process. Use this outside of your draw() and setup() functions.
void keyPressed(){
// Record Video
if( key == 'r' || key == 'R' ) {
RECORDVIDEO = !RECORDVIDEO; // Boolean switch
if(RECORDVIDEO == true) {
println("Recording has Started");
setup(); // Go back to Setup and start a New Recording
}
else {
println("Recording has Stopped");
mm.finish(); // Since we were recording, let's stop!
}
}
}
Step 03 – Place initRecord() and recordSketch() into your sketch
void initRecord() {
//Recording Techniques
int h = hour();
int m = minute();
int s = second();
String filename = "movies/sketch_"+h+m+s+".mov";
if(RECORDVIDEO == true) {
mm = new MovieMaker(this, width, height, filename,
30, MovieMaker.H263, MovieMaker.HIGH);
}
}
void recordSketch() {
if(RECORDVIDEO) {
mm.addFrame();
}
}
Step 04 – Run InitRecord() at the end of your setup() function
initRecord(); // initialize Video Capture
Step 05 – Run recordSketch() at the end of your draw() function
recordSketch(); // Starts Video Capture when ready
Full Example
/**********************************
* Note: Written in Processing 148
***********************************/
import processing.video.*;
MovieMaker mm;
boolean RECORDVIDEO = false; // Keyboard Letter "R"
void initRecord() {
//Recording Techniques
int h = hour();
int m = minute();
int s = second();
String filename = "movies/sketch_"+h+m+s+".mov";
if(RECORDVIDEO == true) {
mm = new MovieMaker(this, width, height, filename,
30, MovieMaker.H263, MovieMaker.HIGH);
}
}
void recordSketch() {
if(RECORDVIDEO) {
mm.addFrame();
}
}
void keyPressed(){
// Record Video
if( key == 'r' || key == 'R' ) {
RECORDVIDEO = !RECORDVIDEO; // Boolean switch
if(RECORDVIDEO == true) {
println("Recording has Started");
setup(); // Go back to Setup and Start a New Recording
}
else {
println("Recording has Stopped");
mm.finish(); // Since we were recording, let's stop!
}
}
}
void setup() {
size(640,480);
background(0);
initRecord();
}
void draw() {
// Move your mouse around while it records
ellipse( mouseX, mouseY, 30,30);
recordSketch();
}