全部产品

转码模板

本篇文档提供了C/C++ SDK转码模板模块相关功能的API调用示例。包含添加转码模板组、修改转码模板组、删除转码模板组、查询转码模板组、设置默认转码模板组等。

初始化客户端

使用前请先初始化客户端,请参见初始化

添加转码模板组

调用AddTranscodeTemplateGroup接口,完成添加转码模板组功能。

接口参数和返回字段请参见AddTranscodeTemplateGroup。调用示例如下:

#include <stdio.h>
#include <string>
#include <map>
#include <jsoncpp/json/json.h>
#include "vod_sdk/openApiUtil.h"

/**
 * 构建需要添加的转码模板配置数据
 */
Json::Value buildTranscodeTemplateList() {
    Json::Value transcodeTemplateList;
    Json::Value transcodeTemplate;
    //视频流转码配置
    Json::Value video;
    video["Width"] = 640;
    video["Bitrate"] = 400;
    video["Fps"] = 25;
    video["Remove"] = false;
    video["Codec"] = "H.264";
    video["Gop"] = "250";
    transcodeTemplate["Video"] = video;

    //音频流转码配置
    Json::Value audio;
    audio["Codec"] = "AAC";
    audio["Bitrate"] = "64";
    audio["Channels"] = "2";
    audio["Samplerate"] = "32000";
    transcodeTemplate["Audio"] = audio;

    //封装容器
    Json::Value container;
    container["Format"] = "mp4";
    transcodeTemplate["Container"] = container;

    //条件转码配置
    Json::Value transconfig;
    transconfig["IsCheckReso"] = false;
    transconfig["IsCheckResoFail"] = false;
    transconfig["IsCheckVideoBitrate"] = false;
    transconfig["IsCheckVideoBitrateFail"] = false;
    transconfig["IsCheckAudioBitrate"] = false;
    transconfig["IsCheckAudioBitrateFail"] = false;
    transcodeTemplate["TransConfig"] = transconfig;

    //加密配置(只支持m3u8)
    //Json::Value encryptSetting;
    //encryptSetting["EncryptType"] = "Private";
    //transcodeTemplate["EncryptSetting"] = encryptSetting;

    //清晰度
    transcodeTemplate["Definition"] = "LD";

    //模板名称
    transcodeTemplate["TemplateName"] = "testtemplate";

    //水印ID(多水印关联)
    Json::Value watermarkIdList;
    watermarkIdList.append("263261bdc1ff65782f8995c6dd22****");
    //USER_DEFAULT_WATERMARK 代表默认水印ID
    watermarkIdList.append("USER_DEFAULT_WATERMARK");
    transcodeTemplate["WatermarkIds"] = watermarkIdList;
    transcodeTemplateList.append(transcodeTemplate);
    return transcodeTemplateList;
}

/**
 * 添加转码模板组配置
 */
VodApiResponse addTranscodeTemplateGroup(VodCredential authInfo) {
    string apiName = "AddTranscodeTemplateGroup";
    map<string, string> args;
    args["Name"] = "grouptest";
    args["TranscodeTemplateList"] = buildTranscodeTemplateList().toStyledString();
    return getAcsResponse(authInfo, apiName, args);
}

// 请求示例
void main() {
    VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
    VodApiResponse response = addTranscodeTemplateGroup(authInfo);
    printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}

修改转码模板组

调用UpdateTranscodeTemplateGroup接口,完成修改转码模板组功能。

接口参数和返回字段请参见UpdateTranscodeTemplateGroup。调用示例如下:

#include <stdio.h>
#include <string>
#include <map>
#include <jsoncpp/json/json.h>
#include "vod_sdk/openApiUtil.h"

/**
 * 构建需要添加的转码模板配置数据
 */
Json::Value buildTranscodeTemplateList() {
    Json::Value transcodeTemplateList;
    Json::Value transcodeTemplate;
    //视频流转码配置
    Json::Value video;
    video["Width"] = 640;
    video["Bitrate"] = 400;
    video["Fps"] = 25;
    video["Remove"] = false;
    video["Codec"] = "H.264";
    video["Gop"] = "250";
    transcodeTemplate["Video"] = video;

    //音频流转码配置
    Json::Value audio;
    audio["Codec"] = "AAC";
    audio["Bitrate"] = "64";
    audio["Channels"] = "2";
    audio["Samplerate"] = "32000";
    transcodeTemplate["Audio"] = audio;

    //封装容器
    Json::Value container;
    container["Format"] = "mp4";
    transcodeTemplate["Container"] = container;

    //条件转码配置
    Json::Value transconfig;
    transconfig["IsCheckReso"] = false;
    transconfig["IsCheckResoFail"] = false;
    transconfig["IsCheckVideoBitrate"] = false;
    transconfig["IsCheckVideoBitrateFail"] = false;
    transconfig["IsCheckAudioBitrate"] = false;
    transconfig["IsCheckAudioBitrateFail"] = false;
    transcodeTemplate["TransConfig"] = transconfig;

    //加密配置(只支持m3u8)
    //Json::Value encryptSetting;
    //encryptSetting["EncryptType"] = "Private";
    //transcodeTemplate["EncryptSetting"] = encryptSetting;

    //模板名称
    transcodeTemplate["TemplateName"] = "testtemplate";

    //需要修改的转码模板ID
    transcodeTemplate["TranscodeTemplateId"] = "85c2b18ac08fda33e8f6d9c56****";

    //水印ID(多水印关联)
    Json::Value watermarkIdList;
    watermarkIdList.append("263261bdc1ff65782f8995c6dd22****");
    //USER_DEFAULT_WATERMARK 代表默认水印ID
    watermarkIdList.append("USER_DEFAULT_WATERMARK");
    transcodeTemplate["WatermarkIds"] = watermarkIdList;
    transcodeTemplateList.append(transcodeTemplate);
    return transcodeTemplateList;
}

