Configuring libmediainfo to work with Java project without installation across all platforms (OSes)

Help
static0886
2013-04-16
2013-04-19
  • static0886
    static0886
    2013-04-16

    I am using mediainfo (http://mediainfo.sourceforge.net/en) to extract information from audio and video files using Java code.

    My java project runs over all platforms (osx, win & linux). So far I have only tested mediainfo over osx where the procedure is simple: just put libmediainfo.dylib in the target folder and access it using a native library and you're good to go. And the solution works flawlessly...

    I am now looking to expand this functionality to the other OSs, starting with Linux. However, it is proving to be more of a challenge than I thought. At first I kept getting this:

    "java.lang.UnsatisfiedLinkError: Unable to load library 'mediainfo': libmediainfo.so: cannot open shared object file: No such file or directory"
    and this was expected as it was looking in /usr/lib

    but this was solved by installing the suitable libmediainfo0 & libzen0 ".deb from http://mediainfo.sourceforge.net/en/Download/Ubuntu

    Still, my solution needs to be portable, meaning, I want all necessary resources to be included with the java project package without requiring any further installations. I also need to know if it's possible to change mediainfo to look for the resources in my java package instead of a system location.

    For your reference, I am using Java Native Access (jna) to interact with the library. Also using the MediaInfo.java & MediaInfoLibrary.java classes that the website suggests. Let me know if you need other details.

    any wisdom is highly appreciated thanks!!

     
  • The issue is that by default, Linux does not look in the directory of your binary.
    Try this updated MediaInfoDLL.JNA.java, I added a search of a copy of libmediainfo in the directory of MediaInfo.class file.
    With this update, it is ok now if I put libmediainfo.so.0, libmediainfo.so.0.0.0, libzen.so.0, libzen.so.0.0.0 in the same directory as MediaInfo.class.

    I hope it helps.

    side note: I see another issue with such binaries copied in the local directory: you need both 32 and 64 bit version of the library. I think I'll add a test on files like "libmediainfo.x64.so.0" and "libmediainfo.i386.so.0" to avoid such issue (the right library would be loaded depending of the CPU) if it is useful.

     
    Last edit: Jerome Martinez 2013-04-17
  • static0886
    static0886
    2013-04-19

    Salut Jerome
    Thanks a lot for your support.

    I have followed your instructions and now I'm getting this:

    Apr 16, 2013 8:14:49 PM org.tssg.monitor.MediaInfoNew <clinit>
    WARNING: Failed to preload libzen
    Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'mediainfo': JNA native support (linux-i386/libmediainfo.so) not found in resource path (monitor.jar)
    at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:220)
    at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:322)
    at com.sun.jna.Library$Handler.<init>(Library.java:142)
    at com.sun.jna.Native.loadLibrary(Native.java:387)
    at org.tssg.monitor.MediaInfoNew$MediaInfoDLL_Internal.<clinit>(MediaInfoDLL.JNA.java:95)
    at org.tssg.monitor.MediaInfoNew.<init>(MediaInfoDLL.JNA.java:186)

    (MediaInfoNew is the MediaInfo class you sent)

    What i did is place the libzen.so.0.0.0, libmediainfo.so.0.0.0, and their aliases in the compiled classes folder.
    As you can see, the code also fails to get libzen.

    For your reference, I am using the jna-3.5.2.jar that comes with platform-3.5.2.jar. I believe these are the latest versions of jna.
    I am also using the i686 versions of libmedia & libzen on Ubuntu 12.04.

    Here's the result from uname -a:
    Linux UbuntuDesktop2 3.2.0-37-generic-pae #58-Ubuntu SMP Thu Jan 24 15:51:02 UTC 2013 i686 i686 i386 GNU/Linux

    Merci bcp de nouveau

     
  • static0886
    static0886
    2013-04-19

    It looks like I managed to make it work.
    What i did was include the libmedia & libzen files in the monitor.jar file under linux-i386 directory.
    will try the same for win & other versions of linux and tell you how it goes