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.
IndexProgramming Questions & HelpPrograms › saveFrame hangs, files huge!
Page Index Toggle Pages: 1
saveFrame hangs, files huge! (Read 1174 times)
saveFrame hangs, files huge!
Mar 10th, 2006, 5:45pm
 
I have a simple draw loop with saveFrame.  The first frame is saved correctly but then the applet freezes and the applet has to be quit or killed from a terminal session.

void draw() {
 image(img, 0, 0);

 for (int i=0; i<numCars; i++)
   cars[i].move(random(-2,2),random(-2,2));
 
 if (makeMovie)
   saveFrame();

 println("framerate="+framerate);
}

Am I doing something obviously wrong?

The tif files are also huge!  Is it possible to save with a compressed format?

Thanks!

Owen

Re: saveFrame hangs, files huge!
Reply #1 - Mar 11th, 2006, 4:15am
 
(this is just guesses in lieu of someone more knowledgeable coming along...)

Have you tried to work out what's causing saveFrameto choke? Like cutting out car movement or making it smaller and so on?

If it turns out to be the size, maybe you could export in a vector format before you draw the background image in, then composite those vector images over the background later when you make the movie (if I understand what you're doing right).

http://www.texone.org/prosvg/
http://processing.unlekker.net/SimplePostscript/index.html
http://www.mark-hill.co.uk/AIExport/

Also, sounds like you're on linux, if you zip up your code I/someone who's around could try it on windows to see if the problem lies there. Although trying saveFrame on a very very simple sketch shoudl reveal whether that's it.



Re: saveFrame hangs, files huge!
Reply #2 - Mar 11th, 2006, 7:19pm
 
Thanks for the idea, uoou: when I make the number of cars 0, the saveFrame works fine!  It's even pretty fast.  

BTW: Here's the original applet without the frameSave() code:
http://backspaces.net/files/Roads/applet/

If I set the number of cars to 1, it still works!  Weirder and weirder.  Still pretty fast.

If I set the number of cars to 100, it just works .. but very, very slowly.  The simulation itself runs quite fast (6fps even with 15,000 cars) as you can see from running the applet.

So it looks like the problem has to do with the cars?  Or possibly with any significant change at all in the image?

BTW: I also found that this behavior/bug is also true with saveBytes .. I tried converting the image to jpg using a previously posted SaveJpg method, and it also worked with 1, 10, very slowly with 100 and so on.  Its a bit slower anyhow due to the additional computation.

Owen

import com.sun.image.codec.jpeg.*;

void SaveJpg(String fname){
 ByteArrayOutputStream out = new ByteArrayOutputStream();
 BufferedImage img = new BufferedImage(width, height, 2);
 img = (BufferedImage)createImage(width, height);
 loadPixels();
 for(int i = 0; i < width; i++) {
   for(int j = 0; j < height; j++) {
     int id = j*width+i;
     img.setRGB(i,j, pixels[id]);
   }
 }
 try{
   JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
   encoder.encode(img);
 } catch(Exception e){System.out.println(e);}
 byte [] a = out.toByteArray();
 saveBytes(fname, a);
}

Re: saveFrame hangs, files huge!
Reply #3 - Mar 12th, 2006, 2:46am
 
Ok, running it in processing I get about 6fps with java2d, 8fps with P3D and 11fps with OPENGL.

OpenGL seems to fall off the fastest as you increase the number of cars - with 7000 it's more like 30fps. Whereas P3D with 7000 cars is about 11fps.

Hmm, if I draw the image like this:

 background(img);

Rather than using image(), the framerate rises a fair bit (12fps in P3D).

Oh. Hmm. I've just put a saveFrame() in and it works fine. I stayed in P3D and it's dropped from 12fps to about 8 but it's saving the images with no probs.

Right, gonna go boot to linux and try tunning it there.
Re: saveFrame hangs, files huge!
Reply #4 - Mar 12th, 2006, 3:02am
 
Works fine here too. Slightly slower than windows but that's all.

Looks like it's time to check obvious stuff like running out of disk space and that?

Re: saveFrame hangs, files huge!
Reply #5 - Mar 12th, 2006, 3:18am
 
Though it's not disk space because you said it works fine for you with few cars... this is weird.

For me, saving an image just drops it by a few fps. And it seems the same for you, up to a point...

I'm going to ramp up the number of cars as see if I can hit a limit. I would say that it's maybe starting to run out of memory and use disk, but processing's mem limit should be way lower than physical ram. Mine's just on default, whatever that is.

Hng. Doesn't seem to matter. Even with 1 million cars - framerate goes right down to about 0.3 fps, but it chugs along saving the images fine.

I don't know what to suggest...

Edit - may as well upload what I have in case I've changed anything without thinking:

http://redcrayon.do.sapo.pt/backs/

Re: saveFrame hangs, files huge!
Reply #6 - Mar 12th, 2006, 5:06am
 
I forgot to mention: I'm using Processing 107 on Mac OS X.  Don't know if it matters though.

Owen
Re: saveFrame hangs, files huge!
Reply #7 - Mar 12th, 2006, 6:28am
 
Might be worth getting someone else with a mac to run the code, see if it's a mac thing or something to do with your setup.
Re: saveFrame hangs, files huge!
Reply #8 - Mar 12th, 2006, 4:36pm
 
saveFrame is really slow on osx, because java file i/o seems to be complete crap with the apple java implementation (there's an 8:1 difference between a 2.66 ghz dell desktop and my 1.5 ghz powerbook). so that's probably part of the problem.

it sounds like there's some sort of interaction between how saveFrame() works and how the draw() method works that might be slowing things down further though.. wonder if this is related to the other threading issues.
Re: saveFrame hangs, files huge!
Reply #9 - Mar 13th, 2006, 6:17am
 
Hi Ben, nice to hear from you and thanks for all the fish^H^H^H^H Processing .. its an absfab use of Java!

I don't think its an IO problem, because when we take the rectangles out by reducing the number of cars to 0 or a similar low number, the frame rate out to disk seems quite reasonable.  For example, if I put cars to 0, thus outputting identical frames each draw() call, I eventually stabilize at around 1.7 fps (at 46 frames).  That's fine I think for that large a tif (1.4MB).

So it seems to be something to do with the odd interaction of drawing a bunch of rectangles (cars) on top of the city map.

Thanks for beaming into the conversation and bless you for the delightful system!

Owen
Re: saveFrame hangs, files huge!
Reply #10 - Mar 28th, 2006, 3:37am
 
Well, the problem seems to have evaporated, lord knows why!

I tried uoou's idea of using background(img) and everything started to work.  But just to check, I went back to image(img, 0, 0) .. and it worked too!

I am on a later Processing: 109, but don't know if that fixed it.

Anyway, case closed for now.

BTW: using the nifty contributed software SaveJpg makes quite a difference in overall size even tho a fps or too slower.  Quite nice.
Re: saveFrame hangs, files huge!
Reply #11 - Mar 28th, 2006, 4:00am
 
DOH!

Also suggested by uoou was to try P3D .. which I did too .. and THAT did make a difference: using JAVA2D brought back the same old problem.  OPENGL seems to work too, although I seem to need to use image(img, 0, 0) rather than background(img).  If I use the latter, I just get a grey background rather than the santa fe image.

So in summary, it looks like JAVA2D is where the saveFrame() problem resides, and in addition, it seems like OPENGL fails to show the image using background() but works with Image(..)

Sorry for being a bit unorganized.  Thanks a bunch uoou!

Owen
Re: saveFrame hangs, files huge!
Reply #12 - Mar 28th, 2006, 3:57pm
 
as posted on the related thread:

i think this is probably related to another bug report that i could never confirm. so we'll track this issue here:
http://dev.processing.org/bugs/show_bug.cgi?id=189

if anyone can help me track this down with an example that consistently causes trouble, that'd be great. i'll close this thread so we can follow up using the bugs db.
Re: saveFrame hangs, files huge!
Reply #13 - Mar 31st, 2006, 7:29pm
 
fixed for 0112, thanks to backspaces for posting an example so that i had something from which to debug.
Page Index Toggle Pages: 1