I need to saveFrame() while showing a video on the sketch display screen

Hi. I have a new question about code. I'm trying to save frames from a web cam while a video is playing in the screen.

I have this code that allows me to save frames, but I don't want to save frames from the displayed video. What I'm not seeing?

Thanks in advance!

import processing.video.*;

Capture cam;
Movie video;

boolean showVideo=false;
boolean saveframe=false; 

void setup() { 
  size(640, 480); 
  cam = new Capture(this, 640, 480, 30);
  video = new Movie(this, "ex.mp4");
  cam.start();
} 


void draw() {
  background(0);
  if (showVideo==false) { 
    image(cam, 0, 0);
  } else {
    image(video, 0, 0);   
  }
  if (saveframe==true) {saveFrame("output.##.jpg");
  }
}

void keyPressed() {
  showVideo=true;
  video.loop();
  saveframe=true;
}

void keyReleased() {
  showVideo=false;
  video.stop();
  saveframe=false;
}

void captureEvent(Capture webCam) {
  webCam.read();
}

void movieEvent(Movie m) {
  m.read();
}

Answers

  • Two approaches to consider:

    1. Draw onto the sketch surface, then save whatever is there with saveFrame()
    2. Draw something you DON'T want to appear on the sketch surface to a PGraphics buffer, then use PGraphics.save()
  • Thanks, I'll try!

Sign In or Register to comment.