文档

转码

更新时间:

本文提供了PHP SDK转码的操作步骤及完整的代码示例。

转码相关API调用及参数详细信息请参见提交转码作业

完整代码

<?php
require_once './aliyun-php-sdk-core/Config.php'; 
use Mts\Request\V20140618 as Mts;

function initMtsClient($accessKeyId, $accessKeySecret) {
    $regionId = 'cn-shanghai';  // 服务接入区域
    $profile = DefaultProfile::getProfile($regionId, $accessKeyId, $accessKeySecret);
    return new DefaultAcsClient($profile);
}

try {
    $client = initMtsClient(getenv('ALIBABA_CLOUD_ACCESS_KEY_ID'), getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET'));
    $response = submitClipJob($client);
    print_r($response);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

function submitClipJob($client) {
    $pipelineId = 'd7cedd984be7dd63395c*****';   #管道ID  可在控制台查看
    $templateId = "S00000001-100020"; #转码模板ID,可在控制台查看
    $ossLocation = 'oss-cn-shanghai';
    $bucket = '<bucket name>';
    $ossInputObject = 'input.mp4';
    $ossOutputObject = 'output.mp4';
    $request = new Mts\SubmitJobsRequest();
    # input参数
    $input = array('Location' => $ossLocation,
               'Bucket' => $bucket,
               'Object' => urlencode($ossInputObject));

    # output参数
    $output = array('OutputObject' => urlencode($ossOutputObject));
    # 视频参数
    $output['Video'] = array('Codec' =>'H.264',
                            'Bitrate' => 1500,
                            'Width' => 1280,
                            'Fps' => 25);
    # 音频参数
    $output['Audio'] = array('Codec' => 'AAC',
                            'Bitrate' => 128,
                            'Channels' => 2,
                            'Samplerate' => 44100);
    $output['TemplateId'] = $templateId;

    $outputs = array($output);

    $request->setInput(json_encode($input));
    $request->setOUtputs(json_encode($outputs));
    $request->setOutputBucket($bucket);
    $request->setOutputLocation($ossLocation);
    $request->setPipelineId($$pipelineId);  
    return $client->getAcsResponse($request);
}
  • 本页导读 (1)
文档反馈