Video Export (with Toggle)

final String sketchname = getClass().getName();

import com.hamoid.*;
VideoExport videoExport;

boolean record = false;

void keyReleased() {
  if (key == 'r') {
    record = !record;
    println("recording:", record);
  }
}

void rec() {
  if (frameCount == 1) {
    videoExport = new VideoExport(this, "../"+sketchname+".mp4");
    videoExport.setFrameRate(30);  
    videoExport.startMovie();
  }
  if (record) {
    videoExport.saveFrame();
  }
}