All Products
Search
Document Center

ApsaraVideo Media Processing:Add a video file

Last Updated:Aug 28, 2023

This topic provides the sample code for using ApsaraVideo Media Processing (MPS) SDK for Python to add a video file to a media library. You can specify a workflow to process the video file.

Note

If the media library meets the triggering rules of a workflow, the workflow is triggered. Otherwise, the workflow is not triggered. For more information, see Workflow triggering rules for files.

import os

from urllib.parse import quote
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.AddMediaRequest import AddMediaRequest

# Obtain an AccessKey ID and an AccessKey secret from environment variables.
credentials = AccessKeyCredential(os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'], os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET'])
# The region_id parameter specifies the ID of the region in which your MPS service is deployed. For information about supported regions, see 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>'
# The input object must be URL-encoded.
oss_object = 'mps-test/input/video.mp4'

request = AddMediaRequest()
request.set_FileURL("http://" + bucket_name + ".oss-cn-shanghai.aliyuncs.com/" + quote(oss_object))
request.set_MediaWorkflowId("829be1a2c3de957e341****")

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