Intelligent Media Management (IMM) allows you to query media metadata, such as the resolution, bitrate, frame rate, and encoding protocol. You can then use the media metadata to retrieve media files, display media information during playback, and intelligently manage the media files. This improves the efficiency of media file management.
Scenarios
Data filtering and retrieval
You can use media metadata as the filtering condition to retrieve the desired media files by using different matching methods, such as exact match, prefix or suffix match, and fuzzy match.
Media management
You can classify and manage media files based on media metadata, such as the resolution, bitrate, frame rate, and encoding protocol. You can choose to play certain videos based on specified metadata conditions.
Supported audio and video formats
Category | Format |
Audio | Mainstream audio formats, such as AAC, MP3, AC3, Opus |
Video | Mainstream video formats, such as MP4, MPEG-TS, MKV, MOV, AVI, FLV, and M3U8. |
Prerequisites
An AccessKey pair is created and obtained. For more information, see Create an AccessKey pair.
OSS is activated, a bucket is created, and objects are uploaded to the bucket. For more information, see Upload objects.
IMM is activated. For more information, see Activate IMM.
A project is created in the IMM console. For more information, see Create a project.
NoteYou can call the CreateProject operation to create a project. For more information, see CreateProject.
You can call the ListProjects operation to query the existing projects in a specific region. For more information, see ListProjects.
Usage
Call the DetectMediaMeta operation to query media metadata.
The following example queries the metadata of the media file oss://test-bucket/test-object.mp4 in an IMM project named test-project.
Sample request
{
"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",
"City": "",
}
],
"StreamCount": 2,
"VideoHeight": 1080,
"FormatName": "mov,mp4,m4a,3gp,3g2,mj2",
"LatLong": "+39.998800,+116.480900"
}The following sample code queries media metadata by using IMM SDK for Python:
# -*- 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:
"""
Use your AccessKey ID and AccessKey secret to initialize the client.
@return: Client
@throws Exception
"""
# If the project code is leaked, the AccessKey pair may be leaked and the security of all resources in your account may be compromised. The following lines are provided for reference only.
# For security reasons, we recommend that you use temporary access credentials that are provided by Security Token Service (STS). For more information, visit https://www.alibabacloud.com/help/en/sdk/developer-reference/v2-manage-php-access-credentials.
config = open_api_models.Config(
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured. ,
access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
# Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured. ,
access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
)
# Specify the IMM endpoint. For a list of IMM endpoints for supported regions, visit https://api.alibabacloud.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:
# Print the response of the API operation if necessary.
client.detect_media_meta_with_options(detect_media_meta_request, runtime)
except Exception as error:
# Handle exceptions with caution in your actual business scenario and never ignore exceptions in your project. In this example, error messages are printed.
# Display error messages.
print(error.message)
# Show the URL for troubleshooting.
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:
# Print the response of the API operation if necessary.
await client.detect_media_meta_with_options_async(detect_media_meta_request, runtime)
except Exception as error:
# Handle exceptions with caution in your actual business scenario and never ignore exceptions in your project. In this example, error messages are printed.
# Display error messages.
print(error.message)
# Show the URL for troubleshooting.
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])