媒体处理
本文提供了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地址,水印文件存储源站需要和视频存储源站一致
//FileURL示例:https://example-bucket-****.oss-cn-shanghai.192.168.0.0/16/watermarks/02A1B22DF25D46C3C725A4****.png
watermark1["FileUrl"] = "<your File URL>";
watermarks.append(watermark1);
//文字水印内容替换
Json::Value watermark2;
//模板上面关联需要替换内容的文字水印ID
watermark2["WatermarkId"] = "d297ba31ac5242d207****";
//需要替换成对应的内容
watermark2["Content"] = "用户ID:6****";
watermarks.append(watermark2);
overrideParams["Watermarks"] = watermarks;
return overrideParams;
}
/**
* 生成加密需要的密钥,response中包含密文密钥和明文密钥,用户只需要将密文密钥传递给点播即可
*/
string generateDataKey(string serviceKey) {
string ciphertextBlob;
/*此处需实现KMS获取密文密钥,详情参考VOD产品-GenerateKMSDataKey接口*/
return ciphertextBlob;
}
/**
* 构建HLS标准加密的配置信息
*/
Json::Value buildEncryptConfig() {
//随机生成一个加密的密钥,返回的response包含明文密钥以及密文密钥
//视频标准加密只需要传递密文密钥即可
string ciphertextBlob = generateDataKey();
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());
}
提交截图作业
调用SubmitSnapshotJob接口,完成提交截图作业功能。
接口参数和返回字段请参见SubmitSnapshotJob。调用示例如下:
说明
创建截图模板详细请参见截图模板。
#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());
}