All Products
Search
Document Center

ApsaraVideo Media Processing:Query a media file based on its OSS URL

Last Updated:Aug 29, 2023

If you use a workflow to create a video-on-demand (VOD) file from a live stream, you cannot obtain the media ID of the live stream. In this case, you can call the QueryMediaListByURL operation to query the live stream by using its Object Storage Service (OSS) URL.

import os
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkcore.auth.credentials import AccessKeyCredential
from aliyunsdkmts.request.v20140618.QueryMediaListByURLRequest import QueryMediaListByURLRequest

# Obtain the AccessKey ID and AccessKey secret from environment variables.
credentials = AccessKeyCredential(os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'], os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET'])
# Set the region_id parameter to the ID of the region in which the service is called. For more information about the supported regions, see "Regions and endpoints" at https://www.alibabacloud.com/help/zh/apsaravideo-for-media-processing/latest/service-regions.
client = AcsClient(region_id = 'cn-shanghai', credential = credentials)
bucket_name = '<your bucket name>'

request = QueryMediaListByURLRequest()
request.set_accept_format('json')

request.set_FileURLs("http://" + bucket_name + ".oss-cn-shanghai.aliyuncs.com/mps-test/input/video.mp4")


response = client.do_action_with_exception(request)
# Display the output.
print(str(response, encoding='utf-8'))