java - 错误 com.xuggle.ferry.JNILibraryLoader - 无法加载库 : xuggle-xuggler; version: 3;

标签 java xuggler

我最近从 this link 下载了 Xuggler 教程:帧捕获和视频创建 的代码。 ,我已经在我的项目中添加了运行此代码所需的所有 .jar 文件,但是,当我运行此代码时,出现错误:

这是我的代码:

package xug;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import com.xuggle.mediatool.IMediaReader;
import com.xuggle.mediatool.MediaListenerAdapter;
import com.xuggle.mediatool.ToolFactory;
import com.xuggle.mediatool.event.IVideoPictureEvent;
import com.xuggle.xuggler.Global;

public class VideoThumbnailsExample {

    public static final double SECONDS_BETWEEN_FRAMES = 10;
    private static final String inputFilename = "e:/low_light.mp4";
    private static final String outputFilePrefix = "e:/Frames/processedImages";
    // The video stream index, used to ensure we display frames from one and
    // only one video stream from the media container.
    private static int mVideoStreamIndex = -1;
    // Time of last frame write
    private static long mLastPtsWrite = Global.NO_PTS;
    public static final long MICRO_SECONDS_BETWEEN_FRAMES =
            (long) (Global.DEFAULT_PTS_PER_SECOND * SECONDS_BETWEEN_FRAMES);

    public static void main(String[] args) {

        IMediaReader mediaReader = ToolFactory.makeReader(inputFilename);

        // stipulate that we want BufferedImages created in BGR 24bit color space
        mediaReader.setBufferedImageTypeToGenerate(BufferedImage.TYPE_3BYTE_BGR);

        mediaReader.addListener(new ImageSnapListener());

        // read out the contents of the media file and
        // dispatch events to the attached listener
        while (mediaReader.readPacket() == null) ;

    }

    private static class ImageSnapListener extends MediaListenerAdapter {

        public void onVideoPicture(IVideoPictureEvent event) {

            if (event.getStreamIndex() != mVideoStreamIndex) {
                // if the selected video stream id is not yet set, go ahead an
                // select this lucky video stream
                if (mVideoStreamIndex == -1) {
                    mVideoStreamIndex = event.getStreamIndex();
                } // no need to show frames from this video stream
                else {
                    return;
                }
            }

            // if uninitialized, back date mLastPtsWrite to get the very first frame
            if (mLastPtsWrite == Global.NO_PTS) {
                mLastPtsWrite = event.getTimeStamp() - MICRO_SECONDS_BETWEEN_FRAMES;
            }

            // if it's time to write the next frame
            if (event.getTimeStamp() - mLastPtsWrite
                    >= MICRO_SECONDS_BETWEEN_FRAMES) {

                String outputFilename = dumpImageToFile(event.getImage());

                // indicate file written
                double seconds = ((double) event.getTimeStamp())
                        / Global.DEFAULT_PTS_PER_SECOND;
                System.out.printf(
                        "at elapsed time of %6.3f seconds wrote: %s\n",
                        seconds, outputFilename);

                // update last write time
                mLastPtsWrite += MICRO_SECONDS_BETWEEN_FRAMES;
            }

        }

        private String dumpImageToFile(BufferedImage image) {
            try {
                String outputFilename = outputFilePrefix
                        + System.currentTimeMillis() + ".png";
                ImageIO.write(image, "png", new File(outputFilename));
                return outputFilename;
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        }
    }
}

我在这方面遇到了以下错误。

[main] ERROR com.xuggle.ferry.JNILibraryLoader - Could not load library: xuggle-xuggler; version: 3; Visit http://www.xuggle.com/xuggler/faq/ to find common solutions to this problem
java.lang.UnsatisfiedLinkError: no xuggle-xuggler in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860)
    at java.lang.Runtime.loadLibrary0(Runtime.java:845)
    at java.lang.System.loadLibrary(System.java:1084)
    at com.xuggle.ferry.JNILibraryLoader.loadLibrary0(JNILibraryLoader.java:265)
    at com.xuggle.ferry.JNILibraryLoader.loadLibrary(JNILibraryLoader.java:168)
    at com.xuggle.xuggler.XugglerJNI.<clinit>(XugglerJNI.java:19)
    at com.xuggle.xuggler.Global.<clinit>(Global.java:238)
    at xug.VideoThumbnailsExample.<clinit>(VideoThumbnailsExample.java:28)
Exception in thread "main" Java Result: 1

请解释为什么 Class-Loader 无法加载 .jar 文件。

最佳答案

您遇到的问题是无法找到 Xuggle 使用的 native 库。我怀疑您的类路径中存在冲突。

如果“所有 jar”是指下载页面中的 jar,则不应下载所有这些。在 Xuggler downloads page它表示要么下载包含所有操作系统的 native 库的 xuggle‑xuggler.jar,要么选择特定的体系结构。

在尝试运行您链接到的示例时,我做了以下操作:

  • 已下载 xuggle‑xuggler.jar (第 5.2 节)。我没有使用 Maven,所以根据下载页面上的说明,我打开了 Xuggle POM file使用特定版本检查并获取依赖项。
  • 使用 google 的一些帮助,这些依赖项是:slf4j-1.6.4 , commons-cli 1.1 , logback 1.0 ,(包含两个所需的 jar ),xuggle-utils 1.20和你可以忽略的 junit
    下载后,您可以在 zip 文件中找到 5 个 jar(slf4j-api-1.6.4.jar、commons-cli-1.1.jar、logback-core-1.0.0.jar、logback-classic-1.0.jar)。 0.jar、xuggle-utils-1.20.688.jar)在 POM 文件中描述为 xuggle‑xuggler.jar 的依赖项。
  • 在您最喜欢的 IDE(我使用 Eclipse)中创建一个项目,将这 6 个 jar 文件导入到您的项目中,您就可以开始了。

按照上述步骤,我能够在 Windows 机器上成功运行您的测试程序。

希望对您有所帮助。

关于java - 错误 com.xuggle.ferry.JNILibraryLoader - 无法加载库 : xuggle-xuggler; version: 3;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18077307/

相关文章:

java - 匹配部分字符串以恢复密码

java - Xuggler 是否有更高级别的 API?

ffmpeg - 使用 libspeex 为 Raspberry pi 编译 Xuggler 时出现问题 #1

java - 使用 Xuggler 通过 Java 检测网络摄像头

java - Xuggler/Java 视频缩略图

java - 在java中将颜色转换为rgb值

java - 使用配置单元出现异常 java.lang.NoClassDefFoundError : org/apache/tez/dag/api/SessionNotRunning

java - 如何将多个字段分配为实体的主键(使用 JPA)

java - 依赖 CORS 处理 Java EE 7 Server API 中未捕获的异常

java - 使用 xuggler 从图片创建 mp4 和 java mp3