Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OutOfMemoryError: Failed to allocate memory within limits #15

Open
Ggsdl opened this issue Jan 15, 2017 · 11 comments
Open

OutOfMemoryError: Failed to allocate memory within limits #15

Ggsdl opened this issue Jan 15, 2017 · 11 comments
Labels

Comments

@Ggsdl
Copy link

Ggsdl commented Jan 15, 2017

Dear CrazyOrr:
I use this Project, after recording 1 minutes will be crash, the reason is java.lang.OutOfMemoryError: Failed to allocate memory within limits: totalBytes = 255M + 112K > maxBytes = 256M
do you have some good suggestions to correct this error
Thanks very much

@CrazyOrr
Copy link
Owner

You can set PREFERRED_PREVIEW_WIDTH and PREFERRED_PREVIEW_HEIGHT to smaller values to try to get a smaller preview size to reduce the memory allocation of it.

@Ggsdl
Copy link
Author

Ggsdl commented Jan 18, 2017

Thank you for your reply, I try to set PREFERRED_PREVIEW_WIDTH and PREFERRED_PREVIEW_HEIGHT to smaller like this :
private static final int PREFERRED_PREVIEW_WIDTH = 320; private static final int PREFERRED_PREVIEW_HEIGHT = 240;

But it also crash at 1-2 minutes .
Now , i want record a 10 minutes Video, if use your code , do you have some good suggestions to correct this error ?
Thanks very much

@CrazyOrr
Copy link
Owner

It could be memory leaks.
If you use Android Studio, you can monitor memory usage by View -> Tool Windows -> Android Monitor -> Monitors tab. If you observe that the Allocated memory size gets larger and larger over time, you should Dump Java Heap and do Allocation Tracking to find out what is taking all the memory.

@Ggsdl
Copy link
Author

Ggsdl commented Jan 19, 2017

I try to find memory leaks , but not find, can you help me to find this ? I just use your project only change the MAX_VIDEO_LENGTH to 10 minutes, Thanks !

@CrazyOrr
Copy link
Owner

It works fine on my device. Please provide more info about your testing environment (device model, Android version etc) and upload error logs, .hprof, .alloc files around the crash point.

@Ggsdl
Copy link
Author

Ggsdl commented Jan 19, 2017

error log is like this , my device is samsung ,android version is 5.0.1
01-19 10:38:02.442 22665-22873/com.github.crazyorr.ffmpegrecorder E/AndroidRuntime: FATAL EXCEPTION: Thread-17822 Process: com.github.crazyorr.ffmpegrecorder, PID: 22665 java.lang.OutOfMemoryError: Failed to allocate memory within limits: totalBytes = 255M + 600K > maxBytes = 256M at org.bytedeco.javacpp.Pointer.deallocator(Pointer.java:558) at org.bytedeco.javacpp.Pointer.init(Pointer.java:121) at org.bytedeco.javacpp.BytePointer.allocateArray(Native Method) at org.bytedeco.javacpp.BytePointer.<init>(BytePointer.java:82) at org.bytedeco.javacv.FFmpegFrameFilter.pushImage(FFmpegFrameFilter.java:265) at org.bytedeco.javacv.FFmpegFrameFilter.push(FFmpegFrameFilter.java:252) at org.bytedeco.javacv.FFmpegFrameFilter.push(FFmpegFrameFilter.java:248) at com.github.crazyorr.ffmpegrecorder.FFmpegRecordActivity$VideoRecordThread.run(FFmpegRecordActivity.java:702)

@Ggsdl
Copy link
Author

Ggsdl commented Jan 19, 2017

It just point in project file : FFmpegRecordActivity this line frameFilter.push(recordedFrame.getFrame());

@CrazyOrr
Copy link
Owner

This could be a bug upstream. See this issue.
You can try set android:largeHeap to true for now.

@Ggsdl
Copy link
Author

Ggsdl commented Jan 19, 2017

I set android:largeHeap to true ,but It does't work also , I see the Monitors ,this project works hightest memory is 50MB, then it crash,reason is :
01-19 17:35:19.502 31298-31597/com.github.crazyorr.ffmpegrecorder E/AndroidRuntime: FATAL EXCEPTION: Thread-24881 Process: com.github.crazyorr.ffmpegrecorder, PID: 31298 java.lang.OutOfMemoryError: Failed to allocate memory within limits: totalBytes = 511M + 600K > maxBytes = 512M at org.bytedeco.javacpp.Pointer.deallocator(Pointer.java:558) at org.bytedeco.javacpp.Pointer.init(Pointer.java:121) at org.bytedeco.javacpp.BytePointer.allocateArray(Native Method) at org.bytedeco.javacpp.BytePointer.<init>(BytePointer.java:82) at org.bytedeco.javacv.FFmpegFrameFilter.pushImage(FFmpegFrameFilter.java:265) at org.bytedeco.javacv.FFmpegFrameFilter.push(FFmpegFrameFilter.java:252) at org.bytedeco.javacv.FFmpegFrameFilter.push(FFmpegFrameFilter.java:248) at com.github.crazyorr.ffmpegrecorder.FFmpegRecordActivity$VideoRecordThread.run(FFmpegRecordActivity.java:702)

@CrazyOrr
Copy link
Owner

Check if org.bytedeco.javacpp.DeallocatorThread is working properly.

@CrazyOrr
Copy link
Owner

@Ggsdl @LoginGit
I added capacity restraints on frame queues (mFrameToRecordQueue and mRecycledFrameQueue) in the latest commit. So the queues won't increase infinitely to the point of OOM, but frames may get dropped when a queue is full, so video quality may suffer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants