[Loading A 'small movie' in .PNG frames (Memory DEBO)] *closed*... (._.)

Thanks pickle my issue isn’t relating to the loading process :point:
The loading process loads 123 frames almost flawlessly while updating a JProgressBar’s percentage.

I know there’s got to be a better way to cache Images lol…

If by changing them from a:

ArrayList<BufferedImage>

To:

LinkedList<ImageIcon>

reduced the allocated memory on start up from 872mb to 850mb, what else can I do?

Your 3 steps sound like something I’ll try out today, I know it takes anywhere from 200ms - 216ms to load 1 frame.
(Shuffled in intervals of 60ms - 75ms while playing)

Now that I think about it this, it isn’t really efficient lol.
You don’t see YouTube ‘pre-buffering’ a whole clip at once when you click play XD.

If it takes roughly 200ms to load/unload an image, then that’s roughly 5 images per second.

Saying that you had 123 images, that’s about 25 images you’d need to load before you start swapping.

Then as you start the movie, you push images to the front of your list, and pop the images that have played in sort of a first in, first out sort of fashion.

This assumes that you aren’t going to loop this movie continuously with zero pauses. If that’s the case then there’s no way around it and you need to have all the images or you’ll run into a delay/crash somewhere along the line.

-Pickle :slight_smile:

This is one of the few programming tasks that can’t be done unless you use ‘hacks’. Hacks are unreliable and only work in specific cases.

You need to work out a way to solve this problem with out using hacks.

There are 2 ways I can see to do so:

  • Use OpenGL + one of the LWJGL media players
  • Completely change your idea of the format, and use a system which contains whole images where neccessary, and when there are chunks of pixels that stay the same, have some code which only replaces the parts of the image that change (like using g.drawImage() on the original image). This will require a new file format, lots of designing, and some nasty coding work, but at least it will be reliable if you get it right, and it will cut down the size massively

Good Luck!

Uuugh… Not that nightmare again…
[/quote]
yea ^^
but its just appropriate when you wanna play video in java 2D D:
the punishment should fit the crime :smiley:

My bad T_T

ArrayList<BufferedImage> / LinkedList<BufferedImage> 

results in 850mb used.

ArrayList<ImageIcon> / LinkedList<ImageIcon>

is the one resulting in 872mb used.

(After research):
Evidently my problem has to due with a ‘Memory Leak’, which is being caused by me adding all the Images to the LinkedList and never removing them O.O.

I tried the ‘Memory leak finder / stopper’ called “Plumbr” that thing failed hard-core lol.
Never even detected the memory leak, as soon as it occurred Plumbr just crashed :expressionless: :expressionless: :expressionless:

850MB is more than my HexPrism engine uses (mostly)

Just use OpenGL. There is absolutely no advantage to Java2D except the easyness of learning.
Once you’ve learnt the basics of OpenGL, it’s even easier to code.

You don’t need to use JMF to play a video-only MJPEG stream. You can do that with just ImageIO. Various examples online, such as this http://thistleshrub.net/Joomla/index.php?option=com_content&view=article&id=115:displaying-streamed-mjpeg-in-java&catid=43:robotics&Itemid=64

That really does make sense… since 850MB/123pngs = roughly 6.9MB per .png… those would have to be some massive png’s lol :slight_smile:

-Pickle

It’s not the size of the .png, it’s the size of the image in RAM.
This means that any .png compression is lost.

Well Pickle, my Game’s Dimension is only 800x600, so yeah lol.
Those Images could be re sized some T_T.

EDIT:
Lol guys.
I’m not looking for a Game Engine to use…
I’m not looking to upgrade from Java2D (At the moment)…
I’m not having ‘time’ issues with loading them…
I’m not looking to Stream JPEG from a website…

The opening question was:
“How can I load around 123 Images while optimizing the allocated memory”.

I lowered it by around 20MB just by changing the generic List that I was using.
There’s got to be some sort of compressed List that I haven’t ran into yet…

