I am trying to load a video file with javacv but I am facing some problems.
I managed to compile an application that will show an image on screen so I assume that my setup is ok.
The code I am using is the following.
import java.io.File;
import com.googlecode.javacv.CanvasFrame;
import com.googlecode.javacv.FFmpegFrameGrabber;
public class TestCV{
public static void main(String[] args) throws Exception {
File f = new File("input.mp4");
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(f);
final CanvasFrame canvas = new CanvasFrame("My Image");
canvas.showImage(grabber.grab());
}
}
Here is the error
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Users\takas\AppData\Local\Temp\jniavutil3690549951281752227.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at com.googlecode.javacpp.Loader.load(Loader.java:337)
at com.googlecode.javacpp.Loader.load(Loader.java:271)
at com.googlecode.javacv.cpp.avutil.<clinit>(avutil.java:76)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.googlecode.javacpp.Loader.load(Loader.java:291)
at com.googlecode.javacv.cpp.avcodec.<clinit>(avcodec.java:87)
at com.googlecode.javacv.FFmpegFrameGrabber.<init>(FFmpegFrameGrabber.java:73)
at com.googlecode.javacv.FFmpegFrameGrabber.<init>(FFmpegFrameGrabber.java:69)
at tester.t.JavaFlow.main(JavaFlow.java:13)
Do I have to use separate ffmpeg dlls? There is one ffmpeg dll in the opecv bin folder.
If I have to do this I will need a better way to include them using eclipse. Until now I just add the folder to path variable. For example I added this to make opencv work.
C:\opencv\build\common\tbb\ia32\vc10\;C:\opencv\build\x86\vc10\bin\;
some days back i got same error and i solved this by following procedure,
download ffmpeg precompiled file for windows
for window 32
http://ffmpeg.zeranoe.com/builds/win32/shared/ffmpeg-0.7.1-win32-shared.7z
for window 64
http://ffmpeg.zeranoe.com/builds/win64/shared/ffmpeg-0.7.1-win64-shared.7z
extract folder some where on hard-disk copy all dlls put them into system32 folder. basically these dll required to be in you path so that java program can access them
Related
I am new to OpenCV.
I have a project that uses OpenCV to read video feed from a video file and detect motion in each frame.
The code runs smoothly in Eclipse. But problem comes when I was trying to export it to a .jar file.
I export the code as a "Runnable JAR file" and select "Package required libraries into generated JAR" option in Eclipse. I tried to run the code through java command. But it gives following error.
C:\Users\Zhang\Documents\B-ACS>java -jar exp.jar
Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java2411 in
java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at cvTest3.VideoCaptureDemo.<clinit>(VideoCaptureDemo.java:33)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
der.java:56)
The code at line 33 is:
static{
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
How should I export the code into a JAR file?
I'm trying to make a game and it runs fine in eclipse, but I get this error when I export and run it as a jar file.
Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl64 in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at org.lwjgl.Sys$1.run(Sys.java:72)
at java.security.AccessController.doPrivileged(Native Method)
at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
at org.lwjgl.Sys.loadLibrary(Sys.java:87)
at org.lwjgl.Sys.<clinit>(Sys.java:117)
at org.lwjgl.opengl.Display.<clinit>(Display.java:135)
at org.newdawn.slick.AppGameContainer$1.run(AppGameContainer.java:39)
at java.security.AccessController.doPrivileged(Native Method)
at org.newdawn.slick.AppGameContainer.<clinit>(AppGameContainer.java:36)
at ultra.game.core.MainGame.main(MainGame.java:1827)
I have tried so many things. I set the natives location to the native folder and I checked inside and lwjgl64 is in there. Any help?
LWJGL uses its own variables for the path to the native libraries:
System.setProperty("org.lwjgl.librarypath", new File("pathToNatives").getAbsolutePath());
If you kept the file structure from the LWJGL package you can use something like this:
switch(LWJGLUtil.getPlatform())
{
case LWJGLUtil.PLATFORM_WINDOWS:
{
JGLLib = new File("./native/windows/");
}
break;
case LWJGLUtil.PLATFORM_LINUX:
{
JGLLib = new File("./native/linux/");
}
break;
case LWJGLUtil.PLATFORM_MACOSX:
{
JGLLib = new File("./native/macosx/");
}
break;
}
System.setProperty("org.lwjgl.librarypath", JGLLib.getAbsolutePath());
This means that you do not have the native library named "lwjgl64" in a place so that Java can find and load it, or that you are using a 32-bit JVM and you are trying to load a 64-bit native library (or vice versa) - if you want to use native libraries, they must have the same "bitness" as the JVM you are using.
On Windows, the native library would be in a file lwjgl64.dll; on Mac OS X or other Unix-like systems it would be lwjgl64.so. Find this file, and then set the system property java.library.path using the -D option when you start your program, for example:
java -Djava.library.path=C:\MyProject\lib com.mypackage.MyProgram
where C:\MyProject\lib would be the directory that contains the DLL.
Why it seems that is impossible to load a library (.dll) in Java, if it is not located in /jre/bin folder. It's crazy, but I have 2 dll's:
aa.dll
bb.dll, which depends on aa.dll
If I copy these dll's in C:\Tmp the following code it is not working.....
If copy these dll'd in C:\Program Files\Java\jre1.8.0_25\bin, the same code it's working.
The code, very simple:
public class Main {
public static void main(String[] args) {
System.load("C:\\Tmp\\ftd2xx.dll");
System.out.println("ftd2xx.dll loaded");
System.load("C:\\Tmp\\JD2XX.dll");
}
}
The error (result):
ftd2xx.dll loaded
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jd2xx in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at jd2xx.JD2XX.<clinit>(JD2XX.java:729)
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at Main_02.main(Main_02.java:7)
To be more confusing, one library I can load from c:\Tmp (aa.dll), the other one I cannot (bb.dll).
This last one requires to reside in C:\Program Files\Java\jre1.8.0_25\bin.
If somebody has any useful idea, I will appreciate very much.
I tought the JVM does not want to load possible dangerous, or untrusted native code? And if it resides in the jre folder it consider the code is safe? But it is jus an ideea.
Thank you.
I confirm the same:
Windows 7(64bit);jre1.8.0_102(32bit);DLL's(32bit);
Exactly the same but in my case one dll(aa.dll) is dependent on another bb.dll (aa.dll->bb.dll)
aa.dll can be loaded from anywhere (a projects lib path for ex), but only and only if I copy bb.dll to jre1.8.0_102\bin directory; No chances to load otherwise. Tried various combinations to set -Djava.library.path=project_path\lib, to set system PATH=project_path\lib, copy both dll's to windows\system32 - nothing helps, the only chance is to have it on jre\bin path.
AN UPDATE:
And you have answered your question your self. It's a security:
Go to -> Java Control Panel -> Advanced -> Mixed code ..
Set "Disable verification.."
and aa.dll loads successfully. Both stored in project_path\lib
In my project I want to capture image from my webcam.
I configured step by step following the instructions from this "OpenCV-JavaCV : eclipse project configuration windows 7" blog post.
After configuration is finished, i tested samples codes and the application found my webcam
SETUP: Setting up device 0
SETUP: Namuga 1.3M Webcam
SETUP: Couldn't find preview pin using SmartTee
SETUP: Capture callback set
SETUP: Device is setup and ready to capture.
and then i got an error which is .dll error.
I use windows 7 x64.
Exception in thread "Thread-2" java.lang.UnsatisfiedLinkError: C:\Users\Administrator\AppData\Local\Temp\javacpp153028723186\jniopencv_core.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary1(Unknown Source)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:418)
at com.googlecode.javacpp.Loader.load(Loader.java:368)
at com.googlecode.javacpp.Loader.load(Loader.java:315)
at com.googlecode.javacv.cpp.opencv_core.<clinit>(opencv_core.java:131)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.googlecode.javacpp.Loader.load(Loader.java:334)
at com.googlecode.javacpp.Loader.load(Loader.java:315)
at com.googlecode.javacv.cpp.opencv_core$CvArr.<clinit>(opencv_core.java:158)
at com.googlecode.javacv.VideoInputFrameGrabber.grab(VideoInputFrameGrabber.java:158)
at GrabberShow.run(GrabberShow.java:24)
at java.lang.Thread.run(Unknown Source)
How can i solve this problem?
Check whether your Opencv version and JavaCv versions are matching each other. You can check that on the readme file on javacv-bin it specifically say about the required version of the opencv.
Unsatisfied link means that not all native code libraries required by jniopencv_core.dll could be found.
Did you deploy them all or just jniopencv_core.dll?
I faced this problem on Windows XP and Windows 7, and this is how I fixed it on both platforms, using Netbeans 7.2:
Install all required software:
FFmpeg (32-bit shared): Zeranoe FFmpeg offers win32 builds. Download and extract ffmpeg-20121020-git-04bf2e7-win32-shared.7z. Place its content at C:\ffmpeg.
Note: make sure C:\ffmpeg\bin is a valid path.
OpenCV 2.4.2 (32-bit): download OpenCV-2.4.2.exe and extract it. Place its content at C:\opencv.
Note: make sure C:\opencv\build\x86\vc10\bin is valid path.
JavaCV 0.2: download javacv-0.2-bin.zip and extract it. Move the extracted folder to C:\javacv-bin.
Microsoft Visual C++ redistributable package (32-bit): download and install vcredist_x86.exe.
Configure the environment:
Edit the environment variable PATH and append the following paths at the end:
C:\ffmpeg\bin;C:\opencv\build\x86\vc10\bin
Now you ready to create a new Netbeans project and test your application. But before you compile it,dDon't forget to right-click the Libraries folder at the pProjects window* and click Add Jar/FOLDER to select all the .jar files located at C:\javacv-bin.
Make sure you have the vm arg -Djava.library.path=<path-to-native> that points to the directory with your dlls.
I'm trying to start my java game but I have some troubles with the java command line:
Here is what I type:
C:\>java -Djava.library.path=%cd%\lib -jar game.jar
And here is what I got:
Exception in thread "main" java.lang.NoClassDefFoundError: org/lwjgl/LWJGLException
at com.game.Main.main(Main.java:7)
Caused by: java.lang.ClassNotFoundException: org.lwjgl.LWJGLException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
I can start my game with Eclipse (With Run as Java Application) but after the menu I got the following error:
Exception in thread "Thread-5" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at org.lwjgl.Sys$1.run(Sys.java:72)
at java.security.AccessController.doPrivileged(Native Method)
at org.lwjgl.Sys.doLoadLibrary(Sys.java:65)
at org.lwjgl.Sys.loadLibrary(Sys.java:81)
at org.lwjgl.Sys.<clinit>(Sys.java:98)
at org.lwjgl.opengl.Display.<clinit>(Display.java:129)
at com.game.displaygui.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
lwjgl.jar has been put into the folder \lib.
Could you explain me with I got that?
Thanks.
This because lwjgl library is made by two components:
the .jar file which contains Java code
and the native binary library (which can be .so or .dll or .dylib according to your OS)
The first error you are getting is because you are setting the library path, that should contain the native library, but it does contain the .jar. So you get a java.lang.NoClassDefFoundError because you should set either the library path to the folder that contains native library, either the classpath to contain the real lwjgl.jar file.
The second error that you get with Eclipse is a successive step: your classpath contains the jar library but it is not able to find the native library attached to it, you can fix it in the following way:
You should specify explicitly which lib files to include (seperated by ;) :
-cp %cd%\lib\lwjdl.jar;%cd%\lib\<another-lib>.jar
Don't be tempted to use the wildcard * as it will cause more harm than good (from previous experience :))
You use the java.library.path option to specify the location of native libraries to load. In the location pointed to by that option you would place all dll or .so files required by LWJGL. On the other hand, you need to make sure that all required JAR files are on your classpath, via the -classpath option. Currently, you have your JAR files in the wrong directory.
In Eclipse, if you using maven.
Add the following to the project "Run" : "VM options" .
-Djava.library.path=yourpath/youproject/java/target/natives