All Products
Search
Document Center

Transcoding template

Last Updated: Jul 11, 2019

Initialize a client

Initialize a client before using the SDK. For more information, see initVodClient.

Add a transcoding template group

For more information about the request and response parameters, see AddTranscodeTemplateGroup.

/**
 * Method for constructing the transcoding template configuration
 * @return
 */
function buildTranscodeTemplateList() {
    $transcodeTemplateList = array();
    $transcodeTemplate = array();

    // Specifies the video stream transcoding configuration.
    $video = array();
    $video["Width"] = 640;
    $video["Bitrate"] = 400;
    $video["Fps"] = 25;
    $video["Remove"] = false;
    $video["Codec"] = "H. 264";
    $video["Gop"] = 250;
    $transcodeTemplate["Video"] = $video;

    // Specifies the audio stream transcoding configuration.
    $audio = array();
    $audio["Codec"] = "AAC";
    $audio["Bitrate"] = 64;
    $audio["Channels"] = 2;
    $audio["Samplerate"] = 32000;
    $transcodeTemplate["Audio"] = $audio;

    // Specifies the encapsulation container.
    $container = array();
    $container["Format"] = "mp4";
    $transcodeTemplate["Container"] = $container;

    // Specifies the conditional transcoding configuration.
    $transconfig = array();
    $transconfig["IsCheckReso"] = false;
    $transconfig["IsCheckResoFail"] = false;
    $transconfig["IsCheckVideoBitrate"] = false;
    $transconfig["IsCheckVideoBitrateFail"] = false;
    $transconfig["IsCheckAudioBitrate"] = false;
    $transconfig["IsCheckAudioBitrateFail"] = false;
    $transcodeTemplate["TransConfig"] = $transconfig;

    // Specifies the encryption configuration, which supports only the M3U8 format.
    //$encryptSetting= array();
    //$encryptSetting["EncryptType"] = "Private";
    //$transcodeTemplate["EncryptSetting"] = $encryptSetting;

    // Sets the definition.
    $transcodeTemplate["Definition"] = "LD";

    // Sets the template name.
    $transcodeTemplate["TemplateName"] = "testtemplate";

    // Associates watermark IDs with transcoding template IDs.
    $watermarkIdList= array();
    $watermarkIdList[] = "263261bdc1ff65782f8995c6ddxxxxxx";
    // USER_DEFAULT_WATERMARK indicates the default watermark ID.
    $watermarkIdList[] = "USER_DEFAULT_WATERMARK";
    $transcodeTemplate["WatermarkIds"] = $watermarkIdList;
    $transcodeTemplateList[] = $transcodeTemplate;

    return json_encode($transcodeTemplateList);
}

/**
 * Method for adding a transcoding template group
 */
function addTranscodeTemplateGroup($client) {
    $request = new vod\AddTranscodeTemplateGroupRequest();
    // Sets the name of the transcoding template group.
    $request->setName("grouptest");
    // Configures the transcoding template group.
    $request->setTranscodeTemplateList(buildTranscodeTemplateList()); 

    return $client->getAcsResponse($request);
}

/**
 * Call example
 */
