bytedeco / javacv

Java interface to OpenCV, FFmpeg, and more
Other
7.42k stars 1.57k forks source link

JVM crash error #2070

Open jetamie opened 11 months ago

jetamie commented 11 months ago

Pseudocode

public class Demo {
private final static OpenCVFrameConverter.ToMat converter = new OpenCVFrameConverter.ToMat();
public static void main(String[] args) throws Exception {
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("test.mp4")
grabber.start();
Frame img = null;
while((img = grabber.grabImage()) !=null ) {
Mat mat = converter.convert(img);
//todo do something
}
}
}

description

It worked very well at first, and I would repeat this logic over and over again, and immediately after a while, the JVM crashed, and here is the screenshot

screenshots

saudet commented 11 months ago

Please call grabber.stop() at the end.

jetamie commented 11 months ago

Please call grabber.stop() at the end.

Sorry, I didn't write completely above, I used grabber.restart()

jetamie commented 11 months ago

Please call grabber.stop() at the end.

Do I need to reinitialize the ToMat object?

saudet commented 11 months ago

restart() might not always work. Try not to use it see if it works.

jetamie commented 11 months ago

restart() might not always work. Try not to use it see if it works.

I need to read video frames in a loop, similar to FFmpeg's --loop parameter function

saudet commented 10 months ago

Creating multiple instances of FFmpegFrameGrabber should do what you need.