Yes, but you saved 20MB because the ImageIcons were simply wrapping the BufferedImages, so naturally there was more stuff in memory with a list of ImageIcons. The actual RAM used by BufferedImages was the same. If you cannot cut down your image size or resolution, you’ll probably have to find an Image implementation that is more space efficient than BufferedImage (which I believe typically is just uncompressed RGB data). See this StackOverflow post for a discussion about this very problem and possibly some ideas for minimizing your memory requirements.

The answer is you can’t.

The only optimisations so far have been cutting off parts of the image, and removing the overhead of an ArrayList.

There is no way to compress the images in memory. You have to find a way to cut down on the amount of images (or at least full images) required.

That is the only solution.

As for a different kind of list. Why a list? Use a BufferedImage[].

IMO you should not attempt to stream a movie for an intro. Especially not in Java2D.

Instead I would create a “modular” animation, made up of shapes and images. You can use something like Flash or Inkscape to create the animation. You can probably find some Java2D SVG parsers on the web, or you can create your own framework if your animation is relatively simple. This might not be exactly the look you’re going for, but it’s a much more realistic option.

And of course, as everybody else is saying, if you want to do something like this you should be using OpenGL. Even just storing downsampled and compressed textures on the GPU might be enough to solve your problem.

Well thanks for that.
Now that I’m actually calculating how long each Image takes to load.
Implementing ‘BufferedImage[]’ instead of the List resulted in lowering the elapsed time took to load all 123 Images by about 5 - 7 seconds.

@BoBear2681:
Thanks, I realized that the ImageIcon had something to do with the BufferedImage when the ‘Java Heap Space’ error occured.
Could see in the stack trace that the ImageIcon was polling BufferedImage methods.
Creating DirectColorModel, DataBufferInt etc, thanks :smiley:

@davedes:
The ‘Animation’ isn’t really complicated lol, nor is it ‘Memory Consuming’.

Method for shuffling Images:


if (animatedBackground) {
	if (mainMenuFrameTimer.elapsed() >= 60 + engine.getCurrentInterval()) {
		currentIntroFrame++;
		mainMenuFrameTimer.reset();
	}
}

Method for rendering:


if (animatedBackground) {
	if (currentIntroFrame <= totalIntroFrames) {
		g2d.drawImage(gameWindow.getFrames().get(currentIntroFrame), x, y, null);
	}
}

The only thing ‘Memory Consuming’ is the actual Images that are being appended to the List.

How about making the images very small and up-scaling them with nearest-neighbour filtering. Choose an art style that works well with nearest neighbour filtering. And reduce the image size by avoiding repeating areas like a starry background (which should instead be static).

Did you look at the code behind that link? Nothing says your stream has to come from a website, it could come from a file. The point is that finding a way to have all your images loading on the fly from a single file (as JPEGs) should be fast enough and get rid of your memory issue.

I like that Idea :o
Thanks mate ;D

I’ve only messed around with MagFilter’s in JMonkeyEngine, so I’d have to look into ‘Nearest-Neighbour Filtering’ with Images in Java2D.
I do remember that when switching to MagFilter.NEAREST, it would result in major pixelation D: (MineCraft status textures)

EDIT:
About the Art Style… 8)

All of the 123 frames (Images) were captured with a Screen-Recorder I programmed in Java.
Don’t think I could really modify the art style of a video that was ‘pre-recorded’ can I?
:-X

Why is this recorded video so important to your game? Why don’t you just re-do the intro using programatically animated sprites and shapes? It will probably look better; more original, and less “this is ripped off a crappy quality YouTube video.”

It all goes with the music for the game trust me.
(Personally I think the Quality of them are fine, even while animated)

Main Menu: (In Controls Menu, yes the background’s animated)

Projects have motives lol. :point:
I started messing around in my IDE one day, wanted to make a ‘Screen Recorder’.
Than I wanted to create a ‘Movie Shuffler’ to see how the playback was.
From there it turned out nice enough for me to want to actually implement a little Game + Menu into it.
Now here we are :smiley:

IMHO it looks cheap and inconsistent with the GUI, and will undoubtedly look inconsistent with the game sprites… but whatever floats your boat. :-\