-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
OutOfMemoryException by FFMpegFrameGrabber #911
Comments
Others have noticed leaks as well. Would you have any profiler report to share?
|
I don't know how to see the profilers can you please help me with this? |
This is the code we are using for creating thumbnail. If we are doing
|
Any problem with this perticular code. I am debugging it but not able found.
|
Thanks for the code! It looks alright so, I guess there is a leak somewhere in native code, but someone is going to need to debug this... BTW, this is probably the same as issue #899. |
Is it a closed issue? If it is close issue. which version we need to upgrade. |
No, I've marked it as a duplicate issue and leaving this one open. |
Do we have any quick fix for this? |
If you don't mind using more memory, you can increase the threshold: |
Can I use this |
Yes, that works too.
|
Thanks :) 👍 |
Hi, Small question/clarification how come |
On Windows, for example, native memory allocation/deallocation are expensive operations, especially when a lot of garbage has accumulated, such that JavaCPP gives up trying to free memory and aborts. By restricting the total amount of memory available, garbage collection is performed more frequently, with less delay. This might be what is happening here. |
Oh thanks for the information :) |
BTW, the new |
Hi, I'm suffering from the same OutOfMemory issue. I tried using Here is the error: avformat_open_input() error -2: Could not open input "java.io.BufferedInputStream@7ff35a3f". (Has setFormat() been called?)
org.bytedeco.javacv.FrameGrabber$Exception: avformat_open_input() error -2: Could not open input "java.io.BufferedInputStream@7ff35a3f". (Has setFormat() been called?)
at org.bytedeco.javacv.FFmpegFrameGrabber.startUnsafe(FFmpegFrameGrabber.java:754)
at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:690) Here is my code: Short[] _getAudioFloatArrayFromFile(InputStream fileStream, int targetSampleRate) throws FrameGrabber.Exception {
try (PointerScope scope = new PointerScope()) {
ArrayList<Short> ret = new ArrayList<>();
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(fileStream);
grabber.setSampleFormat(1); // AV_SAMPLE_FMT_S16, signed 16 bits
grabber.setSampleRate(targetSampleRate);
grabber.setAudioChannels(1); // 1 channel mono audio
grabber.setFormat("m4a");
grabber.start();
Frame frame = grabber.grabSamples();
while (frame != null) {
if (frame.samples == null) {
break;
}
ShortBuffer channelSamplesShortBuffer = (ShortBuffer) frame.samples[0];
channelSamplesShortBuffer.rewind();
for (int i = 0; i < channelSamplesShortBuffer.remaining(); i++) {
ret.add(channelSamplesShortBuffer.get(i));
}
frame = grabber.grabSamples();
}
grabber.stop();
grabber.release();
return ret.toArray(new Short[0]);
}
} |
The callback objects are saved as static references, we'll need to add a null check for that... |
Thanks a lot for the quick solution @saudet ! Since I need this urgently, I attempted to use Any suggestions for how I can get around this? Thanks! |
We can use a dummy pom.xml file with Maven to download the artifacts, and
have sbt look in Maven's cache, similar to what is explained here:
https://deeplearning4j.org/android
|
@omarzouk If you're not able to get this working, just copy the new versions of source code itself of FFmpegFrameGrabber.java, etc to your project. |
@saudet thanks! I just created a dummy pom with javacv-platform as dependency, and uploaded a fat jar with all dependencies to our company's internal nexus. This way SBT can just download the fat jar, and it will have everything. |
I think |
@saudet I am still facing the memory leak issue, when i am converting image to video using FFmpegFrameRecorder in while(true) loop |
@gudduIgn You'll need to provide some details about what you're doing if you expect someone to help! |
Hi saudet. How do I limit the maximum memory used by javacv? thanks |
@duck123456 Set the "org.bytedeco.javacpp.maxphysicalbytes" system property: |
if Set the "org.bytedeco.javacpp.maxphysicalbytes" system property:,it will error occurred java.lang.OutOfMemoryError: Physical memory usage is too high: physicalBytes (10990M) > maxPhysicalBytes (10923M) |
It needs to set before calling anything else. |
static{ |
What does Pointer.maxPhysicalBytes() return?
|
yes With the return |
|
Can you send a pull request?
|
Both the buffer and the context are properly freed here, so I'm not sure what you want to fix: |
yes ,avio_alloc_context is no problem ,if use inputStream this no to close avformat_close_input |
it need to avformat_close_input(oc); Otherwise, memory leaks will occur |
no,Just use it avformat_free_context still can't release it,you can try it |
Ok, so please send a pull request with the proposed changes! I can't guess what you want to do here. |
Ok, I'll test it again, and if it's ok, I'll pull request |
I get repeatedly this error when loading high resolution (4K) and long videos. The execution hangs at the instruction
This does not happen with a short 4K video (about 10s). I already tried to set the --- EDIT Source video is passed with the instructions
|
If you don't need to seek within the InputStream, make sure to disable seeking. |
I only need to analyze an mp4 video (800mb+) frame by frame. What do you mean by disabling seeking? This is my code val inputVideo = contentResolver.openInputStream(mSelectedFileUri!!)
val grabber = FFmpegFrameGrabber(inputVideo)
grabber.format = "mp4"
grabber.start()
var currentFrame = grabber.grabFrame(false, true, false, false)
while (currentFrame != null) {
// perform frame processing
Thread.sleep(300)
mParsingFrameNumber += 1
currentFrame = grabber.grab()
} And hangs at Sorry for my dumb questions but I really cannot figure this out. Thank you for your availability |
As per issue #1304, set the |
If I do so,
I am using as dependency
|
So your format needs some seeking capabilities. You can try to set a small value for |
…meGrabber.release()` (issue #911) * Upgrade dependencies for Leptonica 1.79.0
I think I've fixed all the memory leaks occurring in |
May I ask which version of this memory leak problem began to appear? |
We are using FFMpegFrameGrabber for
creating thumbnails out of videos
.We are facing
OutOfMemoryException
Like below.. Thanks in advance.
The text was updated successfully, but these errors were encountered: