- AcsClient インスタンスを作成します。
client = AcsClient(access_key_id, access_key_secret, mps_region_id);
- リクエストを作成して、パラメーターを設定します。
request = SubmitSnapshotJobRequest.SubmitSnapshotJobRequest() request.set_accept_format('json')
- スクリーンショットのパラメーターを設定します。
- Input
job_input = {'Location': oss_location, 'Bucket': oss_bucket, 'Object': quote(head_object) } request.set_Input(json.dumps(job_input))
- SnapshotConfig
- OutputFile
job_output = {'Location': oss_location, 'Bucket': oss_bucket, 'Object': quote(oss_output_object) } snapshot_config = {'OutputFile': job_output}
- Time
snapshot_config['Time'] = 2
- Interval/Num
snapshot_config['Interval'] = 2 snapshot_config['Num'] = 3
- Width/Height
snapshot_config['Height'] = 360
- OutputFile
- Input
- API リクエストを開始して、戻り値を表示します。
response_str = client.do_action_with_exception(request) response = json.loads(response_str) print response print 'RequestId is:', response['RequestId'] print 'JobId is:', response['SnapshotJob']['Id'] print 'http://%s.%s.aliyuncs.com/output_00001.jpg' % (oss_bucket, oss_location) print 'http://%s.%s.aliyuncs.com/output_00002.jpg' % (oss_bucket, oss_location) print 'http://%s.%s.aliyuncs.com/output_00003.jpg' % (oss_bucket, oss_location)
コード全体
# -*- coding: utf8 -*-
import json
from urllib import quote
from aliyunsdkcore.client import AcsClient
from aliyunsdkmts.request.v20140618 import SubmitSnapshotJobRequest
access_key_id = 'xxx'
access_key_secret = 'xxx'
mps_region_id = 'cn-hangzhou'
pipeline_id = 'xxx'
oss_location = 'oss-cn-hangzhou'
oss_bucket = 'xxx'
oss_input_object = 'input.mp4'
oss_output_object = 'output_{Count}.jpg'
# AcsClient
client = AcsClient(access_key_id, access_key_secret, mps_region_id);
# request
request = SubmitSnapshotJobRequest.SubmitSnapshotJobRequest()
request.set_accept_format('json')
# Input
job_input = {'Location': oss_location,
'Bucket': oss_bucket,
'Object': quote(oss_input_object) }
request.set_Input(json.dumps(job_input))
# SnapshotConfig->OutputFile
job_output = {'Location': oss_location,
'Bucket': oss_bucket,
'Object': quote(oss_output_object) }
snapshot_config = {'OutputFile': job_output}
# SnapshotConfig->Time
snapshot_config['Time'] = 2
# SnapshotConfig->Interval/Num
snapshot_config['Interval'] = 2
snapshot_config['Num'] = 3
# SnapshotConfig->Width/Height
snapshot_config['Height'] = 360
# SnapshotConfig
request.set_SnapshotConfig(json.dumps(snapshot_config))
# PipelineId
request.set_PipelineId(pipeline_id)
# call api
response_str = client.do_action_with_exception(request)
response = json.loads(response_str)
print response
print 'RequestId is:', response['RequestId']
print 'JobId is:', response['SnapshotJob']['Id']
print 'http://%s.%s.aliyuncs.com/output_00001.jpg' % (oss_bucket, oss_location)
print 'http://%s.%s.aliyuncs.com/output_00002.jpg' % (oss_bucket, oss_location)
print 'http://%s.%s.aliyuncs.com/output_00003.jpg' % (oss_bucket, oss_location)