How can I extract Metadata from a .MP4 and a .AVI with native library in JAVA

856 Views Asked by At

I try to make a media player and a video library for a school project, and I need to extract metadata from a .MP4 and .AVI to store in a XML files and can edit this metadata.

I did some research and I didn't find what I'm looking for, because I need a native Java library, and not a library that we need to install in our IDE.

And I have make my media player with JavaFX, and JavaFX can not read .avi media. So I need to convert this .avi to .mp4 is it possible to do this in Java with a native library?

2

There are 2 best solutions below

1
wrf On

I'm not quite clear what is meant by "native java library". Java itself (JDK / JRE) does not support parsing of media meta data. The only possibility would be to use a third party library like "Apache Tika":

How to read MP3 file tags

2
David Kariuki On

You can do this with the Java standard library.

public class YourClass {

    Path yourFile = ...;
    BasicFileAttributes attr = Files.readAttributes(yourFile, BasicFileAttributes.class);
    
    System.out.println("creationTime: " + attr.creationTime());
    System.out.println("lastAccessTime: " + attr.lastAccessTime());
    System.out.println("lastModifiedTime: " + attr.lastModifiedTime());
    
    System.out.println("isDirectory: " + attr.isDirectory());
    System.out.println("isOther: " + attr.isOther());
    System.out.println("isRegularFile: " + attr.isRegularFile());
    System.out.println("isSymbolicLink: " + attr.isSymbolicLink());
    System.out.println("size: " + attr.size());
}

This is platform dependent and may throw exceptions or return unexpected results.

Read more at Managing Metadata (File and File Store Attributes).