bytedeco/javacv
View on GitHubWith Limiting the memory,unknown error made the jvm crash.
Open
#2,308 opened on Dec 3, 2024
help wantedquestion
Description
Environment Info
Linux 81-228 5.15.0-122-generic
ldd (Ubuntu GLIBC 2.35-0ubuntu3.8) 2.35
Jvm Conf
-Dorg.bytedeco.javacpp.maxPhysicalBytes=4G -Dorg.bytedeco.javacpp.maxBytes=4G -Dorg.bytedeco.javacpp.noPointerGC=true -Dorg.bytedeco.javacpp.logger.debug=true -XX:+PreserveFramePointer
Crash Info
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007ff55263d770, pid=2934393, tid=0x00007ff5ec78d640
# OpenJDK Runtime Environment 8.0
Problematic frame:
# C [libavformat.so.60+0x1e4770] av_write_frame+0x140
--------------- T H R E A D ------------
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007efeba29dea0, pid=3069676, tid=0x00007efeb9dff640
#
# JRE version: OpenJDK Runtime Environment
# Java VM: OpenJDK 64-Bit Server VM
# Problematic frame:
# C [libswscale.so.7+0x36ea0]
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# If you would like to submit a bug report, please visit:
# https://github.com/adoptium/adoptium-support/issues
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
--------------- T H R E A D ---------------
Current thread (0x00007eff5c067000): JavaThread "pool-138-thread-1" [_thread_in_native, id=3075030, stack(0x00007efeb9d00000,0x00007efeb9e00000)]
siginfo: si_signo: 11 (SIGSEGV), si_code: 1 (SEGV_MAPERR), si_addr: 0x00007efeb6e1e012
Registers:
RAX=0x0000000000000458, RBX=0x00007efe9c8700c0, RCX=0x0000000000004087, RDX=0x00000000000020de
RSP=0x00007efeb9dfdf68, RBP=0x00007efe9cdbb4c0, RSI=0x0000000000000c88, RDI=0x0000000000001160
R8 =0x00007efeb6e1e010, R9 =0x0000000000000000, R10=0x00007efeb9dfe210, R11=0x00007efeb6e1e010
R12=0x00007efe9cf0e1c0, R13=0x00000000ffffecff, R14=0x0000000000000457, R15=0x00000000000009be
RIP=0x00007efeba29dea0, EFLAGS=0x0000000000010202, CSGSFS=0x002b000000000033, ERR=0x0000000000000004
TRAPNO=0x000000000000000e
Top of Stack: (sp=0x00007efeb9dfdf68)
0x00007efeb9dfdf68: 00007eff3021ef30 00007efeb6e1e010
0x00007efeb9dfdf78: 00007efe9cdbb4c0 00007efe9c8700c0
0x00007efeb9dfdf88: 0000000000000458 00000000000009be
0x00007efeb9dfdf98: 00007efeba2d0385 00000000000008b0
0x00007efeb9dfdfa8: 0000000000000458 0000000000001a10
0x00007efeb9dfdfb8: 00007eff3021ef30 0000000000000002
0x00007efeb9dfdfc8: 0000000000000040 00007eff30000030
0x00007efeb9dfdfd8: 00007eff301c70b0 00007efe9c8700c0
0x00007efeb9dfdfe8: 00007efeb6e1e010 00007efe9cdbb4c0
0x00007efeb9dfdff8: 00007efe9cf0e1c0 000009c0f9ed6d5c
0x00007efeb9dfe008: 00000458000008b0 000008b000001a10
0x00007efeb9dfe018: 0000000000000040 0000000000002360
0x00007efeb9dfe028: 0000000000000000 00007efeb9dfe200
0x00007efeb9dfe038: 00000000000009c0 00007eff30215500
0x00007efeb9dfe048: 00007efeb9dfe230 0000000000000000
0x00007efeb9dfe058: 00007efeba2afda1 00000000000008b0
0x00007efeb9dfe068: 0000000000000458 0000000000001a10
0x00007efeb9dfe078: 00007eff3021ef30 00007eff30061e40
0x00007efeb9dfe088: 00007efeb9dfe230 00007efeb9dfe210
0x00007efeb9dfe098: 0000000000000003 00000000000008b0
0x00007efeb9dfe0a8: 00007efeba2a15fe 00007efeb9dfe200
0x00007efeb9dfe0b8: 00007efeba2a14e3 00000000000fd3db
0x00007efeb9dfe0c8: 00007eff30215500 00007eff30061e40
0x00007efeb9dfe0d8: 00000000000009c0 00000458000009c0
0x00007efeb9dfe0e8: 0000000000000458 00000000000009c0
0x00007efeb9dfe0f8: 0000000000000001 00007efe00000002
0x00007efeb9dfe108: 00007efe000009c0 0000000000000000
0x00007efeb9dfe118: 0000000000000000 0000000000000000
0x00007efeb9dfe128: 00000000000009c0 00007efeb9dfe180
0x00007efeb9dfe138: 00007effe625dc28 00007eff30215500
0x00007efeb9dfe148: 00000000000008b0 00000000000009c0
0x00007efeb9dfe158: 00007eff5c067000 00000007c0af8258
Instructions: (pc=0x00007efeba29dea0)
0x00007efeba29de80: 8b 44 24 d8 4c 8b 44 24 b8 45 31 c9 85 c0 0f 8e
0x00007efeba29de90: 9c 01 00 00 4c 89 6c 24 d0 44 8b 6c 24 fc 66 90
0x00007efeba29dea0: 45 0f b6 58 02 41 0f b6 40 01 49 83 c0 06 8b 7c
0x00007efeba29deb0: 24 a0 45 0f b6 50 fa 45 89 df 45 0f af fd 0f af
Register to memory mapping:
RAX=0x0000000000000458 is an unknown value
RBX=0x00007efe9c8700c0 is an unknown value
RCX=0x0000000000004087 is an unknown value
RDX=0x00000000000020de is an unknown value
RSP=0x00007efeb9dfdf68 is pointing into the stack for thread: 0x00007eff5c067000
RBP=0x00007efe9cdbb4c0 is an unknown value
RSI=0x0000000000000c88 is an unknown value
RDI=0x0000000000001160 is an unknown value
R8 =0x00007efeb6e1e010 is an unknown value
R9 =0x0000000000000000 is an unknown value
R10=0x00007efeb9dfe210 is pointing into the stack for thread: 0x00007eff5c067000
R11=0x00007efeb6e1e010 is an unknown value
R12=0x00007efe9cf0e1c0 is an unknown value
R13=0x00000000ffffecff is an unknown value
R14=0x0000000000000457 is an unknown value
R15=0x00000000000009be is an unknown value
Stack: [0x00007efeb9d00000,0x00007efeb9e00000], sp=0x00007efeb9dfdf68, free space=1015k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [libswscale.so.7+0x36ea0]
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j org.bytedeco.ffmpeg.global.swscale.sws_scale(Lorg/bytedeco/ffmpeg/swscale/SwsContext;Lorg/bytedeco/javacpp/PointerPointer;Lorg/bytedeco/javacpp/IntPointer;IILorg/bytedeco/javacpp/PointerPointer;Lorg/bytedeco/javacpp/IntPointer;)I+0
j org.bytedeco.javacv.FFmpegFrameRecorder.recordImage(IIIIII[Ljava/nio/Buffer;)Z+637
j org.bytedeco.javacv.FFmpegFrameRecorder.record(Lorg/bytedeco/javacv/Frame;I)V+77
j org.bytedeco.javacv.FFmpegFrameRecorder.record(Lorg/bytedeco/javacv/Frame;)V+30
j com.xxxxxx.xxxxxx.xxxxxx.xxxxxx.record.FrameDataWriter.recordFrameToVideo(Lorg/bytedeco/javacv/Frame;)V+99
j com.xxxxxx.xxxxxx.xxxxxx.xxxxxx.record.FrameDataWriter.handleFrameByMode(Lorg/bytedeco/javacv/Frame;)V+42
j com.xxxxxx.xxxxxx.xxxxxx.xxxxxx.record.FrameDataWriter.playSuspendScenarios()V+183
j com.xxxxxx.xxxxxx.xxxxxx.xxxxxx.record.FrameDataWriter.handleOtherMode()V+53
j com.xxxxxx.xxxxxx.xxxxxx.xxxxxx.record.FrameDataWriter.run()V+114
j java.lang.Thread.run()V+11
j java.util.concurrent.ThreadPoolExecutor.runWorker(Ljava/util/concurrent/ThreadPoolExecutor$Worker;)V+95
j java.util.concurrent.ThreadPoolExecutor$Worker.run()V+5
j java.lang.Thread.run()V+11
v ~StubRoutines::call_stub
Running Code
public class FrameDataWriter implements Runnable {
private static final Logger LOGGER = LoggerProxy.getLogger(FrameDataWriter.class);
private static final String VIDEO_NAME = "video.mp4";
private static final int FRAME_RATE_VALUE = 60;
public static final int AV_CODEC_ID_H264 = 27;
private final String outputDir;
private final RecordingBean recordingBean;
private FFmpegFrameRecorder fFmpegFrameRecorder;
private FFmpegFrameGrabber frameGrabber;
private File binaryFile;
public FrameDataWriter(String serial, RecordingBean recordingBean) {
this.outputDir = recordingBean.getOutputDir();
this.recordingBean = recordingBean;
}
@Override
public void run() {
handleOtherMode();
}
private Logger logger() {
return LOGGER;
}
private void initGrabber() throws FFmpegFrameGrabber.Exception {
this.frameGrabber = new FFmpegFrameGrabber(binaryFile);
this.frameGrabber.setVideoCodec(AV_CODEC_ID_H264);
this.frameGrabber.setFrameRate(FRAME_RATE_VALUE);
frameGrabber.start(true);
}
private String addTag(String msg) {
return String.format(Locale.ENGLISH, "%s %s", recordingBean.getUuid(), msg);
}
private void handleFrameByMode() throws Exception {
initGrabber();
int count = 0;
for (;;) {
try (Frame frame = frameGrabber.grabFrame()) {
if (frame == null) {
break;
}
recordFrameToVideo(frame);
count++;
} catch (Exception e) {
logger().debug(addTag("Play dynamic scenarios to grab frame error:{}"), e);
}
}
logger().debug(addTag("Handle frame finished! And frame count is " + count));
}
public void handleOtherMode() {
long startTime = System.currentTimeMillis();
logger().debug(addTag("Intent to write, please wait!"));
this.binaryFile = recordingBean.getBinaryFile();
try {
handleFrameByMode();
} catch (Exception e) {
logger().error(addTag("Take frame error:{}"), e);
} finally {
tearDown();
long duration = System.currentTimeMillis() - startTime;
logger().debug(addTag("Write frame to file duration: {}ms"), duration);
}
}
private void recordFrameToVideo(Frame frame) throws Exception {
if (fFmpegFrameRecorder == null) {
int w = frame.imageWidth;
int h = frame.imageHeight;
if (w > 0 && h > 0) {
fFmpegFrameRecorder = new FFmpegFrameRecorder(new File(outputDir, VIDEO_NAME), frame.imageWidth,
frame.imageHeight);
fFmpegFrameRecorder.setFrameRate(FRAME_RATE_VALUE);
fFmpegFrameRecorder.setVideoCodec(AV_CODEC_ID_H264);
fFmpegFrameRecorder.start();
}
}
if (fFmpegFrameRecorder != null) {
fFmpegFrameRecorder.record(frame);
}
}
private void tearDown() {
try {
if (fFmpegFrameRecorder != null) {
fFmpegFrameRecorder.close();
fFmpegFrameRecorder = null;
}
if (frameGrabber != null) {
frameGrabber.close();
frameGrabber = null;
}
} catch (IOException e) {
logger().error(addTag("Frame teardown error:{}"), e);
} finally {
logger().info(addTag("H264 Writer finished!"));
}
}
}