在CentOS中,使用javacpp调用FFmpeg进行视频裁剪一帧,在我自己的开发机器上使用这段代码没问题,但是在centos6中报了NoClassDefFound:无法初始化类org.bytedeco.javacpp.avutil
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.javacpp.avformat$AVFormatContext
at org.bytedeco.javacv.FFmpegFrameGrabber.startUnsafe(FFmpegFrameGrabber.java:383) ~[javacv-1.0.jar:1.0]
at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:377) ~[javacv-1.0.jar:1.0]
at cn.xxtui.support.upload.BasicUpload.convertImage(BasicUpload.java:211) ~[classes/:?]
at cn.xxtui.support.upload.BasicUpload.upload(BasicUpload.java:197) ~[classes/:?]
at cn.com.ql.wiseBeijing.upload.UploadImage.upload(UploadImage.java:144) ~[classes/:?]
at cn.com.ql.wiseBeijing.upload.UploadImage.imageCategory(UploadImage.java:51) ~[classes/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_25]
at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_25]
at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:180) ~[cxf-core-3.1.12.jar:3.1.12]
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96) ~[cxf-core-3.1.12.jar:3.1.12]
... 37 more
这是我的pom配置:
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacpp</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.github.hoary.ffmpeg</groupId>
<artifactId>FFmpeg-linux-x86_64</artifactId>
<version>2.0.1.1
</version>
</dependency>
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>ffmpeg</artifactId>
<version>2.7.1-1.0</version>
</dependency>
这是我的代码:
public String convertImage(String filePath, String imagePath) throws IOException, FrameGrabber.Exception {
FFmpegFrameGrabber g = new FFmpegFrameGrabber(filePath);
g.start();
Java2DFrameConverter java2DFrameConverter = new Java2DFrameConverter();
BufferedImage bufferedImage = java2DFrameConverter.convert(g.grabImage());
String path = imagePath + System.currentTimeMillis() + ".png";
ImageIO.write(bufferedImage, "png", new File(path));
g.stop();
return path;
}
答案 0 :(得分:0)
确保您的计算机上安装了所有需要的库。 在这种情况下,“javacv-platform”。
这就是提示在这个方向上思考的原因:
java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.javacpp.avformat$AVFormatContext
“NoClassDefFound”几乎总是意味着缺少必要的东西。