Lors de la production vidéo, vous pouvez intégrer des séquences de générique de début et de fin contenant des informations clés dans une vidéo principale à l'aide d'un effet Picture-in-Picture (PiP). Cette rubrique fournit un exemple de code illustrant comment configurer les génériques de début et de fin dans ApsaraVideo Media Processing via le kit de développement logiciel (SDK) Python.
Exemple de code
import os
import json
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.SubmitJobsRequest import SubmitJobsRequest
# Read the AccessKey ID and AccessKey secret from the environment variables.
credentials = AccessKeyCredential(os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'], os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET'])
# The region_id is the ID of the region where the service is invoked. For a list of supported regions, see https://www.alibabacloud.com/help/zh/apsaravideo-for-media-processing/latest/service-regions
client = AcsClient(region_id = 'cn-shanghai', credential = credentials)
mps_region_id = 'cn-shanghai'
pipeline_id = '9bad31a2c3d1c22c4df9c6****'
template_id = 'S00000001-200030'
oss_location = 'oss-cn-shanghai'
oss_bucket = '<your bucket name>'
oss_input_object = 'input.mp4'
oss_output_object = 'output.mp4'
head_object = 'head.mp4'
tail_object = 'tail.mp4'
request = SubmitJobsRequest()
request.set_accept_format('json')
# The structure of the Input parameter. The object must be URL encoded.
job_input = {'Location': oss_location,
'Bucket': oss_bucket,
'Object': quote(head_object) }
request.set_Input(json.dumps(job_input))
# The structure of the Output parameter.
output = {'OutputObject': quote(oss_output_object)}
output['TemplateId'] = template_id
# The structure of the Output->OpeningList parameter for the opening clip.
opening_video = {'OpenUrl': 'http://%s.%s.aliyuncs.com/%s'%(oss_bucket, oss_location, quote(head_object)),
'Width': 640,
'Start': 2}
output['OpeningList'] = [opening_video]
# The structure of the Output->TailSlateList parameter for the ending clip.
tailslate_video = {'TailUrl': 'http://%s.%s.aliyuncs.com/%s'%(oss_bucket, oss_location, quote(tail_object)),
'Width': 640,
'BlendDuration': 3,
'BgColor': 'Black'}
output['TailSlateList'] = [tailslate_video]
# The structure of the Outputs parameter.
outputs = [output]
request.set_Outputs(json.dumps(outputs))
request.set_OutputBucket(oss_bucket)
request.set_OutputLocation(oss_location)
request.set_PipelineId(pipeline_id)
response_str = client.do_action_with_exception(request)
response = json.loads(response_str)
# Print the output.
print(str(response, encoding='utf-8'))