Tüm Ürünler
Search
Belge Merkezi

ApsaraVideo Media Processing:Medya dosyalarını birleştirme ve kırpma

Son Güncelleme:Oct 04, 2026

Video birleştirme, farklı formatlara, bit hızlarına ve çözünürlüklere sahip videoları belirli bir format, bit hızı ve çözünürlükte daha uzun bir videoda birleştirmenizi sağlar. Bu işlem genellikle bir videoya başlangıç veya bitiş bölümü eklemek ya da kaydedilen canlı yayın kliplerini birleştirmek için kullanılır. Video kırpma ise orijinal bir videodan bir klip çıkarmanıza ve bu klibi yeni bir video olarak kaydetmenize olanak tanır. Genellikle videolardaki önemli anları öne çıkarmak amacıyla tercih edilir. Bu konuda, medya dosyalarını birleştirmek ve kırpmak için ApsaraVideo Media Processing (MPS) SDK for Python içinde kapsüllenmiş API işlemlerinin nasıl kullanılacağına ilişkin bir örnek sunulmaktadır.

Örnek kod

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

# 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'])
# The region_id parameter specifies the ID of the region in which your MPS service is deployed. For information about supported regions, visit 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 = '9ba1a2b3c561c22c4df9c6****'
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 job input.
job_input = {'Location': oss_location,
             'Bucket': oss_bucket,
             'Object': quote(head_object) }
request.set_Input(json.dumps(job_input))
# The job output.
output = {'OutputObject': quote(oss_output_object)}
output['TemplateId'] = template_id
output['Video'] = {'Width': 1280,
                   'Height': 720}
# The merge list for the job output.
# You must encode the Object Storage Service (OSS) URLs of the media files.
merge_video = {'MergeURL': 'http://%s.%s.aliyuncs.com/%s'%(oss_bucket, oss_location, quote(oss_input_object))}
merge_tail = {'MergeURL': 'http://%s.%s.aliyuncs.com/%s'%(oss_bucket, oss_location, quote(tail_object))}
output['MergeList'] = [merge_video, merge_tail]
# The job outputs.
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)
# Display the response.
print(str(response, encoding='utf-8'))

İlgili Konular