Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Java API for extracting MP4 metadata?

Tags:

java

metadata

mp4

I want to be specific as to what I am asking. I am not asking to modified any MP4 files, just extract metadata such as Width and Height and bitrate and encoding and this is not in the MP3 tags.

I have tested Xuggle which works, but I need to have a library that does not use JNI or any native code.

I already looked into MP4Parser, and Apache Tika, and they both does not extract metadata, just tag info or alter the file.

Is there such java lib?

like image 865
Churk Avatar asked Oct 01 '12 19:10

Churk


2 Answers

I actually found what I was looking for using Mp4Parser

here is a simple lines of code to get what I wanted using Mp4Parser

FileChannel fc = new FileInputStream("content/Video_720p_Madagascar-3.mp4").getChannel();
IsoFile isoFile = new IsoFile(fc);
MovieBox moov = isoFile.getMovieBox();
for(Box b : moov.getBoxes()) {
    System.out.println(b);
}

b contains all the info I needed, now I just have to parse b to get exactly what I want.

like image 60
Churk Avatar answered Sep 21 '22 13:09

Churk


At present (2015), Android SDK provides MediaMetadataRetriever class for extracting metadata:

        MediaMetadataRetriever m = new MediaMetadataRetriever();
        m.setDataSource(mInputFile);
        String extractedHeight = m.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
        String extractedWidth = m.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
like image 37
Kirill Feoktistov Avatar answered Sep 20 '22 13:09

Kirill Feoktistov