Stacker
Stacker

Reputation: 23

Unable to extract parameter from video using MediaInfo

I used MediaInfo pre-build binary files from https://github.com/OLEG4120/MediaInfoLib-android to extract video information. I was able to extract entire video information with below method

MediaInfo mediaInfo = new MediaInfo();
String result = mediaInfo.getMI("/storage/emulated/0/sample.mp4");

And i extracted all information about video file. Now how do i extract a single parameter like Bit Rate and other information ?

i tried this following method

String result1 = mediaInfo.get("/storage/emulated/0/sample.mp4", MediaInfo.StreamKind.VIDEO,
                    1, "Format", MediaInfo.InfoKind.TEXT, MediaInfo.InfoKind.NAME);

But the string is empty. Is there any way i could extract single parameter.

MediaInfo.java

/*  Copyright (c) MediaArea.net SARL. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license that can
 *  be found in the License.html file in the root of the source tree.
 */
package org.mediainfo.android;

/**
 * Give information about a lot of media format.
 */
public class MediaInfo {

    public static int isCanceled = 0;

    // @remark Don't change it carelessly.
    // This order is from MediaInfo_Const.h
    public enum StreamKind {
        GENERAL,
        VIDEO,
        AUDIO,
        TEXT,
        OTHER,
        IMAGE,
        MENU,
        MAX
    }

    // @remark Don't change it carelessly.
    // This order is from MediaInfo_Const.h
    public enum InfoKind {
        NAME, // Unique name of parameter
        TEXT, // Value of parameter
        MEASURE, // Unique name of measure unit of parameter
        OPTIONS, // See InfoOptionKind
        NAME_TEXT, // Translated name of parameter
        MEASURE_TEXT, // Translated name of measure unit
        INFO, // More information about the parameter
        HOWTO, // How this parameter is supported, could be N(No), B(Beta),
               // R(Read only), W(Read/Write)
        DOMAIN, // Domain of this piece of information
        MAX
    }

    public MediaInfo() {
        //handle = create();
        System.out.println("MediaInfo created");
    }

    public int getIsCanceled() {
        return isCanceled;
    }

    /**
     * Get a piece of information about a file. (parameter is an integer)
     *
     * @param streamKind
     *            Kind of Stream
     * @param streamNum
     *            Stream number in Kind of stream
     * @param parameter
     *            Parameter you are looking for in the stream (codec, width,
     *            bitrate, ..), in integer format
     * @return a string about information you search, an empty string if there
     *         is a problem.
     */
    public String get(String filename, StreamKind streamKind, int streamNum, int parameter) {
        String result = getById(filename, streamKind.ordinal(), streamNum,
                parameter); /* InfoKind.TEXT */
        return result;
    }

    /**
     * Get a piece of information about a file. (parameter is an integer)
     *
     * @param streamKind
     *            Kind of Stream
     * @param streamNum
     *            Stream number in Kind of stream
     * @param parameter
     *            Parameter you are looking for in the stream (codec, width,
     *            bitrate, ..), in integer format
     * @param infoKind
     *            Kind of information you want about the parameter (the text,
     *            the measure, the help, ..)
     * @return a string about information you search, an empty string if there
     *         is a problem.
     */
    public String get(String filename, StreamKind streamKind, int streamNum, int parameter,
            InfoKind infoKind) {
        String result = getByIdDetail(filename, streamKind.ordinal(), streamNum,
                parameter, infoKind.ordinal());
        return result;
    }

    /**
     * Get a piece of information about a file. (parameter is an string)
     *
     * @param streamKind
     *            Kind of Stream (general, video, audio, ..)
     * @param streamNum
     *            Stream number in Kind of stream
     * @param parameter
     *            Parameter you are looking for in the stream (codec, width,
     *            bitrate, ..), in string format ("Codec", "Width", ..)
     * @return a string about information you search, an empty string if there
     *         is a problem
     */
    public String get(String filename, StreamKind streamKind, int streamNum, String parameter) {
        String result = getByName(filename, streamKind.ordinal(), streamNum,
                parameter); /* InfoKind.TEXT, InfoKind.NAME */
        return result;
    }

    /**
     * Get a piece of information about a file. (parameter is an string)
     *
     * @param streamKind
     *            Kind of Stream (general, video, audio, ..)
     * @param streamNum
     *            Stream number in Kind of stream
     * @param parameter
     *            Parameter you are looking for in the stream (codec, width,
     *            bitrate, ..), in string format ("Codec", "Width", ..)
     * @param infoKind
     *            Kind of information you want about the parameter (the text,
     *            the measure, the help, ..)
     * @return a string about information you search, an empty string if there
     *         is a problem.
     */
    public String get(String filename, StreamKind streamKind, int streamNum, String parameter,
            InfoKind infoKind) {
        String result = getByNameDetail(filename, streamKind.ordinal(),
                streamNum, parameter, infoKind.ordinal(),
                InfoKind.NAME.ordinal());
        return result;
    }

    /**
     * Get a piece of information about a file. (parameter is an string)
     *
     * @param streamKind
     *            Kind of Stream (general, video, audio, ..)
     * @param streamNum
     *            Stream number in Kind of stream
     * @param parameter
     *            Parameter you are looking for in the stream (codec, width,
     *            bitrate, ..), in string format ("Codec", "Width", ..)
     * @param infoKind
     *            Kind of information you want about the parameter (the text,
     *            the measure, the help, ..)
     * @param searchKind
     *            Where to look for the parameter
     * @return a string about information you search, an empty string if there
     *         is a problem.
     */
    public String get(String filename, StreamKind streamKind, int streamNum, String parameter,
            InfoKind infoKind, InfoKind searchKind) {
        String result = getByNameDetail(filename, streamKind.ordinal(),
                streamNum, parameter, infoKind.ordinal(), searchKind.ordinal());
        return result;
    }