try {
    $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');
    $result = addTranscodeTemplateGroup($client);

    var_dump($result);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

Modify a transcoding template group

For more information about the request and response parameters, see UpdateTranscodeTemplateGroup.

/**
 * Method for constructing the transcoding template configuration
 * @return
 */
function buildTranscodeTemplateList() {
    $transcodeTemplateList = array();
    $transcodeTemplate = array();

    // Specifies the video stream transcoding configuration.
    $video = array();
    $video["Width"] = 960;
    $video["Bitrate"] = 900;
    $video["Fps"] = 25;
    $video["Remove"] = false;
    $video["Codec"] = "H. 264";
    $video["Gop"] = 250;
    $transcodeTemplate["Video"] = $video;

    // Specifies the audio stream transcoding configuration.
    $audio = array();
    $audio["Codec"] = "AAC";
    $audio["Bitrate"] = 96;
    $audio["Channels"] = 2;
    $audio["Samplerate"] = 32000;
    $transcodeTemplate["Audio"] = $audio;

    // Specifies the encapsulation container.
    $container = array();
    $container["Format"] = "mp4";
    $transcodeTemplate["Container"] = $container;

    // Specifies the conditional transcoding configuration.
    $transconfig = array();
    $transconfig["IsCheckReso"] = false;
    $transconfig["IsCheckResoFail"] = false;
    $transconfig["IsCheckVideoBitrate"] = false;
    $transconfig["IsCheckVideoBitrateFail"] = false;
    $transconfig["IsCheckAudioBitrate"] = false;
    $transconfig["IsCheckAudioBitrateFail"] = false;
    $transcodeTemplate["TransConfig"] = $transconfig;

    // Specifies the encryption configuration, which supports only the M3U8 format.
    //$encryptSetting= array();
    //$encryptSetting["EncryptType"] = "Private";
    //$transcodeTemplate["EncryptSetting"] = $encryptSetting;

    // Sets the definition.
    $transcodeTemplate["Definition"] = "SD";

    // Sets the template name.
    $transcodeTemplate["TemplateName"] = "testtemplate";

    // Sets the template ID.
    $transcodeTemplate["TranscodeTemplateId"] = "214a67fab9fdf920f486faa77xxxxxx";

    // Associates watermark IDs with transcoding template IDs.
    $watermarkIdList= array();
    $watermarkIdList[] = "263261bdc1ff65782f8995c6ddxxxxxx";
    // USER_DEFAULT_WATERMARK indicates the default watermark ID.
    $watermarkIdList[] = "USER_DEFAULT_WATERMARK";
    $transcodeTemplate["WatermarkIds"] = $watermarkIdList;
    $transcodeTemplateList[] = $transcodeTemplate;

    return json_encode($transcodeTemplateList);
}

/**
 * Method for modifying a transcoding template group
 */
function updateTranscodeTemplateGroup($client) {
    $request = new vod\UpdateTranscodeTemplateGroupRequest();
    // Sets the name of the transcoding template group.
    $request->setName("grouptest1"); 
    // Sets the ID of the transcoding template group.
    $request->setTranscodeTemplateGroupId("014a67fab9fdf920f486faa77xxxxxx");
    // Configures the transcoding template group.
    $request->setTranscodeTemplateList(buildTranscodeTemplateList());

    return $client->getAcsResponse($request);
}

/**
 * Call example
 */
try {
    $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');
    $result = updateTranscodeTemplateGroup($client);

    var_dump($result);
} catch (Exception $e) {
    print $e->getMessage()."\n"; 
}

Query a list of transcoding template groups

For more information about the request and response parameters, see ListTranscodeTemplateGroup.

/**
 * Method for querying a list of transcoding template groups
 */
function listTranscodeTemplateGroup($client) {
    $request = new vod\ListTranscodeTemplateGroupRequest();
    return $client->getAcsResponse($request); 
}

/**
 * Call example
 */
try {
    $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');
    $result = listTranscodeTemplateGroup($client);

    var_dump($result);
} catch (Exception $e) {
    print $e->getMessage()."\n"; 
}

Query a transcoding template group

For more information about the request and response parameters, see GetTranscodeTemplateGroup.

/**
 * Method for querying a transcoding template group
 */
function getTranscodeTemplateGroup($client) {
    $request = new vod\GetTranscodeTemplateGroupRequest();
    // Sets the ID of the transcoding template group.
    $request->setTranscodeTemplateGroupId("014a67fab9fdf920f486faa77xxxxxx");

    return $client->getAcsResponse($request);
}

/**
 * Call example
 */
try {
    $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');
    $result = getTranscodeTemplateGroup($client);

    var_dump($result);
} catch (Exception $e) {
    print $e->getMessage()."\n"; 
}

Set the default transcoding template group

For more information about the request and response parameters, see SetDefaultTranscodeTemplateGroup.

/**
 * Method for setting the default transcoding template group
 */
function setDefaultTranscodeTemplateGroup($client) {
    $request = new vod\SetDefaultTranscodeTemplateGroupRequest();
    // Sets the ID of the transcoding template group.
    $request->setTranscodeTemplateGroupId("014a67fab9fdf920f486faa77xxxxxx");

    return $client->getAcsResponse($request);
}

/**
 * Call example
 */
try {
    $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>'); 
    $result = setDefaultTranscodeTemplateGroup($client);

    var_dump($result);
} catch (Exception $e) {
    print $e->getMessage()."\n"; 
}

Delete a transcoding template group

For more information about the request and response parameters, see DeleteTranscodeTemplateGroup.

/**
 * Method for deleting a transcoding template group
 */
function deleteTranscodeTemplateGroup($client) {
    $request = new vod\DeleteTranscodeTemplateGroupRequest();
    // Sets the ID of the transcoding template group.
    $request->setTranscodeTemplateGroupId("014a67fab9fdf920f486faa773xxxxxx");

    return $client->getAcsResponse($request);
}

/**
 * Call example
 */
try {
    $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');
    $result = deleteTranscodeTemplateGroup($client);

    var_dump($result);
} catch (Exception $e) {
    print $e->getMessage()."\n"; 
}