Reputation: 2481
I'm creating an app which needs to show a series of Bitmap
s of a video's frames. The app uses MediaCodec
to decode a video into a number of frames and gets Bitmap
s 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 Bitmap
s that need to be displayed right now or soon. Basically I've been trying these methods.
Bitmap
s in advance.It's fast enough to meet my need but as mentioned the app crashes when the number of Bitmap
s exceed 60~65.
JPEG
file and load specific JPEG
s into Bitmap
s when needed.I used BitmapFactory.decodeFile
to load a Bitmap
from a JPEG
, but it was slow.
MJPEG
file and load specific "frame" (technically the byte array) into Bitmap
s 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 Bitmap
s 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?
Upvotes: 2
Views: 4842
Reputation: 8962
For your algorithm, some libraries such as Glide and Picasso can handle that for you. As for the encoding/decoding speed, JPEG is probably your best bet at quickly flushing the Bitmap to disk because the file size is small and it could be backed by hardware.
Some things you can try
android:largeHeap=true
to manifest so you have memory to work withIf you want, manually compiling your jpeg library for your specific needs are possible but that would require non trivial work. Here's something you can test right now.
Upvotes: 3
Reputation: 798
You have a few options, and your caching idea is smart. Off the top of my mind, here are a few things to try:
Upvotes: 2