Loading...
Logo
Processing Forum

Hello,


is there a recommended way of creating a sequence of pngs from a sketch as quickly as possible? I just need to save the frames without displaying them.


Would setting the frame rate to something high (999999), using an offscreen PGraphics object and calling save on it at the end of each draw loop be the best way?


Related to this, I see that frameRate's documentation states that "If the processor is not fast enough to maintain the specified rate, it will not be achieved"


In which case, would my approach drop frames? How could I ensure every frame was rendered and saved as quickly as possible?


Thanks.

Replies(5)

Why do you need an high frame rate if that's for exporting? Usually, the export is processed separately, eg. making a movie out of it.
In your case, unless you make a virtual disk, you will be limited in speed by the disk performances.
I'm not sure what you mean by processed separately.

I'm after the high (unlimited, really) frame rate as I want to run the sketch as quickly as possible and save each frame as an image. I currently seem to be limited by the cpu rather than disk speed, I expect due to the compression in the saveFrame function when I save .png files. I'm working on writing the images to disk as uncompressed arrays of integers using a FileOutputStream - I'm making good progress on this and finding that it's about twice the speed of saveFrame to write each frame to disk.

I don't want frames skipped, as I posted above, and so am looking for the best way to run the sketch. Any ideas?
In general, we save lot of frames to make a movie or something out of these files later. That's what I meant by "processed separately".
Such sketch doesn't need to run in real time. In general, people separate "real time animation" which must be unbound by I/O processes like saving to disk (or loading from disk) and "generating data" which is almost a batch job, sometime even done without display on screen.
That's what I'm thinking, but how does this fit with Processing's setup and draw methods?

If I write a sketch to read in data that I've prepared, then generate and save images from it, how can I do this as quickly as possible? As Processing seems designed to run in real time, I'm not sure what happens behind the scenes in setup and draw that might limit the speed.

Although another approach would be not to use the PApplet class at all, just use PGraphics objects to render and save from the prepared data... is this how you'd do it? What do you think?
I believe, unless any of your animation is based on millis(), it will always be the same relative to the frame rate. If you are rendering still frames for compilation after the sketch has run, the sketch frame rate makes no difference.

Say you have a circle that starts on the left of the window and moves one tenth of the screen width every frame:

float x = 0;
...
void draw() {
      x += .1*width;
      ellipse(x, height/2, 100, 100);
}

If you save ten frames from this sketch, you'll have still frames that, when strung together, produce an animation of the circle moving once across the screen. In the video editing software you use to create a video from an image sequence, if you set the frame rate to 30fps this animation will play in a third of a second (10frames / 30fps = .333). Likewise, if you set the rate at 60fps in your editing software the animation will only take a sixth of a second.

The frame rate in Processing makes no difference in this situation. Each frame can take an hour or a hundredth of a second to render and save. I'm pretty sure most TVs, online services, and codecs don't support such high frame rates though.