【问题标题】:Unable to extract parameter from video using MediaInfo无法使用 MediaInfo 从视频中提取参数
【发布时间】:2022-01-28 06:36:27
【问题描述】:

我使用来自https://github.com/OLEG4120/MediaInfoLib-android 的 MediaInfo 预构建二进制文件来提取视频信息。我能够使用以下方法提取整个视频信息

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

我提取了有关视频文件的所有信息。 现在如何提取Bit Rate 等单个参数和其他信息?

我尝试了以下方法

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

但是字符串是空的。有什么办法可以提取单个参数。

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");
    }
}

转储提取

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                           : High@L3.1
    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

【问题讨论】:

  • 如果省略最后一个参数会发生什么,例如:mediaInfo.get("/storage/emulated/0/sample.mp4", MediaInfo.StreamKind.VIDEO, 1, "Format", MediaInfo.InfoKind.TEXT)?

标签: java android mediainfo


【解决方案1】:

尝试将0 作为StreamKind 的第一个streamNumber,而不是1,例如。

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

MediaInfoLib 的所有示例都是这样做的,eg. here

顺便说一句:我建议直接使用最新的MediaInfoLib,而不是 MediaInfoLib-android 中未维护、4 岁、未记录、修改过的版本。我在短短几分钟内就让当前的Java JNI example 运行(在 Windows 上)。也应该适用于 Android(请参阅 MediaInfoJNI.cpp)。

【讨论】:

  • 我知道它已经过时了,但我不知道如何使用MediaInfoJNI.cpp 构建,我尝试构建.so 文件,构建起来也很复杂。
  • 您不必自己构建 .so。只需从 mediaarea.net/en/MediaInfo/Download/Android 下载 Android 二进制文件 (.apk),将其打开为 .zip 并使用 lib/ 文件夹中的 *.so。
  • streamNumber 0 有效吗?如果是这样,您可能会考虑接受我的回答。
  • 是的,它有效,但我需要澄清一下。当我将参数从Format 更改为Bit rate 时,我没有得到任何值,是否有任何文档?此外,当我使用 .apk 中的.SO 文件时,我收到此错误JNI_ERR returned from JNI_OnLoad。那么您能否提供一个简短指南,说明如何从 MediInfoLib 生成.SO
  • 对于文档,我会参考github.com/MediaArea/MediaInfoLib中的代码和示例。我所做的是克隆存储库并在目录中搜索我正在寻找的东西。例如,搜索“比特率”会得到Source/Resource/Text/Stream/Video.csv,我建议使用参数BitRate 而不是Bit rate
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-10-21
  • 2014-09-12
  • 2017-01-10
  • 2014-08-21
  • 1970-01-01
  • 1970-01-01
  • 2012-03-22
相关资源
最近更新 更多