Polyv Help Center

Help Center

videoCutAndMerge

Updated: 2023-09-22 17:47:34

1. Submit Video Trimming Task

Description

通过视频id、时间范围裁剪视频并生成新的视频
接口地址(仅做说明使用):https://api.polyv.net/v2/video/%s/clip

Call Constraints

  1. The API call is subject to rate limits. For details, please see [/vod/java/limit]. For common call exceptions, please see [/vod/java/exceptionDoc].

Unit Test

    @Test
    public void testClipVideo() throws IOException, NoSuchAlgorithmException {
        VodClipVideoRequest vodClipVideoRequest = new VodClipVideoRequest();
        String vodClipVideoResponse = null;
        try {
            vodClipVideoRequest
                    //可通过 new VodQueryServiceImpl().queryVideoList()获取
                    .setVideoId("1b448be3238618df117f9302327f28d6_1")
                    .setTitle("junit裁剪")
                    .setTimeFrame("[{\"start\":1,\"end\":6}]");
            vodClipVideoResponse = new VodEditServiceImpl().clipVideo(vodClipVideoRequest);
            Assert.assertNotNull(vodClipVideoResponse);
            if (vodClipVideoResponse != null) {
                log.debug("测试提交视频裁剪任务成功,{}", JSON.toJSONString(vodClipVideoResponse));
            }
        } catch (PloyvSdkException e) {
            //参数校验不合格 或者 请求服务器端500错误,错误信息见PloyvSdkException.getMessage()
            log.error(e.getMessage(), e);
            // 异常返回做B端异常的业务逻辑,记录log 或者 上报到ETL 或者回滚事务
            throw e;
        } catch (Exception e) {
            log.error("SDK调用异常", e);
            throw e;
        }
    }

Unit Test Description

  1. If the request is correct, a String object is returned, and the B-side processes the business logic based on this object.

  2. If the request parameter validation fails, a PloyvSdkException is thrown. The error message can be found in PloyvSdkException.getMessage(), e.g., [ Input parameter [xxx.chat.VodxxxRequest] object validation failed, failed field [pic cannot be empty / msg cannot be empty] ].

  3. If the server encounters a processing exception, a PloyvSdkException is thrown. The error message can be found in PloyvSdkException.getMessage(), e.g., [ Error returned from Polyv request data, request serial number: 66e7ad29fd04425a84c2b2b562d2025b, error reason: invalid signature. ]

Request Parameter Description

Parameter Name Required Type Description
videoId true String Video ID [corresponds to the vid field in the API documentation]
title true String Name of the trimmed video
timeFrame true String JSON-formatted specific time segments, format: [{"start":1,"end":6},{"start":10,"end":16}]. The number of segments cannot exceed 5. The start time of each segment must not be greater than the end time. The interval between start and end time must be equal to or greater than 5 seconds. The end time must not exceed the video's playback duration.

Return Object Description

If the API request is successful, the videoId of the newly trimmed video is returned.




2. Merge Videos

Description

通过视频id合并视频并生成新的视频
接口地址(仅做说明使用):https://api.polyv.net/v2/video/%s/concat

Call Constraints

  1. The API call is subject to rate limits. For details, please see [/vod/java/limit]. For common call exceptions, please see [/vod/java/exceptionDoc].

Unit Test

    @Test
    public void testConcatVideo() throws IOException, NoSuchAlgorithmException {
        VodConcatVideoRequest vodConcatVideoRequest = new VodConcatVideoRequest();
        VodConcatVideoResponse vodConcatVideoResponse = null;
        try {
            vodConcatVideoRequest
                    //可通过 new VodQueryServiceImpl().queryVideoList()获取
                    .setVideoIds("1b448be3238618df117f9302327f28d6_1,1b448be3234406608b7838c7ef6b597c_1")
                    .setTitle("junit合并")
                    .setCategoryId("1602300731843")
                    .setScreenCap(1);
            vodConcatVideoResponse = new VodEditServiceImpl().concatVideo(vodConcatVideoRequest);
            Assert.assertNotNull(vodConcatVideoResponse);
            if (vodConcatVideoResponse != null) {
                log.debug("测试合并视频成功,{}", JSON.toJSONString(vodConcatVideoResponse));
            }
        } catch (PloyvSdkException e) {
            //参数校验不合格 或者 请求服务器端500错误,错误信息见PloyvSdkException.getMessage()
            log.error(e.getMessage(), e);
            // 异常返回做B端异常的业务逻辑,记录log 或者 上报到ETL 或者回滚事务
            throw e;
        } catch (Exception e) {
            log.error("SDK调用异常", e);
            throw e;
        }
    }
}

Unit Test Description

  1. If the request is correct, a VodConcatVideoResponse object is returned, and the B-side processes the business logic based on this object.

  2. If the request parameter validation fails, a PloyvSdkException is thrown. The error message can be found in PloyvSdkException.getMessage(), e.g., [ Input parameter [xxx.chat.VodxxxRequest] object validation failed, failed field [pic cannot be empty / msg cannot be empty] ].

  3. If the server encounters a processing exception, a PloyvSdkException is thrown. The error message can be found in PloyvSdkException.getMessage(), e.g., [ Error returned from Polyv request data, request serial number: 66e7ad29fd04425a84c2b2b562d2025b, error reason: invalid signature. ]

Request Parameter Description

Parameter Name Required Type Description
videoIds true String Video IDs, separated by commas. Only supports merging 2 or 3 videos [corresponds to the vids field in the API documentation]
title false String Video title, defaults to "merge-" + the title of the first video. Titles exceeding 128 characters will be truncated.
categoryId false String Category ID, defaults to the default category [corresponds to the cataId field in the API documentation]
screenCap false Integer Whether to enable screen recording optimization, 1 for enable, 0 for disable, defaults to disable [corresponds to the luping field in the API documentation]

Return Object Description

Parameter Name Type Description
concatVideoId String The videoId of the merged video [corresponds to the concatVid field in the API documentation]

联系客服,在线咨询