mp4parser: OutOfMemoryError when building Movie
After upgrading from 1.1.7 to later versions, OutOfMemoryError happens on MovieCreator.build() I think it’s related with removing deferred mapping.
Log from 1.1.14
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 788249407 byte allocation with 16769200 free bytes and 477MB until OOM
at java.nio.ByteBuffer.allocate(ByteBuffer.java:56)
at com.googlecode.mp4parser.AbstractBox.parse(AbstractBox.java:110)
at com.coremedia.iso.AbstractBoxParser.parseBox(AbstractBoxParser.java:107)
at com.googlecode.mp4parser.BasicContainer.next(BasicContainer.java:185)
at com.googlecode.mp4parser.BasicContainer.hasNext(BasicContainer.java:161)
at com.googlecode.mp4parser.util.LazyList.blowup(LazyList.java:30)
at com.googlecode.mp4parser.util.LazyList.size(LazyList.java:77)
at com.googlecode.mp4parser.BasicContainer.getBoxes(BasicContainer.java:80)
at com.googlecode.mp4parser.authoring.samples.DefaultMp4SampleList.<init>(DefaultMp4SampleList.java:36)
at com.coremedia.iso.boxes.mdat.SampleList.<init>(SampleList.java:33)
at com.googlecode.mp4parser.authoring.Mp4TrackImpl.<init>(Mp4TrackImpl.java:62)
at com.googlecode.mp4parser.authoring.container.mp4.MovieCreator.build(MovieCreator.java:57)
at com.googlecode.mp4parser.authoring.container.mp4.MovieCreator.build(MovieCreator.java:38)
Here is the Video with problem Video is made from android, and I’m not familiar with MP4 format, but seems like box header? is not correct, but it work well with 1.1.7 Thank you.
About this issue
- Original URL
- State: open
- Created 9 years ago
- Reactions: 11
- Comments: 31 (5 by maintainers)
Attention everyone~: I just encountered this problem! It is so weird that mp4parser will allocate so much memory which the .mp4 file really do not need. After lots of tests, I notice that my own problem is origin from the .mp4 file itself! My file is created by myself on Android, I record the video to an .mp4 file by overriding an old file which name is the same as my new file. In this situation, maybe google code treat the file as usual then bug appears. So maybe the file is a bad one I think. My final solution is delete the old file before creating an new file, and in this case, the bug disappeared…
I ran into this last year. It’s extremely frustrating and it seems very obvious what the problem is - the code simply tries to create an enormous buffer. Please look at bogru’s comments above. He tracked down the precise commit where it was introduced. I used some of the code he posted here https://github.com/sannies/mp4parser/issues/205 to work around the problem. I have a hard time understanding why sannies is unable to reproduce this. I offered to provide a sample (the account brooksrbrown above), but he did not respond. I wish that he would take a good look at this problem. It is entirely fixable.
You can clone the Git repo, and install to your machine’s local Maven repository using the “install” Maven task in the mp4parser project.
Then in your application’s Gradle file: