Animated PNG sequence

**Hi Gurus, Masters and kindhearted people,

I am using OpenFrameWorks to play PNG sequence (about 480 images) for an animation loop. I am facing an interesting problem here: it runs properly if each image is small (under around 600X400 pixels);

However, if each image is bigger than (approximate bigger 600X400 pixels - no matter how small the size, even it’s only 50K each image). OF only be able to run 256 images of it. If I set OF to run whole sequence 480 images it keep collapsing.

Here is the relevant code:**

void testApp::setup() {

ofDirectory dir;

int nFiles = dir.listDir(“plops”);
if(nFiles) {

for(int i=0; i<dir.numFiles(); i++) {

// add the image to the vector
string filePath = dir.getPath(i);
images.push_back(ofImage());
images.back().loadImage(filePath);

}

}

void testApp::draw() {

ofBackground (253,207,162);

// this is the total time of the animation based on fps
float totalTime = images.size() / sequenceFPS;

int frameIndex = 0;

if(bFrameIndependent) {
// calculate the frame index based on the app time
// and the desired sequence fps. then mod to wrap
frameIndex = (int)(ofGetElapsedTimef() * sequenceFPS) % images.size();
}
else {
// set the frame index based on the app frame
// count. then mod to wrap.
frameIndex = ofGetFrameNum() % images.size();
}

// draw the image sequence at the new frame count (background color + position for animated character)
ofSetColor(253,207,162);
images[frameIndex].draw(0, 90);

}

**How can I solve this problem?
Is that because of the hexadecimal system? As 256 looks relevant.
Should I enlarge the vector size, if so how should I do it?

Thank you so much ?**

I would be willing to bet that this is more likely a limit to the number of textures you can allocate, or maybe just running out of graphics memory.

By default ofImage creates a texture (graphics card memory space) for its associated main memory pixels. It uploads a copy of the image to the gfx memory, and there usually isnt too much of it depending on your graphics card. You can turn this off by calling setUseTexture(false) on the image objects in your vector before you load the image files. this should solve your problem.

alternatively, you may want to use ofPixels objects or even unsigned char *s instead of ofImage to get rid of some overhead.

ofPixels is a nice choice because you can still use the
ofLoadImage(ofPixels &pix, string path) function to easily load an image, without creating a temporary ofImage object just for loading.

You’ll then need only one ofTexture object (and substantially less graphics memory) to display your images, just load the pixels to the texture before you draw.

Thank you so much Tim!!!

I am trying and will tell you what happened.

Cheers!

I’m also interested in knowing more about this because this is what happened to me.

At some point I just thought it was a memory alocation problem of the running application. In windows 7 x64 I was compiling for 32 bits in codeblocks using of0071. I noticed that when I could run the app (having failed to load all of the png sequences), while running the application, when reaching those frames the console started displaying texture not allocated problems. This was always at under 980 MB of ram.
What is weird is I expected pngs to load onto graphics card memory rather than normal RAM but no, it was loaded onto RAM and maybe even onto graphics memory and RAM. I don’t know since I’ve never gone so far in programing.

@OpenFrameDoeswork
Are you sure it was exactly 256 images or is that an approx. number?

I have the same problem here.

I can load aprox. 200 images with 1280x720, but with more than 200 images, bring this error:

  
This application has requested the Runtime to terminate it in an unusual way.    
Please contact the application's support team for more information.    
    
Process returned 3 (0x3)   execution time : 10.307 s    
Press any key to continue.    

If I use setUseTexture(false), no images are displayed.

Here’s a snip of my code:

  
    // Guy 1    
    int nFiles1 = dir1.listDir("3guys/guy1");    
    if(nFiles1) {    
        printf("Folder found.\n");    
    
        for(int i=0; i<dir1.numFiles(); i++) {    
    
            // add the image to the vector    
            string filePath1 = dir1.getPath(i);    
            images1.push_back(ofImage());    
            images1.back().setUseTexture(false);    
            images1.back().loadImage(filePath1);    
    
        }    
    
    }    
    else printf("Could not find folder\n");    

I didn’t tried the ofPixels aproach, but I’ll give a try and post the results.

My setup:

  • Windows 7 Ultimate 64 bits;
  • OF 0072;
  • Code::Blocks;
  • NVidia GeForce GT 650M, 1GB DDR5;
  • 8 GB DDR3 RAM;
  • Core i7 2nd generation.

Thanks,
Daniel

Hi, I got it working by using ofxImageSequence addon.

Works like a charm now, with more than 450 images of 1280x720!!!

Thanks
Daniel

1 Like

I just verified. Not only does it work but memory use is extremely low (I believe it just uses video memory). It seems to be much more efficient. Thanks for the info! :smiley:

Instead of random crashing applications or 880 meg of RAM with lost frames during image loading I get a 28 megs on RAM with no problems. This is very good! It can use pngs with alpha, just remember to use ofEnableAlphaBlending().

1 Like

Yes, it’s the best solution for playing “videos” with alpha channel.

I converted my videos to PNG sequence with alpha channel, and now I have 8 characters on my scene running independently.

I have 75 frames per character, 600 in total. Running smoothly.

Thanks ofxImageSequence and all people on this thread.

Cheers,
Daniel

Thanks Tim nerdjgua, irregular, everyone join in the conversation!!!

The ofxImageSequence addon works!!