javacv
javacv copied to clipboard
JVM crash in docker container
A JVM crash occurred when I extracted the webm video and mp4 video frame by frame, and then merged and recorded them into a new video.This error only occurs when the program is deployed in a docker container and has never appeared on Windows. Here is my code `String inputWebmFile = "C:\Users\viruser.v-desktop\Desktop\1webm.mp4"; String inputMp4File = "C:\Users\viruser.v-desktop\Desktop\1mp4.mp4"; String outputMp4File = "output.mp4";
FFmpegFrameGrabber grabberMp4 = new FFmpegFrameGrabber(inputMp4File);
grabberMp4.setPixelFormat(AV_PIX_FMT_RGBA);
grabberMp4.setVideoCodec(avcodec.AV_CODEC_ID_H264);
FFmpegFrameGrabber grabberWebm = new FFmpegFrameGrabber(inputWebmFile);
grabberWebm.setVideoCodecName("libvpx-vp9");
grabberWebm.setPixelFormat(AV_PIX_FMT_BGRA);
try (OpenCVFrameConverter.ToMat webmConverter = new OpenCVFrameConverter.ToMat();
OpenCVFrameConverter.ToMat mp4Converter = new OpenCVFrameConverter.ToMat();) {
grabberMp4.start();
grabberWebm.start();
FrameRecorder recorder = new FFmpegFrameRecorder(outputMp4File, grabberMp4.getImageWidth(), grabberMp4.getImageHeight());
recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
recorder.setVideoBitrate(grabberMp4.getVideoBitrate());
recorder.setFrameRate(grabberMp4.getFrameRate());
recorder.setFormat("mp4");
recorder.start();
Frame frameMp4;
Frame frameWebm;
while ((frameMp4 = grabberMp4.grabImage()) != null) {
frameWebm = grabberWebm.grabImage();
Mat matMp4 = mp4Converter.convert(frameMp4);
if (matMp4 == null) {
continue;
}
Mat matWebm = webmConverter.convert(frameWebm);
while (Objects.isNull(matWebm) && (frameWebm = grabberWebm.grabImage()) != null) {
matWebm = webmConverter.convert(frameWebm);
}
opencv_imgproc.resize(matWebm, matWebm, new Size(300, 300));
Rect roi = new Rect(0, 0, 300, 300);
Mat back = new Mat(matMp4, roi);
matWebm.copyTo(back, matWebm);
Frame convert = webmConverter.convert(matMp4);
recorder.record(convert);
back.close();
}
grabberMp4.close();
grabberWebm.close();
recorder.close();
} catch (FrameGrabber.Exception | FrameRecorder.Exception e) {
e.printStackTrace();
}`
Here is the log
Please try again with JavaCV 1.5.9.
Please try again with JavaCV 1.5.9.
The crash problem still exists in version 1.5.9. The crash probability will be reduced without closing grabber and recorder, but in this way the memory will continue to grow until it overflows.
Please give it a try with JavaCV 1.5.10-SNAPSHOT: http://bytedeco.org/builds/