# Video Cut And Merge

### 1、提交视频裁剪任务

#### 描述

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

#### 调用约束

1、接口调用有频率限制，[详细请查看](https://git.polyv.net/help-center/document-center/-/blob/master/vod/java/limit/README.md)，调用常见异常，[详细请查看](https://git.polyv.net/help-center/document-center/-/blob/master/vod/java/exceptionDoc/README.md)

#### 单元测试

```java
	@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;
        }
    }
```

#### 单元测试说明

1、请求正确，返回String对象，B端依据此对象处理业务逻辑；

2、请求参数校验不合格，抛出PloyvSdkException，错误信息见PloyvSdkException.getMessage()，如 \[ 输入参数 \[xxx.chat.VodxxxRequest]对象校验失败，失败字段 \[pic不能为空 / msg不能为空] ]

3、服务器处理异常，抛出PloyvSdkException，错误信息见PloyvSdkException.getMessage()，如 \[ 保利威请求返回数据错误，请求流水号：66e7ad29fd04425a84c2b2b562d2025b，错误原因： invalid signature. ]

#### 请求入参描述

| 参数名       | 必选   | 类型     | 说明                                                                                                                             |
| --------- | ---- | ------ | ------------------------------------------------------------------------------------------------------------------------------ |
| videoId   | true | String | 视频ID【对应api文档的**vid**字段】                                                                                                        |
| title     | true | String | 裁剪后的视频名称                                                                                                                       |
| timeFrame | true | String | json格式的特定时间段，格式为\[{"start":1,"end":6},{"start":10,"end":16}]. 时间段数量不能超过5个，每个片段开始时间不能大于结束时间，开始与结束时间间隔需要超过或者等于5秒，结束时间不能超过视频的播放时长 |

#### 返回对象描述

接口请求成功会返回裁剪后新视频的videoId\ <br>

***

\ <br>

### 2、合并视频

#### 描述

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

#### 调用约束

1、接口调用有频率限制，[详细请查看](https://git.polyv.net/help-center/document-center/-/blob/master/vod/java/limit/README.md)，调用常见异常，[详细请查看](https://git.polyv.net/help-center/document-center/-/blob/master/vod/java/exceptionDoc/README.md)

#### 单元测试

```java
	@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;
        }
    }
}
```

#### 单元测试说明

1、请求正确，返回VodConcatVideoResponse对象，B端依据此对象处理业务逻辑；

2、请求参数校验不合格，抛出PloyvSdkException，错误信息见PloyvSdkException.getMessage()，如 \[ 输入参数 \[xxx.chat.VodxxxRequest]对象校验失败，失败字段 \[pic不能为空 / msg不能为空] ]

3、服务器处理异常，抛出PloyvSdkException，错误信息见PloyvSdkException.getMessage()，如 \[ 保利威请求返回数据错误，请求流水号：66e7ad29fd04425a84c2b2b562d2025b，错误原因： invalid signature. ]

#### 请求入参描述

| 参数名        | 必选    | 类型      | 说明                                               |
| ---------- | ----- | ------- | ------------------------------------------------ |
| videoIds   | true  | String  | 视频id，用逗号隔开，只支持合并2个或者3个【对应api文档的**vids**字段】       |
| title      | false | String  | 视频标题，默认为“合并-”+第一个视频的标题。标题长度超过128会被截取             |
| categoryId | false | String  | 分类id，默认为默认分类【对应api文档的**cataId**字段】               |
| screenCap  | false | Integer | 是否开启录屏优化，1表示开启，0表示关闭，默认为关闭【对应api文档的**luping**字段】 |

#### 返回对象描述

| 参数名           | 类型     | 说明                                     |
| ------------- | ------ | -------------------------------------- |
| concatVideoId | String | 合并后的视频videoId【对应api文档的**concatVid**字段】 |

<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://polyv.gitbook.io/document/docs/vod/java/videocutandmerge.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
