Skip to content

andy-miles/mediainfo-jna-wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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. Usage
  3. Contributing
  4. License
  5. Contact

About The Project

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

Feature Highlights

  1. JAR includes native libraries for MacOS (intel and arm), Linux (x64), and Windows (x64).
    1. 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.

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 JAR also uses the MediaInfoLib Binary License for the bundled native libraries:

This product uses MediaInfo library, Copyright (c) 2002-2024 MediaArea.net SARL.
Website: https://mediaarea.net/en/MediaInfo
Email: [email protected]

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

Packages

 
 
 

Languages