I'm creating an app which needs to show a series of Bitmaps of a video's frames. The app uses MediaCodec to decode a video into a number of frames and gets Bitmaps of each frame to display them on ImageView.
The problem is that each Bitmap's size is about 2~3MB (Frame size is 1280 x 720, the size of 720p video.) so that when the number of Bitmap is above 60~65, the app crashes due to the lack of memory. In order to avoid this problem I've been implementing the D tour algorithm which loads only Bitmaps that need to be displayed right now or soon. Basically I've been trying these methods.
1. Load all Bitmaps in advance.
It's fast enough to meet my need but as mentioned the app crashes when the number of Bitmaps exceed 60~65.
2. When extracting frames, save each frame into a JPEG file and load specific JPEGs into Bitmaps when needed.
I used BitmapFactory.decodeFile to load a Bitmap from a JPEG, but it was slow.
3. When extracting frames, save whole frames into an MJPEG file and load specific "frame" (technically the byte array) into Bitmaps when needed.
I thought if I load Bitmap from the byte array itself the performance might be better. So when extracting frames, I created another metadata file containing information of each frame's byte indices and used that information to load Bitmaps when needed. [BitmapFactory.decodeByteArray](http://developer.android.com/reference/android/graphics/BitmapFactory.html#decodeByteArray(byte[], int, int)) is used. I could see a slight improvement in speed but it is still insufficient.
What else can I try to boost up Bitmap loading in this situation?