"OutOfMemoryError" When Loading Animated GIF

Hi,

I tried to load a series of gif files using the gifAnimation library and encountered "OutOfMemoryError". I have tried increasing the memory settings but encountered the same error.

The problem occurs at Line 15.

This is how the code looks like:

import gifAnimation.*;

Gif scene0, scene1A, scene1B, scene2;

int cplay = 0; //Current gif playing.

void setup() {
  size(1920, 1080);
  background(0);
  imageMode(CENTER);

  scene0 = new Gif(this, "Scene 0.gif");
  scene1A = new Gif(this, "Scene 1 - A.gif");
  scene1B = new Gif(this, "Scene 1 - B.gif");
  scene2 = new Gif(this, "Scene 2.gif");

  scene0.play()
  cplay = 0;

}

void draw() {

  if(cplay == 0){
     image(scene0, width/2, height/2 - 150);
  }
  else if (cplay == 1){ 
    image(scene1A, width/2, height/2);
    image(scene1B, width/2, height/2);
  }
  else {
     image(scene2, width/2, height/2);
  }

}

void mouseReleased(){

  cplay = cplay + 1;

  scene0.stop();
  scene1A.stop();
  scene1B.stop();

   if(cplay == 0){
    scene0.play();
  }
  else if (cplay == 1){
     scene1A.play();
     scene1B.play();
  }
  else {
    scene2.play();
  }
}

Regards.

Answers

  • Quick test you can do on your side and report. If you run one file at the time, do you get any error? Can you share your gif files?

    Kf

  • edited March 2018

    If I run one file at the time, the error does not occur. When I load multiple file with increased memory, the startup took a while before it fully loads and it consumes quite a lot of memory.

    Just wondering if Processing is not a suitable environment for animation?

    These are my GIF files: https://drive.google.com/drive/folders/1T4OrfSm0ascub8xIc-Isnea3rnXKEVDn

  • Answer ✓

    Just wondering if Processing is not a suitable environment for animation?

    Open source ===> Who knows ?

    It really depends on your expectations and your resources as in computer and in resources as what you are trying to load. Is the Gif library the most suitable tool for you? As it is right now, it seems it is not working for you. If you check the source code of the library, a gif object is treated as an array of PImages. How big are those gifs? I do not work with gifs so I can't tell how it would perform. If you share them, people could run (likely) your code and provide some feedback.

    On a side note, notice that 1A and 1B are overlapping. Is that intended or you forgot to introduce an offset when displaying that pair of gif objects?

    You can also discuss more about your animation's details and forum goers could provide relevant feedback.

    By the way, you might be interested in checking the exhibition section to see what people has done before.

    Kf

  • I have provided the links to my GIFs in the previous comments. I intend to make the 1B to run after the 1A. Maybe I code wrongly on that part?

  • I have provided the links to my GIFs in the previous comments

    "You need permission

    Want in? Ask for access, or switch to an account with permission."

    good job.

  • Answer ✓

    scene2 is 72 frames, all 1920x1080. 19MB compressed...

    that's why you're out of memory.

  • Is there any other way to efficiently play a long animation?

  • I wonder if instead of the gif file, you play a movie type of object. You should be able to convert the gif into a movie by retrieving the PImage array and using VideoExport by hamoid. This should be done in a separate sketch.

    However I am not sure if it is going to work. I am assuming playing a movie would be more efficient and you are not been limited by the computing power of your machine. Plus I usually handle movies with smaller image dimensions. A quick test would be to get a few movies with that image size and play them together. If it works, then Movie would be the way to go. Please take my comment with a grain of salt as I am not an expert in this topic.

    And I didn't test your code... I can't atm.

    I intend to make the 1B to run after the 1A

    Related to this comment: Based on your code scene 1A and 1B are shown together. Not sure what you mean 1B run after 1A then.

    Kf

  • I will try that out. Thanks a lot.

Sign In or Register to comment.