本篇文档提供了C/C++ SDK媒体处理模块相关功能的API调用示例,包含提交转码作业、提交截图作业、查询截图数据、导播台视频预处理。
初始化客户端
使用前请先初始化客户端,请参见初始化。
提交转码作业
调用SubmitTranscodeJobs接口,完成提交转码作业-普通功能。
接口参数和返回字段请参见SubmitTranscodeJobs。调用示例如下:
#include <stdio.h>
#include <string>
#include <map>
#include <jsoncpp/json/json.h>
#include "vod_sdk/openApiUtil.h"
/**
* 1、构建覆盖参数,目前只支持图片水印文件地址、文字水印的内容覆盖;
* 2、需要替换的水印信息对应水印ID必须是关联在指定的模板ID(即TranscodeTemplateId)中;
* 3、不支持通过媒体处理接口去增加一个没有关联上的水印
* 注意:图片水印的文件存储源站需要和发起转码的视频存储源站一致
*/
Json::Value buildOverrideParams() {
Json::Value overrideParams;
Json::Value watermarks;
Json::Value watermark1;
watermark1["WatermarkId"] = "2ea587477c5a1bc8b57****";
//需要替换成对应图片水印文件的OSS地址,水印文件存储源站需要和视频存储源站一致
watermark1["FileUrl"] = "https://outin-40564284ef05113e1403e7.oss-cn-shanghai.192.168.0.0/16/watermarks/02A1B22DF25D46C3C725A4****.png";
watermarks.append(watermark1);
//文字水印内容替换
Json::Value watermark2;
//模板上面关联需要替换内容的文字水印ID
watermark2["WatermarkId"] = "d297ba31ac5242d207****";
//需要替换成对应的内容
watermark2["Content"] = "用户ID:6****";
watermarks.append(watermark2);
overrideParams["Watermarks"] = watermarks;
return overrideParams;
}
/**
* 生成加密需要的秘钥,response中包含密文秘钥和明文秘钥,用户只需要将密文秘钥传递给点播即可
* 注意:KeySpec 必须传递AES_128,且不能设置NumberOfBytes
* @param serviceKey 点播提供生成秘钥的service key,在用户的秘钥管理服务中可看到描述为vod的加密key
*/
string generateDataKey(string serviceKey) {
string ciphertextBlob;
/*此处需实现KMS获取密文秘钥,详情参考KMS产品-GenerateDataKey接口*/
return ciphertextBlob;
}
/**
* 构建HLS标准加密的配置信息
*/
Json::Value buildEncryptConfig() {
//点播给用户在KMS(秘钥管理服务)中的Service Key,可在用户秘钥管理服务对应的区域看到描述为vod的service key
string serviceKey = "<Your Service Key>";
//随机生成一个加密的秘钥,返回的response包含明文秘钥以及密文秘钥,
//视频标准加密只需要传递密文秘钥即可
string ciphertextBlob = generateDataKey(serviceKey);
Json::Value encryptConfig;
//解密接口地址,该参数需要将每次生成的密文秘钥与接口URL拼接生成,表示每个视频的解密的密文秘钥都不一样
//至于Ciphertext这个解密接口参数的名称,用户可自行制定,这里只作为参考参数名称
encryptConfig["DecryptKeyUri"] = "http://192.168.0.0/16/decrypt?Ciphertext=" + ciphertextBlob;
//秘钥服务的类型,目前只支持KMS
encryptConfig["KeyServiceType"] = "KMS";
//密文秘钥
encryptConfig["CipherText"] = ciphertextBlob;
return encryptConfig;
}
/**
* 提交媒体处理作业
*/
VodApiResponse submitTranscodeJobs(VodCredential authInfo) {
string apiName = "SubmitTranscodeJobs";
map<string, string> args;
//需要转码的视频ID
args["VideoId"] = "34a6ca54f5c140eece85a289****";
//转码模板ID
args["TemplateGroupId"] = "e8aa925a9798c630d30cd7****";
//构建需要替换的水印参数(只有需要替换水印相关信息才需要构建)
//Json::Value overrideParams = buildOverrideParams();
//覆盖参数,暂只支持水印部分参数替换(只有需要替换水印相关信息才需要传递)
//args["OverrideParams"] = overrideParams.toStyledString();
//构建标准加密配置参数(只有标准加密才需要构建)
//Json::Value encryptConfig = buildEncryptConfig();
//HLS标准加密配置(只有标准加密才需要传递)
//args["EncryptConfig"] = encryptConfig.toStyledString();
return getAcsResponse(authInfo, apiName, args);
}
/**
* 以下为调用示例
*/
void main() {
VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
VodApiResponse response = submitTranscodeJobs(authInfo);
printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}
提交截图作业
#include <stdio.h>
#include <string>
#include <map>
#include <jsoncpp/json/json.h>
#include "vod_sdk/openApiUtil.h"
/**
* 构建雪碧图截图配置
* @return
*/
Json::Value buildSnapshotTemplateConfig() {
Json::Value spriteSnapshotConfig;
spriteSnapshotConfig["CellWidth"] = "120";
spriteSnapshotConfig["CellHeight"] = "68";
spriteSnapshotConfig["Columns"] = "3";
spriteSnapshotConfig["Lines"] = "10";
spriteSnapshotConfig["Padding"] = "20";
spriteSnapshotConfig["Margin"] = "50";
//保留雪碧图原始图
spriteSnapshotConfig["KeepCellPic"] = "keep";
spriteSnapshotConfig["Color"] = "tomato";
return spriteSnapshotConfig;
}
/**
* 提交媒体截图处理作业调用函数
*/
VodApiResponse submitSnapshotJob(VodCredential authInfo) {
string apiName = "SubmitSnapshotJob";
map<string, string> args;
//需要截图的视频ID(推荐传递截图模板ID)
args["VideoId"] = "4d237a8270084849bf4207876181****";
//截图模板ID
args["SnapshotTemplateId"] = "5d745e6b8baadf589e0702426cfc6****";
//如果设置了SnapshotTemplateId,会忽略下面参数
args["Count"] = "50";
args["SpecifiedOffsetTime"] = "0";
args["Interval"] = "1";
args["Width"] = "200";
args["Height"] = "200";
//雪碧图配置(如果需要)
Json::Value spriteSnapshotConfig = buildSnapshotTemplateConfig();
args["SpriteSnapshotConfig"] = spriteSnapshotConfig.toStyledString();
return getAcsResponse(authInfo, apiName, args);
}
// 请求示例
void main() {
VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
VodApiResponse response = submitSnapshotJob(authInfo);
printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}
查询截图数据
调用ListSnapshots接口,完成查询截图数据功能。
接口参数和返回字段请参见ListSnapshots。调用示例如下:
#include <stdio.h>
#include <string>
#include <map>
#include "vod_sdk/openApiUtil.h"
/**
* 查询截图数据
*/
VodApiResponse listSnapshots(VodCredential authInfo) {
string apiName = "ListSnapshots";
map<string, string> args;
//视频ID
args["VideoId"] = "c86c0ceba9796535****";
args["SnapshotType"] = "CoverSnapshot";
args["PageNo"] = "1";
args["PageSize"] = "20";
return getAcsResponse(authInfo, apiName, args);
}
// 请求示例
void main() {
VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
VodApiResponse response = listSnapshots(authInfo);
printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}
导播台视频预处理
调用SubmitPreprocessJobs接口,完成导播台视频预处理功能。
接口参数和返回字段请参见SubmitPreprocessJobs。调用示例如下:
#include <stdio.h>
#include <string>
#include <map>
#include "vod_sdk/openApiUtil.h"
/**
* 导播台视频预处理
*/
VodApiResponse submitPreprocessJobs(VodCredential authInfo) {
string apiName = "SubmitPreprocessJobs";
map<string, string> args;
//视频ID
args["VideoId"] = "c86c0ceba97965352418";
args["PreprocessType"] = "PreprocessType";
return getAcsResponse(authInfo, apiName, args);
}
// 请求示例
void main() {
VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
VodApiResponse response = submitPreprocessJobs(authInfo);
printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}
在文档使用中是否遇到以下问题
更多建议
匿名提交