titansgroup / k4l-video-trimmer

A library with UI and mechanisms to trim local videos on Android applications.
MIT License
784 stars 224 forks source link

Out of memory issue with large files #7

Open Sateesh2 opened 8 years ago

Sateesh2 commented 8 years ago

When I select a large file to trim, on clicking save app crashes with below log

FATAL EXCEPTION: pool-1-thread-1 Process: life.knowledge4.videocroppersample, PID: 32469 java.lang.OutOfMemoryError: Failed to allocate a 440786855 byte allocation with 11418026 free bytes and 239MB 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$1.hasNext(LazyList.java:55) at com.coremedia.iso.IsoFile.getMovieBox(IsoFile.java:102) at com.googlecode.mp4parser.authoring.container.mp4.MovieCreator.build(MovieCreator.java:51) at life.knowledge4.videotrimmer.utils.TrimVideoUtils.genVideoUsingMp4Parser(TrimVideoUtils.java:71) at life.knowledge4.videotrimmer.utils.TrimVideoUtils.startTrim(TrimVideoUtils.java:65) at life.knowledge4.videotrimmer.K4LVideoTrimmer$12.execute(K4LVideoTrimmer.java:362) at life.knowledge4.videotrimmer.utils.BackgroundExecutor$Task.run(BackgroundExecutor.java:212) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:154) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818)

kevalpatel2106 commented 7 years ago

Can you specify your device model and android version you have?

Sateesh2 commented 7 years ago

Hi, I was using OnePlus 2 and file size was more than 150 mb. Later I took your code and replaced mp4parser with ffmpeg and it worked fine.

On Sep 6, 2016 3:10 PM, "Keval Patel" notifications@github.com wrote:

Can you specify your device model and android version you have?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/knowledge4life/k4l-video-trimmer/issues/7#issuecomment-244900931, or mute the thread https://github.com/notifications/unsubscribe-auth/AGaFlHDuZxPx0FPIdgheDcO98eHBXXm3ks5qnTUCgaJpZM4JZgjf .

dogo commented 7 years ago

@Sateesh2 could you please propose a PR with those changes? they are really interesting

Sateesh2 commented 7 years ago

@dogo I just created PR with above-mentioned changes. Sorry for the late reply

ashishvirani29 commented 7 years ago

i have same issue please give solution.

Sateesh2 commented 7 years ago

Hi, Ashish, the reason for the out of memory issue is the latest mp4parser changes. So I took the current project and rolled back mp4parser to "com.googlecode.mp4parser:isoparser:1.1.7". You may need to update one or two lines in TrimVideoUtils class. Let me know if you are stuck.

kushmpatel commented 6 years ago

@Sateesh2 Hi I am facing the same problem. So can you please give me a code? I have changed my dependency from "com.googlecode.mp4parser:isoparser:1.1.20" to "com.googlecode.mp4parser:isoparser:1.1.7".

Sateesh2 commented 6 years ago

In TrimVideoUtils.java file go to genVideoUsingMp4Parser() method, in the first line of this method change FileDataSourceViaHeapImpl to FileDataSourceImpl.

anuj7sharma commented 5 years ago

Changing FileDataSourceViaHeapImpl to FileDataSourceImpl is not helping. Crash issue still persists.