How can I extract meta data from various video file formats?

后端 未结 2 653
北海茫月
北海茫月 2021-01-02 22:04

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

相关标签:
2条回答
  • 2021-01-02 22:26

    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);
    
    0 讨论(0)
  • 2021-01-02 22:33

    The vikiiii solutions works, but I found :

    • It still required a bit of work to get everything running on my desktop. (download the dll, extract the code, browse files...)
    • We have no clue of the constants (like "BitRate") available

    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);
        //...
    
    0 讨论(0)
提交回复
热议问题