Skip to content

A JNA wrapper to access MediaInfoLib

License

Notifications You must be signed in to change notification settings

andy-miles/mediainfo-jna-wrapper

Repository files navigation

Contributors Forks Stargazers Issues LinkedIn


Logo
mediaarea.net

mediainfo-jna-wrapper

A JNA wrapper to access MediaInfoLib.
Maven Project Info - Javadoc
Report Bug - Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Contributing
  5. License
  6. Contact

About The Project

A JNA wrapper to access the native MediaInfo library to parse media information from media files.

Feature Highlights

  1. Native library JARs are available for MacOS (Intel and ARM), Linux (x64 and ARM), and Windows (x64 and ARM).
    • Note: Other MediaInfoLib platforms can still be used as long as the native libraries are included in the library path
  2. Provides an abstract MediaInfoBase class that can be extended to simplify access to media parameters.

Getting Started

Include the following package dependencies in your project's classpath. Note: These packages are published to both GitHub and Maven Central repositories.

  1. Required interface package

    <dependency>
       <groupId>com.amilesend</groupId>
       <artifactId>mediainfo-jna-wrapper</artifactId>
       <version>2.1.6</version>
    </dependency>
  2. Platform-specific library packages You may select 1 or more of the following for your project:

    1. Linux

      1. x64
      <dependency>
         <groupId>com.amilesend</groupId>
         <artifactId>mediainfo-jna-lib-linux-x86-64</artifactId>
         <version>2.1.6</version>
      </dependency>
      1. ARM64
      <dependency>
         <groupId>com.amilesend</groupId>
         <artifactId>mediainfo-jna-lib-linux-aarch64</artifactId>
         <version>2.1.6</version>
      </dependency>
    2. MacOS

      1. ARM
      <dependency>
         <groupId>com.amilesend</groupId>
         <artifactId>mediainfo-jna-lib-mac-aarch64</artifactId>
         <version>2.1.6</version>
      </dependency>
      1. Intel
      <dependency>
         <groupId>com.amilesend</groupId>
         <artifactId>mediainfo-jna-lib-mac-x86-64</artifactId>
         <version>2.1.6</version>
      </dependency>
    3. Windows

      1. x64
      <dependency>
         <groupId>com.amilesend</groupId>
         <artifactId>mediainfo-jna-lib-win-x86-64</artifactId>
         <version>2.1.6</version>
      </dependency>
      1. ARM
      <dependency>
         <groupId>com.amilesend</groupId>
         <artifactId>mediainfo-jna-lib-win-aarch64</artifactId>
         <version>2.1.6</version>
      </dependency>

Usage

Recipes

Open a video file using the default MediaInfo object

// Initialize the JNA bindings
MediaInfoLibrary library = MediaInfoLibrary.newInstance();
// The wrapper class to access the native methods
MediaInfoAccessor accessor = new MediaInfoAccessor(library);

// Opens a video file with the MediaInfo object being an AutoClosable
try (MediaInfo myVideo = new MediaInfo(accessor).open("./MyVideo.mkv")) {
    List<String> videoCodecs =
            MediaInfo.parseList(myVideo.get(StreamType.General, 0, "Video_Codec_List"));
    int videoWidth = Integer.parseInt(myVideo.get(StreamType.Video, 0, "Width"));
   
    // Get and parse additional parameters...
}

For more information, please refer to javadoc or source.

Defining a custom MediaInfo object

// Extend to define the explicit parameters for your java application.
public class MyVideoMediaInfo extends MediaInfoBase<MyVideoMediaInfo>  {
    public MyVideoMediaInfo(MediaInfoAccessor accessor) {
        super(accessor);
    }
 
    public List<String> getVideoCodecs() {
        String codecsList = mediaInfo.get(StreamType.General, 0, "Video_Codec_List");
        return parseList(codecsList);
    }

    public Duration getDuration() {
        long value = (long) Double.parseDouble(
                getAccessor().get(StreamType.General, 0, "Duration"));
        return Duration.ofMillis(value);
    }

    public int getWidth() {
        return Integer.parseInt(getAccessor().get(StreamType.Video, 0, "Width"));
    }

    public int getHeight() {
        return Integer.parseInt(getAccessor().get(StreamType.Video, 0, "Height"));
    }
    
    public Instant getCreationTime() {
        String encodingTime = getAccessor().get(StreamType.General, 0, "Encoded_Date");
        return parseTime(encodingTime);
    }
    
    // Define additional accessor methods here...
}

// Initialize the JNA bindings
MediaInfoLibrary library = MediaInfoLibrary.newInstance();
// The wrapper class to access the native methods
MediaInfoAccessor accessor = new MediaInfoAccessor(library);

// Opens a video file with the MyVideoMediaInfo object being an AutoClosable
try (MyVideoMediaInfo myVideo = new MyVideoMediaInfo(accessor).open("./MyVideo.mkv")) {
    List<String> videoCodecs = myVideo.getVideoCodecs();
    Duration movieDuration = myVideo.getDuration();
    int videoWidth = myVideo.getWidth();
    int videoHeight = myVideo.getHeight();
    Instant encodingTimestamp = myVideo.getCreationTime();

    // Access additional custom accessor methods...
}

Contributing

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT license.

The built binary JARs also uses the MediaInfoLib Binary License for the bundled native libraries:

This product uses MediaInfo library, Copyright (c) 2002-2026 MediaArea.net SARL.
Website: https://mediaarea.net/en/MediaInfo
Email: info@mediaarea.net

See LICENSE for more information.

Contact

Andy Miles - andy.miles (at) amilesend.com

Project Link: https://github.com/andy-miles/mediainfo-jna-wrapper

About

A JNA wrapper to access MediaInfoLib

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

 
 
 

Languages