/**
 * 修改转码模板组配置
 */
VodApiResponse updateTranscodeTemplateGroup(VodCredential authInfo) {
    string apiName = "UpdateTranscodeTemplateGroup";
    map<string, string> args;
    //转码模板组ID
    args["TranscodeTemplateGroupId"] = "4c71a339fecec0152b4fa6f452****";
    args["Name"] = "grouptest";
    args["TranscodeTemplateList"] = buildTranscodeTemplateList().toStyledString();
    return getAcsResponse(authInfo, apiName, args);
}

// 请求示例
void main() {
    VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
    VodApiResponse response = updateTranscodeTemplateGroup(authInfo);
    printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}

查询转码模板组列表

调用ListTranscodeTemplateGroup接口,完成查询转码模板组列表功能。

接口参数和返回字段请参见ListTranscodeTemplateGroup。调用示例如下:

#include <stdio.h>
#include <string>
#include <map>
#include <jsoncpp/json/json.h>
#include "vod_sdk/openApiUtil.h"

/**
 * 查询转码模板组列表
 */
VodApiResponse listTranscodeTemplateGroup(VodCredential authInfo) {
    string apiName = "ListTranscodeTemplateGroup";
    map<string, string> args;
    return getAcsResponse(authInfo, apiName, args);
}

// 请求示例
void main() {
    VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
    VodApiResponse response = listTranscodeTemplateGroup(authInfo);
    printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}

查询单个转码模板组

调用GetTranscodeTemplateGroup接口,完成查询单个转码模板组功能。

接口参数和返回字段请参见GetTranscodeTemplateGroup。调用示例如下:

#include <stdio.h>
#include <string>
#include <map>
#include <jsoncpp/json/json.h>
#include "vod_sdk/openApiUtil.h"

/**
 * 查询单个转码模板组配置
 */
VodApiResponse getTranscodeTemplateGroup(VodCredential authInfo) {
    string apiName = "GetTranscodeTemplateGroup";
    map<string, string> args;
    args["TranscodeTemplateGroupId"] = "a0fa0fda545e50e7a3eb75491****";
    return getAcsResponse(authInfo, apiName, args);
}

// 请求示例
void main() {
    VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
    VodApiResponse response = getTranscodeTemplateGroup(authInfo);
    printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}

设置默认转码模板组

调用SetDefaultTranscodeTemplateGroup接口,完成设置默认转码模板组功能。

接口参数和返回字段请参见SetDefaultTranscodeTemplateGroup。调用示例如下:

#include <stdio.h>
#include <string>
#include <map>
#include <jsoncpp/json/json.h>
#include "vod_sdk/openApiUtil.h"

/**
 * 设置默认转码模板组
 */
VodApiResponse setDefaultTranscodeTemplateGroup(VodCredential authInfo) {
    string apiName = "SetDefaultTranscodeTemplateGroup";
    map<string, string> args;
    args["TranscodeTemplateGroupId"] = "a0fa0fda545e50e7a3eb75491****";
    return getAcsResponse(authInfo, apiName, args);
}

// 请求示例
void main() {
    VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
    VodApiResponse response = setDefaultTranscodeTemplateGroup(authInfo);
    printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}

删除转码模板组

调用DeleteTranscodeTemplateGroup接口,完成删除转码模板组功能。

接口参数和返回字段请参见DeleteTranscodeTemplateGroup。调用示例如下:

#include <stdio.h>
#include <string>
#include <map>
#include <jsoncpp/json/json.h>
#include "vod_sdk/openApiUtil.h"


/**
 * 删除转码模板组配置
 */
VodApiResponse deleteTranscodeTemplateGroup(VodCredential authInfo) {
    string apiName = "DeleteTranscodeTemplateGroup";
    map<string, string> args;
    args["TranscodeTemplateGroupId"] = "a0fa0fda545e50e7a3eb75491****";
    return getAcsResponse(authInfo, apiName, args);
}

// 请求示例
void main() {
    VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
    VodApiResponse response = deleteTranscodeTemplateGroup(authInfo);
    printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}