我最近下载了一个代码,用于“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请解释为什么类加载器无法加载.jar文件.
发布于 2013-08-08 23:36:34
您面临的问题是,无法找到Xuggle使用的本地库。我怀疑你的类路径中有冲突。
如果你所说的“所有的罐子”是指下载页面中的罐子,那么你不应该下载所有的罐子。在Xuggler下载页面,它说要么下载包含所有操作系统的本机库的xuggle‑xuggler.jar,要么选择特定的体系结构。
在尝试运行链接到的示例时,我执行了以下操作:
junit,您可以忽略它们。
下载后,您可以在zip文件中找到POM文件中描述的5 jars (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.jar),它们是xuggle‑xuggler.jar的依赖项。按照上面的步骤,我能够在Windows机器上成功地运行您的测试程序。
我希望这能帮上忙。
发布于 2014-10-23 13:27:19
看起来最好的解决方案是,由于我必须如何安装/配置Xuggle才能不获得UnsatisfiedLinkError?的原因,在maven中使用Xaggler5.4
发布于 2016-09-16 14:10:45
在C.S.的回答之后,我的工作结束了:
https://stackoverflow.com/questions/18077307
复制相似问题