    /**
     * Count of streams of a stream kin (StreamNumber not filled), or count of
     * piece of information in this stream.
     *
     * @param streamKind
     *            Kind of Stream (general, video, audio, ..)
     * @return number of streams of the given stream kind
     */
    public int countGet(String filename, StreamKind streamKind) {
        int result = countGet(filename, streamKind.ordinal(), -1);
        return result;
    }

    /**
     * Count of streams of a stream kin (StreamNumber not filled), or count of
     * piece of information in this stream.
     *
     * @param streamKind
     *            Kind of Stream (general, video, audio, ..)
     * @param streamNumber
     *            Stream number in Kind of stream
     * @return number of streams of the given stream kind
     */
    public int countGet(String filename, StreamKind streamKind, int streamNumber) {
        int result = countGet(filename, streamKind.ordinal(), streamNumber);
        return result;
    }

    public String getMI(String filename) {
        String result = getMediaInfo(filename);
        return result;
    }

    public String getMIOption(String param) {
        String result = getMediaInfoOption(param);
        return result;
    }

    private native String getById(String filename, int streamKind, int streamNum,
            int parameter);

    private native String getByIdDetail(String filename, int streamKind, int streamNum,
            int parameter, int kindOfInfo);

    private native String getByName(String filename, int streamKind, int streamNum,
            String parameter);

    private native String getByNameDetail(String filename, int streamKind,
            int streamNum, String parameter, int kindOfInfo, int kindOfSearch);

    private native int countGet(String filename, int streamKind, int streamNum);

    private native String getMediaInfo(String filename);

    private native String getMediaInfoOption(String param);

    static {
        System.loadLibrary("mediainfo");
    }
}

Dump extract

File
    Complete name                            : /storage/emulated/0/sample.mp4
    
    General
    Format                                   : MPEG-4
    Format profile                           : Base Media / Version 2
    Codec ID                                 : mp42 (isom/mp42)
    File size                                : 48.1 MiB
    Duration                                 : 5mn 33s
    Overall bit rate mode                    : Variable
    Overall bit rate                         : 1 213 Kbps
    Encoded date                             : UTC 2014-06-26 10:18:07
    Tagged date                              : UTC 2014-06-26 10:18:07
    gsst                                     : 0
    gstd                                     : 333066
    gssd                                     : BD155E602HH1408471349425322
    gshh                                     : r2---sn-aiglln6e.googlevideo.com
    
    Video
    ID                                       : 1
    Format                                   : AVC
    Format/Info                              : Advanced Video Codec
    Format profile                           : [email protected]
    Format settings, CABAC                   : Yes
    Format settings, ReFrames                : 1 frame
    Codec ID                                 : avc1
    Codec ID/Info                            : Advanced Video Coding
    Duration                                 : 5mn 32s
    Bit rate                                 : 1 018 Kbps
    Maximum bit rate                         : 2 944 Kbps
    Width                                    : 1 280 pixels
    Height                                   : 720 pixels
    Display aspect ratio                     : 16:9
    Frame rate mode                          : Constant
    Frame rate                               : 29.970 (30000/1001) fps
    Color space                              : YUV
    Chroma subsampling                       : 4:2:0
    Bit depth                                : 8 bits
    Scan type                                : Progressive
    Bits/(Pixel*Frame)                       : 0.037
    Stream size                              : 40.4 MiB (84%)
    Encoded date                             : UTC 1904-01-01 00:00:00
    Tagged date                              : UTC 2014-06-26 10:18:10
    
    Audio
    ID                                       : 2
    Format                                   : AAC
    Format/Info                              : Advanced Audio Codec
    Format profile                           : LC
    Codec ID                                 : 40
    Duration                                 : 5mn 33s
    Bit rate mode                            : Variable
    Bit rate                                 : 192 Kbps
    Maximum bit rate                         : 201 Kbps
    Channel(s)                               : 2 channels
    Channel positions                        : Front: L R
    Sampling rate                            : 44.1 KHz
    Frame rate                               : 43.066 fps (1024 spf)
    Compression mode                         : Lossy
    Stream size                              : 7.62 MiB (16%)
    Title                                    : IsoMedia File Produced by Google, 5-11-2011
    Encoded date                             : UTC 2014-06-26 10:18:09
    Tagged date                              : UTC 2014-06-26 10:18:10

Upvotes: 1

Views: 1279

Answers (1)

ax.
ax.

Reputation: 59927

Try 0 as first streamNumber of a StreamKind instead of 1, eg.

mediaInfo.get("sample.mp4", MediaInfo.StreamKind.VIDEO, 0, "Format", MediaInfo.InfoKind.TEXT, MediaInfo.InfoKind.NAME)

That's what all the examples of MediaInfoLib do, eg. here.

By the way: I would suggest to use the up-to-date MediaInfoLib directly instead of the unmaintained, 4-years-old, undocumented, modified version in MediaInfoLib-android. I got the current Java JNI example running (on Windows) in just a few minutes. Should work for Android, too (see MediaInfoJNI.cpp).

Upvotes: 4

Related Questions