所以我正在使用 JavaCV 并尝试从 mp4 文件中将帧捕获为图像。当我尝试保存图像并且无法在任何地方找到解决方案时,我不断收到 EXCEPTION_ACCESS_VIOLATION。OpenCV、JavaCV 和 Java 都是相同的位数 (64)。我还安装了 64 位 Visual C++。这是我正在使用的代码,任何想法是什么导致了这种情况或替代解决方案是什么。提前感谢您的帮助。
public class VideoTest {
public static void main(final String args[]) {
VideoTest vt = new VideoTest();
IplImage[] images = vt.extractVideoFrames("video.mp4");
int i = 1;
//Save images
for(IplImage image : images) {
/* Exception_ACCESS_VIOLATION occurs here */
cvSaveImage(Integer.toString(i) + ".jpg", image);
i++;
}
}
/* Extract at least 30 frames from the video at even intervals */
private IplImage[] extractVideoFrames(String videoName) {
FrameGrabber grabber = new FFmpegFrameGrabber(videoName);
try {
grabber.start();
} catch (com.googlecode.javacv.FrameGrabber.Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
double frameLength = grabber.getLengthInFrames();
int increment = (int) Math.ceil(frameLength / 30);
if (frameLength < 30) {
System.err.println("Not enough frames");
}
IplImage[] faceImgArr = new IplImage[30];
/* Ensure we don't go past end of video and get at least 30 frames */
for (int i = 0, j = 0; i < frameLength && j <= 30; i += increment, j++) {
try {
if ((grabber.getFrameNumber() % increment) == 0) {
faceImgArr[j] = grabber.grab();
} else {
grabber.grabFrame();
}
} catch (Exception e) {
System.err.println("Error grabbing frame");
}
}
return faceImgArr;
}
}
Error Message:
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000066de1630, pid=1328, tid=7016
#
# JRE version: 6.0_32-b05
# Java VM: Java HotSpot(TM) 64-Bit Server VM (20.7-b02 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C [opencv_ffmpeg242_64.dll+0x5a1630]
#
# An error report file with more information is saved as:
# C:\Users\name\workspace\Video\hs_err_pid1328.log
#
Snippet from log:
Stack: [0x0000000002900000,0x0000000002a00000], sp=0x00000000029fec30, free space=1019k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [opencv_ffmpeg242_64.dll+0x5a1630] cvWriteFrame_FFMPEG+0x59e2b0
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j com.googlecode.javacv.cpp.opencv_highgui.cvCreateFileCapture(Ljava/lang/String;)Lcom/googlecode/javacv/cpp/opencv_highgui$CvCapture;+0
j com.googlecode.javacv.OpenCVFrameGrabber.start()V+22
j main.recognition.VideoTest.extractVideoFrames(Ljava/lang/String;)[Lcom/googlecode/javacv/cpp/opencv_core$IplImage;+10
j main.recognition.VideoTest.main([Ljava/lang/String;)V+11
v ~StubRoutines::call_stub