gpt4 book ai didi

java - Xuggle 和 java 库路径

转载 作者:行者123 更新时间:2023-11-29 06:07:33 25 4
gpt4 key购买 nike

我正在用 Java 编写截屏应用程序。我决定使用 Xuggle 来完成它,并按照 xuggle wiki 上的安装说明进行操作。

我用 %XUGGLE_HOME%\bin 和 %XUGGLE_HOME%\lib 设置了 PATH 环境。一切似乎都很好。我将此应用程序制作为 RCP 插件。我在“RCP-mail”模板上试过了,插件工作正常,视频生成正确。

但是当我决定在“真实”应用程序上使用它时,插件崩溃并出现一条奇怪的错误消息:

Starting Capture

2011-11-10 08:08:45,438 [Thread-5] WARN com.xuggle.ferry.JNILibraryLoader - Failure: library load of library: xuggle-xuggler; version: 3: absolute path: C:\Program Files (x86)\Xuggle\bin\libxuggle-xuggler-3.dll; error: java.lang.UnsatisfiedLinkError: C:\Program Files (x86)\Xuggle\bin\libxuggle-xuggler-3.dll: Can't find dependent libraries

2011-11-10 08:08:45,447 [Thread-5] WARN com.xuggle.ferry.JNILibraryLoader - Failure: library load of library: xuggle-xuggler; version: 3: absolute path: C:\Program Files (x86)\Xuggle\bin\libxuggle-xuggler-3.dll; error: java.lang.UnsatisfiedLinkError: C:\Program Files (x86)\Xuggle\bin\libxuggle-xuggler-3.dll: Can't find dependent libraries

2011-11-10 08:08:45,453 [Thread-5] 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.library.path 定义明确:

logger.info(System.getProperty("java.library.path"));

返回

Nov 10, 2011 8:08:45 AM com.gvs.tools.ui.record.video.handler.RecordHandler startRecording
INFO: C:\Program Files (x86)\Java\jre6\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files (x86)/Java/jre6/bin/client;C:/Program Files (x86)/Java/jre6/bin;C:/Program Files (x86)/Java/jre6/lib/i386;C:\Program Files (x86)\Xuggle\bin;C:\Program Files (x86)\Xuggle\lib;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\JProbe 8.3\bin;C:\Program Files\TortoiseSVN\bin;D:\Work\Paul\eclipse;;.

要使插件与此应用程序一起工作,我缺少什么?这个问题是因为应用程序使用了其他原生库(例如 3D-dll)吗?

这是用于制作截屏视频的代码:

RecordHandler.java:
private void startRecording() {

Logger logger = Logger.getLogger(RecordHandler.class.getName());
logger.info(System.getProperty("java.library.path"));

// Initialize framesQueue
framesQueue = new LinkedBlockingQueue<BufferedImage>();
// Initialize the capture thread
captureThread = new ScreenCapturer();
captureThread.setCaptureFramesQueue(framesQueue);

// Initialize the recorder
encoderThread = new FrameEncoder("test.mp4");
encoderThread.setCapturedFramesQueue(framesQueue);

// Start capture
captureThread.start();
// wait for the Queue to be feed before encoding
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
}
encoderThread.start();
}

屏幕捕捉器.java:

    @Override
public void run() {
// Retrieve the application main window's shell
Display.getDefault().asyncExec(new Runnable() {

@Override
public void run() {
appShell = Display.getCurrent().getActiveShell();
}
});

isRunning = true;
System.out.println("Starting Capture");
for (numberOfFramesTaken = 0; isRunning && numberOfFramesTaken <= IVideoEncoderConfiguration.MAXIMUM_NUMBER_OF_FRAMES; numberOfFramesTaken++) {
try {
takeScreenShot();
Thread.sleep(IVideoEncoderConfiguration.CAPTURE_TIME_INTERVAL_MILLIS);
} catch (InterruptedException e) {
}
}
System.out.println("Capture has ended");
System.out.println("Number of frames taken: "
+ numberOfFramesTaken);
}

/**
* Take a screen capture and store it in the capturedFramesQueue
*/
private void takeScreenShot() {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
if (appShell != null) {
Rectangle bounds = appShell.getBounds();
java.awt.Rectangle awtBounds = new java.awt.Rectangle(bounds.x, bounds.y, bounds.width, bounds.height);
final BufferedImage screenCapture = robot.createScreenCapture(awtBounds);
try {
capturedFramesQueue.put(screenCapture);
} catch (InterruptedException e) {
}
}
}
});
}

帧编码器.java:

public void run() {
isRunning = true;
String outFile = outputdirectoryPath + outputFileName;
// First, let's make a IMediaWriter to write the file.
final IMediaWriter writer = ToolFactory.makeWriter(outFile);
// Retrieve the first frame to guess video dimensions
BufferedImage firstFrame = null;
try {
firstFrame = capturedFramesQueue.take();
} catch (InterruptedException e) {
}
if (firstFrame == null) {
return;
}
// We tell it we're going to add one video stream, with id 0,
// at position 0, and that it will have a fixed frame rate of
// FRAME_RATE.
writer.addVideoStream(0, 0,
IVideoEncoderConfiguration.FRAME_RATE,
firstFrame.getWidth(), firstFrame.getHeight());

long startTime = System.nanoTime();
for (numberOfFramesRecorded = 0; isRunning
&& numberOfFramesRecorded <= IVideoEncoderConfiguration.MAXIMUM_NUMBER_OF_FRAMES; numberOfFramesRecorded++) {
// Retrieve the captured frame
try {
final BufferedImage currentFrame = convertToType(capturedFramesQueue.take(), BufferedImage.TYPE_3BYTE_BGR);
// encode the next frame
writer.encodeVideo(0, currentFrame, System.nanoTime() - startTime,
TimeUnit.NANOSECONDS);
// sleep, time depending of FRAME_RATE
Thread.sleep(IVideoEncoderConfiguration.CAPTURE_TIME_INTERVAL_MILLIS);
} catch (InterruptedException e) {
}
}
// Get the remaining frame on the queue
Collection<BufferedImage> frames = new LinkedList<BufferedImage>();
capturedFramesQueue.drainTo(frames, IVideoEncoderConfiguration.MAXIMUM_NUMBER_OF_FRAMES - numberOfFramesRecorded);
for (BufferedImage frame : frames) {
BufferedImage currentFrame = convertToType(frame, BufferedImage.TYPE_3BYTE_BGR);
writer.encodeVideo(0, currentFrame, System.nanoTime() - startTime,
TimeUnit.NANOSECONDS);
}
// close the MediaWriter, write the trailer if needed
writer.close();
}

最佳答案

我知道有点晚了,但问题是 Xuggler 要求所有 DLL 都在操作系统加载路径环境中,而不仅仅是 java.library.path

这意味着所有随 Xuggle 安装的 DLL(例如,libavcodec.dll)都需要位于启动 Java 的进程的 %PATH% 环境变量中。

关于java - Xuggle 和 java 库路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8076952/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com