文档

获取媒体元信息

更新时间:

通过视频管理功能获取媒体文件元信息,如分辨率、码率、帧率、编码标准等。用于媒体检索、播放展示、智能管理等,提升媒体的运营与管理效率。

应用场景

筛选检索

以某个媒体元信息作为检索条件,进行精确匹配、前(后)缀匹配、模糊匹配等多种检索方式,查找期望的媒体文件列表。

媒体管理

根据媒体元信息,如分辨率、码率、帧率、编码标准等对媒体文件进行分类管理,在此基础上根据业务规则进行播放展示。

支持音视频格式列表

分类

格式

音频

AAC、MP3、AC3、OPUS等多种音频格式。

视频

MP4、MPEG-TS、MKV、MOV、AVI、FLV、M3U8等多种视频格式。

前提条件

使用方法

调用DetectMediaMeta - 获取媒体文件元信息接口获取媒体元信息。

如下以在名称为test-project的IMM项目中,获取OSS路径为oss://test-bucket/test-object.mp4的媒体元信息为例。

请求示例

{
    "ProjectName": "test-project",
   "SourceURI": "oss://test-bucket/test-object.mp4"
}

返回示例

{
    "ProduceTime": "2022-04-24T02:39:57Z",
    "VideoStreams": [
        {
            "CodecTag": "0x31637661",
            "FrameRate": "60/1",
            "ColorSpace": "bt709",
            "FrameCount": 220,
            "Duration": 3.665678,
            "ColorRange": "tv",
            "CodecName": "h264",
            "Bitrate": 19908892,
            "BitDepth": 8,
            "Profile": "High",
            "CodecTagString": "avc1",
            "HasBFrames": 1,
            "AverageFrameRate": "19800000/329911",
            "ColorPrimaries": "bt709",
            "Language": "en",
            "CodecLongName": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
            "Height": 1080,
            "PixelFormat": "yuv420p",
            "Level": 42,
            "Width": 1920,
            "TimeBase": "1/90000",
            "ColorTransfer": "bt709"
        }
    ],
    "RequestId": "09A12708-A41D-0356-AB0E-0F2BCE*****",
    "Size": 10432415,
    "VideoWidth": 1920,
    "FormatLongName": "QuickTime / MOV",
    "Duration": 3.7141,
    "Bitrate": 22470940,
    "AudioStreams": [
        {
            "CodecTag": "0x6134706d",
            "ChannelLayout": "stereo",
            "FrameCount": 173,
            "StartTime": 0.0235,
            "Index": 1,
            "Duration": 3.690667,
            "CodecName": "aac",
            "Bitrate": 320087,
            "SampleFormat": "fltp",
            "Channels": 2,
            "CodecTagString": "mp4a",
            "SampleRate": 48000,
            "Language": "en",
            "CodecLongName": "AAC (Advanced Audio Coding)",
            "TimeBase": "1/48000"
        }
    ],
    "Addresses": [
        {
            "Language": "zh-Hans",
            "Township": "望京街道",
            "AddressLine": "北京市朝阳区望京街道东田运动健身游泳俱乐部宝星华庭公寓",
            "Country": "中国",
            "City": "",
            "District": "朝阳区",
            "Province": "北京市"
        }
    ],
    "StreamCount": 2,
    "VideoHeight": 1080,
    "FormatName": "mov,mp4,m4a,3gp,3g2,mj2",
    "LatLong": "+39.998800,+116.480900"
}

示例代码

以Python SDK为例,获取媒体元信息的完整示例代码如下。

# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import sys
import os
from typing import List

from alibabacloud_imm20200930.client import Client as imm20200930Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_imm20200930 import models as imm_20200930_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient


class Sample:
    def __init__(self):
        pass

    @staticmethod
    def create_client(
        access_key_id: str,
        access_key_secret: str,
    ) -> imm20200930Client:
        """
        使用AccessKey ID&AccessKey Secret初始化账号Client。
        @param access_key_id:
        @param access_key_secret:
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config(
            access_key_id=access_key_id,
            access_key_secret=access_key_secret
        )
        # 填写访问的IMM域名。
        config.endpoint = f'imm.cn-beijing.aliyuncs.com'
        return imm20200930Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        # 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
        # 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
        # 本示例通过从环境变量中读取AccessKey,来实现API访问的身份验证。如何配置环境变量,请参见https://help.aliyun.com/document_detail/2361894.html。
        imm_access_key_id = os.getenv("AccessKeyId")
        imm_access_key_secret = os.getenv("AccessKeySecret")
        client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
        get_media_meta_request = imm_20200930_models.GetMediaMetaRequest(
            project_name='test-project',
            source_uri='oss://test-bucket/test-object.mp4'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印API的返回值。
            client.get_media_meta_with_options(get_media_meta_request, runtime)
        except Exception as error:
            # 如有需要,请打印错误信息。
            UtilClient.assert_as_string(error.message)

    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        # 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
        # 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
        # 本示例通过从环境变量中读取AccessKey,来实现API访问的身份验证。如何配置环境变量,请参见https://help.aliyun.com/document_detail/2361894.html。
        imm_access_key_id = os.getenv("AccessKeyId")
        imm_access_key_secret = os.getenv("AccessKeySecret")
        client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
        get_media_meta_request = imm_20200930_models.GetMediaMetaRequest(
            project_name='test-project',
            source_uri='oss://test-bucket/test-object.mp4'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印API的返回值。
            await client.get_media_meta_with_options_async(get_media_meta_request, runtime)
        except Exception as error:
            # 如有需要,请打印错误信息。
            UtilClient.assert_as_string(error.message)


if __name__ == '__main__':
    Sample.main(sys.argv[1:])