智能点播VideoWorks

    媒资库操作

    上传素材

    使用如下代码可以上传一个视频/音频/图片到媒资库。

    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时返回。

    媒资库设置

    媒资库相关操作需要预先设置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.rmrb, 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.rmrb, notification);
        VideoEditCreateResponse response = client.createVideoEdit(request);
    }

    查询视频合成结果

    使用如下代码可以查询视频合成结果。

    private void pollingVideoEdit(BvwClient client) {
        long editId = 123;
        VideoEditPollingResponse response = client.pollingVideoEdit(editId);
    }
    上一篇
    异常处理
    下一篇
    版本更新记录