wseemann / FFmpegMediaMetadataRetriever

FFmpegMediaMetadataRetriever provides a unified interface for retrieving frame and meta data from an input media file.
1.73k stars 387 forks source link

Native Memory Leak in Android #189

Open jamesguoxin opened 6 years ago

jamesguoxin commented 6 years ago

We are using this code to load video and process frames with OpenCV. A simple example is as following:

FFmpegMediaMetadataRetriever mmr = new FFmpegMediaMetadataRetriever(); mmr.setDataSource(mUri); mmr.release();

Then we start to process one thousand videos to test our mobile algorithm, but according to Android Profiler, the native memory goes to infinity and our app crushed after a few runs. We suspect that FFmpegMediaMetadataRetriever release method doesn't work as it expected. We've tried to pinpoint the exact problem, however, we didn't have a clue. It would be much appreciated if anyone could land a hand. Thanks!!!!

dancingpipi commented 5 years ago

I met this error too, if you solve it , please help me ~

HBiSoft commented 5 years ago

I think it could be that you're not waiting for the process to finish before releasing it and starting it again. Use an AsyncTask then in onPostExecute release FFmpegMediaMetadataRetriever then pass the next path until completed.

When you call FFmpegMediaMetadataRetriever repeatedly without waiting for processes to finish will cause out of memory exception (memory leak).

RowlandOti commented 4 years ago

How is it possible to know when it has completed, in a for loop of items to process? How is the stup of the AsyncTask? Considering, am already doing this heavy work in a background thread, but it still seems to hog onto memory the more items I have in the list to process.

RowlandOti commented 4 years ago

I conclude that since the object des did not have a Singleton, it will lead to several of class objects created having different instances. This would quickly lead to OOM.