We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
time lapse or infrequent frame capture? (Read 933 times)
time lapse or infrequent frame capture?
Sep 17th, 2008, 9:57pm
 
I am trying to figure out how to only capture a frame to a movie every x.x seconds.  Right now, the specific thing I am trying to do is to capture 1 frame every 2/3 of a second.  I want the created file to be 30 fps, so that what I end up with is a fast playback of a slow event.

So far everything I have tried with delays or time just locks up processing (or at least apparently does, I'm new).  Changing the fps in the new MovieMaker tag just plays back the movie slower, so this I'd want this set to 30.  What's the way to do this?

The code below is what I've been starting with, but it doesn't really have to be based on that.  This is just a merge of a couple o the example scripts.

Thanks in advance, Ian



Quote:
/**
 * Getting Started with Capture.
 * 
 * Reading and displaying an image from an attached Capture device. 
 */

import processing.video.*;

Capture cam;

MovieMaker mm;

void setup() {
  size(640, 480);

  // If no device is specified, will just use the default.
  cam = new Capture(this, 640, 480);

  // To use another device (i.e. if the default device causes an error),  
  // list all available capture devices to the console to find your camera.
  //String[] devices = Capture.list();
  //println(devices);
  // Change devices[0] to the proper index for your camera.
  //cam = new Capture(this, width, height, devices[0]);

  // Opens the settings page for this capture device.
  //camera.settings();

mm = new MovieMaker(this, width, height, "vhs_lapse.mov", 30, MovieMaker.JPEG, MovieMaker.BEST);
background(0, 0, 0);

}


void draw() {
  if (cam.available() == true) {
    cam.read();
    image(cam, 0, 0);
    // 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();

  if (key == ' ') {
    // Finish the movie if space bar is pressed
    mm.finish();
    // Quit running the sketch once the file is written
    exit();
  }

  }
}

Re: time lapse or infrequent frame capture?
Reply #1 - Sep 30th, 2008, 12:28pm
 
Here is a solution, hope it works good.

There is a diff variable and a framerate that you might need to change. We use the millis, which gives back the milliseconds from the start of the applet.

Code:
import processing.video.*;

Capture cam;
MovieMaker mm;

void setup() {
size(640, 480);

// If no device is specified, will just use the default.
cam = new Capture(this, 640, 480);

mm = new MovieMaker(this, width, height, "vhs_lapse.mov", 30, MovieMaker.JPEG, MovieMaker.BEST);
background(0, 0, 0);
frameRate(30);
}

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

}
}


int i = 1;
int framerate = 30;
int diff = 600; // 1000msec = 1sec
float m = millis();

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

if (i==diff*framerate/1000) {
float m = millis();
println(m);
mm.addFrame();
i = 0;
}

i++;

}

}

Re: time lapse or infrequent frame capture?
Reply #2 - Oct 2nd, 2008, 10:24pm
 
Thanks very much!  That works perfectly with the various things I'm trying to do right now.  It gives me a couple ideas for other uses, as well.

Thanks, Ian
Page Index Toggle Pages: 1