Kirtan
Kirtan

Reputation: 1812

Loading too many JPEG Files(100 s of ) cause out of memory error

I have too many(100s of) Hi-resolution(1200x800) JPEGS on the SD Card created.

What I am doing right now is Load them all in Thread and Keep them in ArrayList .

I Play Them on Image View Frame By Frame at specific Frame Rate selected by user on UI. My Intention here for loading all the images because I want to play them very fast around 55 fps. Thats works fine if I have 1 Set of 100 image and Tablet with RAM = 1 GB but I have Two Image Viewer both with their own Set of (100 JPEGS) it goes out of memory.

I Tried many ways for my solutions . Here is what I have tried so far.

1 ) FFMPEG video encoding of JPEGS on SDCard ( it will not work as User will be seeking to any position of 100 image and it should be view on screen immediately also I am applying filters like brightness contrast on image so FFMPEG will not work in that)

2) Loading Single file as Bitmap as They are played ( its not working as I want to achieve High Frame Rate and Files Take Time to load )

3) Third Approach which I am using right now works good for me right now but ( Out of Memory Problem as I Have Two Image View with their image set (each one 100 images)) which is loading all Images in ArrayList and user Can Seek to any Image with Seekbar fast as possible and Can Apply various filter on bitmap.

I expect some expert solution for loading fast images on specific frame rate.

Upvotes: 2

Views: 456

Answers (2)

ddmps
ddmps

Reputation: 4380

You're not going to have any luck loading them from the SD card unless you have a super-quick card. A normal card generally won't have a quicker read speed than 10 MB/s. You can always calculate how many frames you need to pre-load and load the rest as it's playing but I'm not going to do that for you, so I suggest using:

android:largeHeap="true" 

in the application-tag in the manifest. This helps out quite a lot with increasing the heap size for your app.

Edit:

If you can allow to show heavily compressed images for the frame navigation you can keep all those in memory (if necessary!) and dynamically load the full images as needed when playing and when user stops at a frame. A simple strategy for buffering:

  1. Load x (depending on FPS and how many frames to play) second worth of images
  2. Calculate how quickly it loaded 1 image (may want to save it and take older load speeds into account as well for robustness)
  3. Calculate how many more you have to load: nFramesToPlay-nLoadedFrames-FPS/(loadSpeed*1.2)*nFramesToPlay (experiment with the arbitrary 1.2. If read-times fluctuate a lot, increase it, and vice versa).

You would have to be sure to load the images in the background, maybe several concurrently (experiment to see if it helps). If read times are really slow, this strategy may do more damage than good.

I also suggest using ActivityManager.getMemoryInfo() and telling the user if you deem it won't be successful in playing the video (tell them to get a better SD card/phone/more memory/less FPS).

Upvotes: 2

Vikrant_Dev
Vikrant_Dev

Reputation: 390

You can do as suggested above using "largeHeap". Another way is to compress the images. You can compress the images here for free.

You can usually loose 50 – 70% of an image size with no perceptible loss in quality. They even give you a little sliding preview pane so you can see the before and after so that you can see the difference in quality.

Upvotes: 0

Related Questions