wseemann / FFmpegMediaMetadataRetriever

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

App is crashing while extracting frames with FFmpeg #240

Closed ArtanBerisha1 closed 1 year ago

ArtanBerisha1 commented 3 years ago

I am using FFmpeg to extract frames from video in Android,

Gradle Dependencies:

    implementation 'com.github.wseemann:FFmpegMediaMetadataRetriever-core:1.0.15'
    implementation 'com.github.wseemann:FFmpegMediaMetadataRetriever-native:1.0.15'
for (index in 0 until number_of_frames_to_capture) {
      bitmap = retriever?.getFrameAtTime((index * (1000000 / frames_per_seconds)).toLong(), FFmpegMediaMetadataRetriever.OPTION_CLOSEST)
      if (bitmap != null) {
           saveImageInExternalDrive(bitmap, System.currentTimeMillis())
      }
}
retriever.release()

The OS is killing my app with the error: "I/Zygote: Process 9770 exited due to signal (9)" , that means there is a memory issue with my app. To extract 1 frame is taking around 1 second (and when I try to process a video with 3-6 min, it takes around 2 hours to finish the process, -> it fails as soon as it extracts around 1300 frames ) and I think this is the issue, so is this something that should happen or not ? Also I am not getting any other error so I don't know where the problem is exactly.

Den-Rimus commented 1 year ago

I second this. We are processing ~3000 short videos (2-12 seconds), extracting each frame with FPS of 3. Every video gets new instance of media extractor, at the end of the video we always call release().

But still memory grows and eventually app gets killed by system. We suspect native memory leak as this taken memory is invisible for GS and is not getting collected.

wseemann commented 1 year ago

Without seeing exactly how you are using the library it's not possible for me to determine if the leak is in my library or your code. In the instance of @ArtanBerisha1 code, he's not calling bitmap.recycle() after each iteration which could result in a OOM error. More so, it's likely taking more time than expected since he's performing an additional IO operation and writing the bitmap to disk for each iteration.

@Den-Rimus given that you just reported this issue today, and clearly would like my help debugging the issue, it seems strange that you would hop over to Stackoverflow and bash my library on an unrelated post before giving me a chance to respond or ask for more information. This library took several years to make, it's very complex, and I wrote it by myself. It's easy to sit behind a computer and be critical of someone else's work, but just remember, you have a job and companies like yours (ScanBot) make money off of hardworking people like myself. People that pour years of their free time into be something just for it to be met with constant criticism and dissatisfaction from people like yourself that contribute nothing back to the projects they use.

ArtanBerisha1 commented 1 year ago

Hi @wseemann , Since this was more than 2 years ago I can't remember exactly how I solved it but one thing for sure the issue wasn't on library side, it was on my part(probably smth with bitmaps), so I am guessing we can close this issue. (Forgot to close this at the time and write the fix of my issue)