3

我最近从这个链接下载了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文件。

4

4 回答 4

4

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

如果“所有 jars”是指下载页面中的 jars,则不应下载所有这些 jars。在Xuggler 下载页面上,它说要么下载xuggle‑xuggler.jar包含所有操作系统的本机库,要么选择特定架构。

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

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

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

我希望这会有所帮助。

于 2013-08-08T23:36:34.010 回答
0

看起来最好的解决方案是使用带有 maven 的 Xuggler 5.4,因为我必须如何安装/配置 Xuggle 才不会得到 UnsatisfiedLinkError?

于 2014-10-23T13:27:19.597 回答
0

按照cs的回答,这对我有用:

  • 而不是 xuggle‑xuggler.jar 使用xuggle-xuggler-5.4.jar(如果链接断开,谷歌名称)

  • 而不是 xuggle-utils-1.20.688.jar 使用com.xuggle.utils-1.22.jar

  • 创建一个项目,导入 6 个 jars 并运行它来测试:

    import com.xuggle.xuggler.ICodec;
    import com.xuggle.mediatool.ToolFactory;
    import com.xuggle.mediatool.IMediaWriter;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.util.concurrent.TimeUnit;
    
    public class XuggleTest {
    
        private static int idx = 1;
        private static final int WIDTH = 500;
        private static final int HEIGHT = 500;
        private static final int NFRAMES = 200;
    
        public static void main(String[] arguments) {
    
            // Create writer
            IMediaWriter writer = ToolFactory.makeWriter("output.mp4");
            writer.addVideoStream(0, 0, ICodec.ID.CODEC_ID_MPEG4, WIDTH, HEIGHT);
            long ms = 15; // ms per frame
    
            for (int i = 0; i < NFRAMES; i++) {
    
                BufferedImage frame = convert(getFrame());
                long time = i * ms;
                writer.encodeVideo(0, frame, time, TimeUnit.MILLISECONDS);
    
                idx++;
            }
            System.out.println("Finished writing file: " + System.getProperty("user.dir") + File.separator + writer.getUrl());
    
            writer.close();
        }
    
        private static BufferedImage convert(BufferedImage value) {
            // Convert data type
            BufferedImage result = new BufferedImage(value.getWidth(), value.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
            result.getGraphics().drawImage(value, 0, 0, null);
            return result;
        }
    
        private static BufferedImage getFrame() {
            // Create image frame
            BufferedImage img = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
            img.createGraphics().fillRoundRect(idx, idx, idx, idx, 10, 10);
            return img;
        }
    }
    
于 2016-09-16T14:10:45.373 回答
0

只需在 Windows 操作系统中下载 xuggler 3.4 exe 并添加 jar 文件 1) xuggle-xuggler-arch-x86_64-w64-mingw32.jar 您可以从以下链接获取此 jar:
https ://files.liferay.com/mirrors/ xuggle.googlecode.com/svn/trunk/repo/share/java/xuggle/xuggle-xuggler/5.4/

于 2018-11-19T05:54:36.167 回答