-
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
Grabber is at a risk of crashing #1960
Comments
Why? What's special about that pixel format? |
I don't know the exact reason either. After many tests, I found that as long as this pixel format is set, the program will crash when the close method is called. |
Could you provide a small self-contained example to reproduce this issue? |
I also found the same problem when using the AV_PIX_FMT_RGBA. Seems any 32 bit format would cause a JVM crash. public class DemoAVFreeCrash {
public static void main(String[] args) throws Exception {
IntStream.range(0, 10).forEach(i -> {
System.out.println("Starting grabber: times=" + i);
try (FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(new FileInputStream(new File("C:\\Users\\user\\Desktop\\video.webm")))) {
grabber.setPixelFormat(avutil.AV_PIX_FMT_RGBA);
grabber.start();
// Grab a Frame and properly close it
try (Frame frame = grabber.grabImage()) {
System.out.println("Frame grabbed: " + frame.timestamp);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println("Finnaly reached!");
}
System.out.println("Closed grabber successfully: times=" + i);
});
}
} And the output is:
It never completes more than 2-3 iterations. Always is failing when freeing the frame av_free(image_ptr[i]); Do you have any idea on why the pixel format with 32 bit could produce this issue? Thanks in advance for your awesome library! |
Please try again with the snapshots: http://bytedeco.org/builds/ |
I've run the same sample code with current 1.5.10-SNAPSHOT. Unfortunately the result was even worse, now I never can finish one iteration. I always get this output:
Again, the issue only appears when using 32 bit pixel format (AV_PIX_FMT_RGBA, AV_PIX_FMT_BGRA, ...) |
I'm not able to reproduce this here. The code above works fine for me with 1.5.10-SNAPSHOT |
Seems the issue is also very related to the video dimensions. I can reproduce it with the following video of 422x194: Maybe it is related to a memory alignment issue or something. |
It's possible. There used to be a bug in FFmpeg requiring this hack: |
Yes, I've already checked that issue. Removing this does not fix it, seems this workaround is still necessary but it's only working when using 24 bit pixel formats like RGB24. I found a new workaround setting the linesize alignment to 64 instead of 32. I've stress tested all a bunch of videos with pixel format RGBA and 64 alignment and now is working as expected. This solution is not nice because of a waste of memory, but it works for me. Thanks @saudet for your support! |
Sounds like a good enough workaround though. Please open a pull request! |
Is setting grabber.setPixelFormat(AV_PIX_FMT_BGRA64LE) the solution to this problem? |
…unaligned width (issue #1960) * Upgrade dependencies for OpenBLAS 0.3.25
…unaligned width (issue #1960) * Upgrade dependencies for OpenBLAS 0.3.25
@CJL6015 No, I've pushed @davepiar's fix. Please give it a try with the snapshots: http://bytedeco.org/builds/ |
@saudet Thank you for your reply |
Fix released with version 1.5.10. Thanks for reporting! |
There is a risk of crash when the grabber restarts and closes, if the pixel format is set to BGRA
grabber.setPixelFormat(avutil.AV_PIX_FMT_BGRA)
The text was updated successfully, but these errors were encountered: