mediaarea.net
A JNA wrapper to access MediaInfoLib.
Maven Project Info
-
Javadoc
Report Bug
-
Request Feature
Table of Contents
A JNA wrapper to access the native MediaInfo library to parse media information from media files.
- JAR includes native libraries for MacOS (intel and arm), Linux (x64), and Windows (x64).
- Other MediaInfoLib platforms can still be used as long as the native libraries are included in the library path
- Provides an abstract MediaInfoBase class that can be extended to simplify access to media parameters.
// 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.
// 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...
}
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!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
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.
Andy Miles - andy.miles (at) amilesend.com
Project Link: https://github.com/andy-miles/mediainfo-jna-wrapper