Java 视频转换遇到问题及解决
Posted 程序媛一枚~
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java 视频转换遇到问题及解决相关的知识,希望对你有一定的参考价值。
Java 视频转换可能会遇到的问题及解决,很多报错都是没有引入 正确的依赖或者版本的问题(javacv版本及ffmpeg版本);
1. 正确的依赖
<!--ffmpeg依赖-->
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv</artifactId>
<version>1.5.1</version>
</dependency>
<!--windows ffmpeg-->
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>ffmpeg</artifactId>
<version>4.1.3-1.5.1</version>
<classifier>windows-x86_64</classifier>
</dependency>
<!--linux ffmpeg-->
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>ffmpeg</artifactId>
<version>4.1.3-1.5.1</version>
<classifier>linux-x86_64</classifier>
</dependency>
2. 遇到问题及解决
2.1 报错 Exception in thread “main” java.lang.NoClassDefFoundError: java.lang.ClassNotFoundException: org.bytedeco.ffmpeg.avutil
完整报错如下
Exception in thread "main" java.lang.NoClassDefFoundError: java.lang.ClassNotFoundException: org.bytedeco.ffmpeg.avutil
at org.bytedeco.javacpp.Loader.load(Loader.java:955)
at org.bytedeco.javacpp.Loader.load(Loader.java:907)
at com.demo.VideoConverter.ffmpegConvert2Mp4(VideoConverter.java:33)
at com.demo.VideoConverter.main(VideoConverter.java:121)
Caused by: java.lang.ClassNotFoundException: org.bytedeco.ffmpeg.avutil
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.bytedeco.javacpp.Loader.load(Loader.java:950)
... 3 more
<!--ffmpeg依赖-->
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv</artifactId>
<version>1.4.3</version>
</dependency>
<!--windows ffmpeg-->
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>ffmpeg</artifactId>
<version>4.1.3-1.5.1</version>
</dependency>
解决: pom依赖及版本问题 更换为上边正确的依赖
2.2 报错 Exception in thread “main” java.lang.UnsatisfiedLinkError: no jniavutil in java.library.path
完整报错如下
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jniavutil in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1483)
at org.bytedeco.javacpp.Loader.load(Loader.java:1186)
at org.bytedeco.javacpp.Loader.load(Loader.java:1036)
at org.bytedeco.ffmpeg.global.avutil.<clinit>(avutil.java:12)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.bytedeco.javacpp.Loader.load(Loader.java:1103)
at org.bytedeco.javacpp.Loader.load(Loader.java:1052)
at com.demo.VideoConverter.ffmpegConvert2Mp4(VideoConverter.java:33)
at com.demo.VideoConverter.main(VideoConverter.java:121)
Caused by: java.lang.UnsatisfiedLinkError: no avutil in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1483)
at org.bytedeco.javacpp.Loader.load(Loader.java:1137)
... 8 more
<!--ffmpeg依赖-->
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv</artifactId>
<version>1.5.1</version>
</dependency>
<!--windows ffmpeg-->
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>ffmpeg</artifactId>
<version>4.1.3-1.5.1</version>
</dependency>
解决: pom依赖及版本问题 更换为上边正确的依赖
2.3 报错 javacpp/cache/ffmpeg-5.0-1.5.7-linux-x86_64.jar/org/bytedeco/ffmpeg/linux-x86_64/libjniavdevice.so libasoud.so.2: cannot open shared object
解决: 安装libasoud.so
yum install alsa-lib-devel
2.4 报错 avacpp/cache/ffmpeg-4.2.2-1.5.3-linux-x86_64.jar/org/bytedeco/ffmpeg/linux-x86_64/libjniavdevice.so: libxcb.so.1: cannot open shared object file: No such file or directory
完整报错如下
caused by: java.lang.UnsatisfiedLinkError: java.lang.UnsatisfiedLinkError: /root/.javacpp/cache/ffmpeg-4.2.2-1.5.3-linux-x86_64.jar/org/bytedeco/ffmpeg/linux-x86_64/libjniavdevice.so: libxcb.so.1: cannot open shared object file: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1934)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1817)
at java.lang.Runtime.load0(Runtime.java:809)
at java.lang.System.load(System.java:1088)
at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1581)
... 18 more
解决: 安装libxcb.so
dnf/yum/apt-get install libxcb
参考
- https://blog.csdn.net/nankangkang/article/details/124352556
- https://github.com/bytedeco/javacv/issues/1431
以上是关于Java 视频转换遇到问题及解决的主要内容,如果未能解决你的问题,请参考以下文章