How can I extract meta data from various video file formats, especially the Resolution and the type of codec used. (But also all other stuff like author). I was not able to
I have found MediaInfo, which supplies dozens of technical and tag information about a video or audio file.
There is a JNI wrapper for MediaInfo in subs4me's source tree that I find very useful.
Here are some code snippets that show how to extract some information from a media file:
File file = new File("path/to/my/file");
MediaInfo info = new MediaInfo();
info.open(file);
String format = info.get(MediaInfo.StreamKind.Video, i, "Format",
MediaInfo.InfoKind.Text,
MediaInfo.InfoKind.Name);
int bitRate = info.get(MediaInfo.StreamKind.Video, i, "BitRate",
MediaInfo.InfoKind.Text,
MediaInfo.InfoKind.Name);
float frameRate = info.get(MediaInfo.StreamKind.Video, i, "FrameRate",
MediaInfo.InfoKind.Text,
MediaInfo.InfoKind.Name);
short width = info.get(MediaInfo.StreamKind.Video, i, "Width",
MediaInfo.InfoKind.Text,
MediaInfo.InfoKind.Name);
int audioBitrate = info.get(MediaInfo.StreamKind.Audio, i, "BitRate",
MediaInfo.InfoKind.Text,
MediaInfo.InfoKind.Name);
int audioChannels = info.get(MediaInfo.StreamKind.Audio, i, "Channels",
MediaInfo.InfoKind.Text,
MediaInfo.InfoKind.Name);
The vikiiii solutions works, but I found :
As a consequence I installed the Windows MediaInfo application and search which are the Keys available to create some java Enum and ease usage.
I created a repository on github https://github.com/clun/movies-metadata to have everything in the same place. Just run mvn:test
on the sample project to get informations on samples MP4, OGG, AVI, FLV, WEBM and MKV.
Here the sample code of the test :
MovieMetadata movieMedataData = new MovieMetadata("./src/test/resources/small.mkv");
movieMedataData.get(General.FORMAT);
movieMedataData.get(Video.DURATION_STRING);
movieMedataData.get(Video.WIDTH_STRING);
movieMedataData.get(Video.HEIGHT_STRING);
movieMedataData.get(Video.BITRATE_STRING);
movieMedataData.get(Audio.COMPRESSION_RATIO);
//...