How can I extract metadata from various video file formats?

How can I extract metadata from various video file formats, especially with the resolution and type of codec used. (But also all other things, such as the author). I could not find a library for this.

+4
source share
3 answers

I found MediaInfo , which provides dozens of technical and tags for information about a video or audio file.

There is a JNI wrapper for MediaInfo in the subs4me source file , which 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); 
+5
source

Vikiiii solutions work, but I found:

  • It still takes a little work to get everything working on my desktop. (download dll, extract code, view files ...)
  • We do not have the concept of constants (for example, "BitRate") available

As a result, I installed the Windows MediaInfo application and search, which are the keys available to create some enum and usability.

I created a repository on github https://github.com/clun/movies-metadata so that everything is in one place. Just run mvn:test in the sample project to get information about the MP4, OGG, AVI, FLV, WEBM, and MKV samples.

Here is an example test code:

  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); //... 
+3
source

Source: https://habr.com/ru/post/1338980/


All Articles