获取媒体元信息

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

应用场景

筛选检索

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

媒体管理

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

支持音视频格式列表

分类

格式

音频

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 os
import sys

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() -> imm20200930Client:
        """
        使用AK&SK初始化账号Client
        @return: Client
        @throws Exception
        """
        # 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
        # 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378659.html。
        config = open_api_models.Config(
            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。,
            access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
            # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。,
            access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
        )
        # Endpoint 请参考 https://api.aliyun.com/product/imm
        config.endpoint = f'imm.cn-hangzhou.aliyuncs.com'
        return imm20200930Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        detect_media_meta_request = imm_20200930_models.DetectMediaMetaRequest(
            project_name='test-project',
            source_uri='oss://test-bucket/test-object.mp4'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            client.detect_media_meta_with_options(detect_media_meta_request, runtime)
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)

    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        detect_media_meta_request = imm_20200930_models.DetectMediaMetaRequest(
            project_name='test-project',
            source_uri='oss://test-bucket/test-object.mp4'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # 复制代码运行请自行打印 API 的返回值
            await client.detect_media_meta_with_options_async(detect_media_meta_request, runtime)
        except Exception as error:
            # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            # 错误 message
            print(error.message)
            # 诊断地址
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)


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