媒资库操作
更新时间:2022-11-15
普通素材
用户上传音频/视频/图片到素材库,创作视频时可从素材中心导入
上传素材
使用如下代码可以上传一个视频/音频/图片到媒资库。
private void upload(BvwClient client) {
String bucket = "<your bucket>";
String key = "<your key>";
String title = "<your media title>";
String mediaType = "video";
MatlibUploadRequest request = new MatlibUploadRequest(mediaType, title, bucket, key);
MatlibUploadResponse response = client.upload2Material(request);
}
上传媒资可以设置通知回调,在MatlibUploadRequest定义notification通知名称即可。
查询素材
使用如下代码可以从媒资库查询一个素材。
private void getMaterial(BvwClient client) {
String materialId = "16c97461e978571b3202172b527f219f";
MaterialGetResponse response = client.getMaterial(materialId);
}
materialId在上传素材upload2Material时返回。
搜索素材
使用如下代码可以从媒资库搜索指定条件的素材。
private void searchMaterial(BvwClient client) {
MaterialSearchRequest request = new MaterialSearchRequest();
request.setTitleKeyword("keyword");
MaterialSearchResponse response = client.searchMaterial(request);
}
删除素材
使用如下代码可以从媒资库删除一个素材。
private void deleteMaterial(BvwClient client) {
String materialId = "16c97461e978571b3202172b527f219f";
MaterialBaseResponse response = client.deleteMaterial(materialId);
}
预置素材
预置素材分为音乐/贴图/背景/字幕/转场,除了系统自带的预置素材外,用户可以自定义音乐/贴图预置素材。创作视频时,不需要导入,可直接使用
上传预置素材
使用如下代码可以上传一个音乐/贴图预置素材到媒资库。
private void uploadMaterialPreset(BvwClient client) {
MatlibUploadRequest request = new MatlibUploadRequest();
request.setBucket("your-bucket");
request.setKey("your-key");
request.setMediaType("audio");
request.setTitle("your-title");
MaterialPresetUploadResponse response = client.uploadMaterialPreset("MUSIC", request);
}
查询预置素材
使用如下代码可以查询一个指定预置素材。
private void getMaterialPreset(BvwClient client) {
String materialId = "89355c2e2bd5d22450d965d7381c0517";
MaterialPresetGetResponse response = client.getMaterialPreset(materialId);
}
搜索预置素材
使用如下代码可以从媒资库搜索指定条件的预置素材。
public void searchMaterialPreset() {
Integer pageNo = 1;
Integer pageSize = 10;
MaterialPresetSearchRequest request = new MaterialPresetSearchRequest();
request.setPageNo(pageNo);
request.setPageSize(pageSize);
MaterialPresetSearchResponse response = client.searchMaterialPreset(request);
}
删除预置素材
使用如下代码可以删除一个指定预置素材。
private void deleteMaterialPreset(BvwClient client) {
String materialId = "89355c2e2bd5d22450d965d7381c0517";
MaterialBaseResponse response = client.deleteMaterialPreset(materialId);
}
媒资库设置
媒资库相关操作需要预先设置bucket。
创建媒资库设置
使用如下代码可以创建媒资库设置,设置媒资库交互中使用的默认bucket。
private void createMatlibConfig(BvwClient client) {
MatlibConfigBaseRequest request = new MatlibConfigBaseRequest("bucket name");
client.createMatlibConfig(request);
}
更新媒资库设置
使用如下代码可以更新媒资库设置,设置媒资库交互中使用的默认bucket。
private void updateMatlibConfig(BvwClient client) {
MatlibConfigBaseRequest request = new MatlibConfigBaseRequest("bucket name");
client.updateMatlibConfig(request);
}
查询媒资库设置
使用如下代码可以查询媒资库设置,设置媒资库交互中使用的默认bucket。
private void getMatlibConfig(BvwClient client) {
MatlibConfigGetResponse respnse = client.getMatlibConfig();
}
智能配音
智能配音功能支持将一段文字按指定的发音类型转化为语音输出。
使用如下代码可以进行文字转语音。
private void text2Audio(BvwClient client) {
Text2AudioRequest request = new Text2AudioRequest(Lists.newArrayList(
"VideoWorks(原VOD音视频点播服务)以媒资为核心,提供了音视图文件的上传、存储、管理、编辑、转码、AI处理(审核、理解、去重)、分发、播放等全生命周期的PaaS服务。",
"VideoWorks致力于成为百度智能云上所有音视频的统一入口,目前已集成了BOS(对象存储)、CDN(内容分发)、MCT(音视频转码)、VCR(视频内容审核)产品,后续会接入VCA(视频内容分析)、智能编辑、智能去重等更多的音视频处理能力。",
"此外,VideoWorks引入了工作流(workflow)能力,用户可根据自身业务需求在console可视化灵活配置音视频的处理流程,一次任务下发即可按照既定流程处理完成,方便快捷。"
), Per.BASE_DUXIAOMEI);
Text2AudioResponse response = client.text2Audio(request);
}
视频合成
视频合成功能支持讲一端视频编辑的Timeline(不同媒体分类组成的时间轴数据)编码合成输出。
使用如下代码可以发起合成。
- 接收合成请求Timeline的Json字符串,直接发起合成。
private void createVideoEdit(BvwClient client) {
String jsonString = "{" +
" \"bucket\":\"testbucket111\"," +
" \"title\":\"default\"," +
" \"cmd\":{" +
" \"timeline\":{" +
" \"video\":[" +
" {" +
" \"key\": \"name\"," +
" \"list\": [" +
" {" +
" \"type\": \"image\"," +
" \"start\": 0," +
" \"end\": 10.5," +
" \"showStart\": 0," +
" \"showEnd\": 10.5," +
" \"width\": 1," +
" \"height\": 1," +
" \"xpos\": 0," +
" \"ypos\": 0," +
" \"duration\": 10.5," +
" \"extInfo\": {" +
" \"style\": \"relief\"," +
" \"lightness\": 0," +
" \"contrast\": 0," +
" \"saturation\": 0," +
" \"hue\": 0," +
" \"speed\": 1," +
" \"transitionStart\": \"white\"," +
" \"transitionEnd\": \"black\"," +
" \"transitionDuration\": 2," +
" \"mirror\":\"hori\"," +
" \"rotate\" : 180" +
" }," +
" \"mediaInfo\": {" +
" \"key\": \"77f70ad4cf57e46af1b1249999c62918.jpeg\"," +
" \"bucket\": \"testbucket111\"," +
" \"fileType\": \"image\"" +
" }," +
" \"uid\": \"d0a7a580-fe36-4baf-b4ac-193565925b01\"" +
" }" +
" ]" +
" }" +
" ]," +
" \"audio\":[" +
" {" +
" \"key\":\"name\"," +
" \"list\":[" +
" ]" +
" }" +
" ]," +
" \"sticker\":[" +
" ]," +
" \"subtitle\" : [" +
" ]" +
" }" +
" }" +
"}";
String notification = "notificationName";
Map<String, Object> editBody = new ObjectMapper().convertValue(JsonUtils.jsonNodeOf(jsonString), Map.class);
VideoEditCreateRequest request = new VideoEditCreateRequest(editBody, RefererType.baidu, notification);
VideoEditCreateResponse response = client.createVideoEdit(request);
}
- 自己组合Timeline数据对象
自己组合Timeline对象(Map<String, Object>) ,将组合好的符合Timeline规则对象作为参数传入VideoEditCreateRequest构造函数即可
private void createVideoEdit(BvwClient client, Map<String, Object> cmd) {
Map<String, Object> editBody = new HashMap<String, Object>();
String notification = "notificationName";
editBody.put("bucket", "userBucket");
editBody.put("title", "editTitle");
editBody.put("cmd", cmd);
VideoEditCreateRequest request = new VideoEditCreateRequest(editBody, RefererType.baidu, notification);
VideoEditCreateResponse response = client.createVideoEdit(request);
}
查询视频合成结果
使用如下代码可以查询视频合成结果。
private void pollingVideoEdit(BvwClient client) {
long editId = 123;
VideoEditPollingResponse response = client.pollingVideoEdit(editId);
}
创建草稿
private void createDraft(BvwClient client) {
MatlibTaskRequest request = new MatlibTaskRequest();
MatlibTaskResponse draft = client.createDraft(request);
}
更新草稿
private void updateDraft(BvwClient client) {
MatlibTaskRequest request = new MatlibTaskRequest();
// request 设置草稿的各个字段值
// 123为创建生成的草稿id
client.updateDraft(123, request);
}
获取草稿列表
private void listDraft(BvwClient client) {
DraftListRequest listRequest = DraftListRequest.of(1, 5);
listRequest.setStatus(MatlibTaskStatus.EDITING);
ListByPageResponse<MatlibTaskGetResponse> draftList = client.getDraftList(listRequest);
}
获取单条草稿
private void getDraft(BvwClient client) {
// 123为创建生成的草稿id
long id = 123L;
GetDraftResponse draft = client.getSingleDraft(id);
}