Search code examples
javajmf

Video recording in java using java media framework is throwing exception


For capture the live video from web using java and jmf i have written the below code , I plugin the usb webcam and i have installed java mediaframewrok latest and updated version.when i complie the program there is no error but while i run the program i got some error like this....

    Exception in thread "VFW Request Thread" java.lang.UnsatisfiedLinkError: JMFSecurityManager: java.lang.UnsatisfiedLinkError: no jmvfw in java.library.path at com.sun.media.JMFSecurityManager.loadLibrary(JMFSecurityManager.java:
206)
        at com.sun.media.protocol.vfw.VFWCapture.<clinit>(VFWCapture.java:19)
        at com.sun.media.protocol.vfw.VFWSourceStream.doConnect(VFWSourceStream.
java:241)
        at com.sun.media.protocol.vfw.VFWSourceStream.run(VFWSourceStream.java:7
63)
        at java.lang.Thread.run(Thread.java:724)

Solution

  • You should load the library like this (and can check the library path if it has been loaded.):

       public class Test {
    
          static {
            try {
                System.load("C:/PATH_TO/jmvfw.dll");
                System.out.println(String.format("%s has been successfully loaded","jmvfw"));
            } catch (UnsatisfiedLinkError e) {
              System.err.println("Native code library jmvfw  failed to load." , e);
              System.exit(1);
            }
          }
          //check if the lib is in java.library.path
          public static void main(String argv[]) {
            String libs = System.getProperty("java.library.path");
            for (String lib : libs.split(";")) 
                System.out.println(lib);
    
          }
        }
    

    Update

    The error:

    C:\jmvfw.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform
    

    means that your DLL is 32-bit. You have to recompile (or download) the DLL for 64-bit. Another option is to switch to a 32-bit JVM -- or get some 32-bit process to load the DLL on your behalf and communicate with that process (a bit complicated).