sannies / mp4parser

A Java API to read, write and create MP4 files
Apache License 2.0
2.74k stars 563 forks source link

OutOfMemory on Android (With project to replicate) #377

Closed HBiSoft closed 4 years ago

HBiSoft commented 5 years ago

This issue has been posted multiple times, but non of them have actually provided a project and file that reproduces this issue #139 #151 #284 #299

I created a project that replicates this issue every time, here is the link (Latest version was used - 1.9.39):

https://github.com/HBiSoft/Mp4ParserOutOfMemory

and here is the file that can be used to reproduce the crash (VERY random video that was posted by another user that is experiencing this crash):

https://drive.google.com/file/d/1MQ3KGVNePta69s9xZu8mAm1qwliqkURq/view?usp=sharing

@sannies you mentioned that you stoped working on this issue when you couldn't reproduce the issue #139, by using my project and file you will definitely be able to reproduce the issue.

Here is the entire log, from selecting the file until the crash happens:

2019-06-02 09:42:01.497 2571-3706/com.HBiSoft.MyApp I/zygote: Starting a blocking GC Alloc
2019-06-02 09:42:01.497 2571-3706/com.HBiSoft.MyApp I/zygote: Starting a blocking GC Alloc
2019-06-02 09:42:01.572 2571-3706/com.HBiSoft.MyApp I/zygote: Alloc concurrent copying GC freed 24883(1177KB) AllocSpace objects, 11(664KB) LOS objects, 49% free, 4MB/8MB, paused 174us total 74.896ms
2019-06-02 09:42:01.572 2571-3706/com.HBiSoft.MyApp I/zygote: Starting a blocking GC Alloc
2019-06-02 09:42:01.645 2571-3706/com.HBiSoft.MyApp I/zygote: Alloc concurrent copying GC freed 2309(106KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 4MB/8MB, paused 206us total 72.936ms
2019-06-02 09:42:01.645 2571-3706/com.HBiSoft.MyApp I/zygote: Forcing collection of SoftReferences for 1GB allocation
2019-06-02 09:42:01.645 2571-3706/com.HBiSoft.MyApp I/zygote: Starting a blocking GC Alloc
2019-06-02 09:42:01.729 2571-3706/com.HBiSoft.MyApp I/zygote: Alloc concurrent copying GC freed 3158(158KB) AllocSpace objects, 1(16KB) LOS objects, 49% free, 3MB/7MB, paused 181us total 83.649ms
2019-06-02 09:42:01.729 2571-3706/com.HBiSoft.MyApp W/zygote: Throwing OutOfMemoryError "Failed to allocate a 1351044194 byte allocation with 4098855 free bytes and 508MB until OOM, max allowed footprint 8197711, growth limit 536870912"
2019-06-02 09:42:01.729 2571-3706/com.HBiSoft.MyApp I/zygote: Starting a blocking GC Alloc
2019-06-02 09:42:01.729 2571-3706/com.HBiSoft.MyApp I/zygote: Starting a blocking GC Alloc
2019-06-02 09:42:01.799 2571-3706/com.HBiSoft.MyApp I/zygote: Alloc concurrent copying GC freed 4(31KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 3MB/7MB, paused 199us total 69.731ms
2019-06-02 09:42:01.799 2571-3706/com.HBiSoft.MyApp I/zygote: Starting a blocking GC Alloc
2019-06-02 09:42:01.868 2571-3706/com.HBiSoft.MyApp I/zygote: Alloc concurrent copying GC freed 9(16KB) AllocSpace objects, 0(0B) LOS objects, 50% free, 3MB/7MB, paused 199us total 68.572ms
2019-06-02 09:42:01.868 2571-3706/com.HBiSoft.MyApp I/zygote: Forcing collection of SoftReferences for 1GB allocation
2019-06-02 09:42:01.868 2571-3706/com.HBiSoft.MyApp I/zygote: Starting a blocking GC Alloc
2019-06-02 09:42:01.948 2571-3706/com.HBiSoft.MyApp I/zygote: Alloc concurrent copying GC freed 28(16KB) AllocSpace objects, 0(0B) LOS objects, 50% free, 3MB/7MB, paused 183us total 79.496ms
2019-06-02 09:42:01.948 2571-3706/com.HBiSoft.MyApp W/zygote: Throwing OutOfMemoryError "Failed to allocate a 1351044200 byte allocation with 4098024 free bytes and 508MB until OOM, max allowed footprint 8196048, growth limit 536870912"
2019-06-02 09:42:01.951 2571-3706/com.HBiSoft.MyApp E/AndroidRuntime: FATAL EXCEPTION: PrepareAsnycWorker
Process: com.HBiSoft.MyApp, PID: 2571
java.lang.OutOfMemoryError: Failed to allocate a 1351044200 byte allocation with 4098024 free bytes and 508MB until OOM, max allowed footprint 8196048, growth limit 536870912
    at java.nio.HeapByteBuffer.<init>(HeapByteBuffer.java:54)
    at java.nio.HeapByteBuffer.<init>(HeapByteBuffer.java:49)
    at java.nio.ByteBuffer.allocate(ByteBuffer.java:261)
    at org.mp4parser.support.AbstractBox.parse(AbstractBox.java:96)
    at org.mp4parser.AbstractBoxParser.parseBox(AbstractBoxParser.java:115)
    at org.mp4parser.BasicContainer.initContainer(BasicContainer.java:107)
    at org.mp4parser.IsoFile.<init>(IsoFile.java:57)
    at org.mp4parser.IsoFile.<init>(IsoFile.java:52)
    at org.mp4parser.muxer.container.mp4.MovieCreator.build(MovieCreator.java:54)
    at org.mp4parser.muxer.container.mp4.MovieCreator.build(MovieCreator.java:39)
    at com.HBiSoft.MyApp.Player.MediaInfoExtractor.extract(MediaInfoExtractor.java:66)
    at com.HBiSoft.MyApp.Player.FramePlayer.prepareInternal(FramePlayer.java:402)
    at com.HBiSoft.MyApp.Player.FramePlayer.access$100(FramePlayer.java:21)
    at com.HBiSoft.MyApp.Player.FramePlayer$1.run(FramePlayer.java:200)
HBiSoft commented 5 years ago

I can confirm that this issue is not present in 1.1.7. Since posting this issue I haven't had any crashes.

I've tried all the versions after 1.1.7, so for now I will stick with 1.1.7.

talesbarretoss commented 5 years ago

Same problem here. I'm using version 1.9.39

Video file https://drive.google.com/open?id=1EX-EJvGAARsRXIb1PQutUTSyuk4mBegt

My code:

        val movie = MovieCreator.build(File(dstPath))

StackTrace:

E/flutter: [ERROR:flutter/shell/platform/android/platform_view_android_jni.cc(40)] java.lang.OutOfMemoryError: Failed to allocate a 2065855862 byte allocation with 16777216 free bytes and 158MB until OOM
        at java.nio.ByteBuffer.allocate(ByteBuffer.java:56)
        at org.mp4parser.support.AbstractBox.parse(AbstractBox.java:96)
        at org.mp4parser.AbstractBoxParser.parseBox(AbstractBoxParser.java:115)
        at org.mp4parser.BasicContainer.initContainer(BasicContainer.java:107)
        at org.mp4parser.IsoFile.<init>(IsoFile.java:57)
        at org.mp4parser.IsoFile.<init>(IsoFile.java:52)
        at org.mp4parser.muxer.container.mp4.MovieCreator.build(MovieCreator.java:54)
        at org.mp4parser.muxer.container.mp4.MovieCreator.build(MovieCreator.java:39)
HBiSoft commented 5 years ago

@talesbarretoss

I tried testing with your video, but I need permission..

Try version 1.1.7, I haven't had this issue since using it.

HBiSoft commented 5 years ago

@talesbarretoss

I just tested your video in my application running 1.1.7 and it's working fine. My device's video player can't open it, but my app can.

Screenshot_20190626-074551_ProGolf

talesbarretoss commented 5 years ago

Thank you @HBiSoft! We will keep version 1.1.7 for a while.