Crop Video
Updated: 2025-01-14 16:04:43
API Description
1、通过视频id裁剪视频
2、接口URL中的{userid}为点播账号userid,具体参考菜单【使用须知】->【获取密钥】
3、接口支持https协议
API URL
http://api.polyv.net/v2/video/{userid}/clip
Request Method
POST
API Constraints
- The API supports both HTTP and HTTPS. HTTPS is recommended for security. API calls have frequency limits. See details
Request Parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
| ptime | true | Long | Current time in milliseconds, valid for 3 minutes |
| sign | true | String | Signature, a 40-character uppercase SHA1 value. The secretkey used to generate the signature is critical for communication security. It must never be used directly on the client side. All API calls must be relayed through your own server to the POLYV server. See signature generation rules |
| vid | true | String | Video ID |
| title | true | String | Name of the cropped video |
| timeFrame | true | String | Specific time segments See timeFrame field description. Format is a JSON array object. Example: [{"start":1,"end":6},{"start":10,"end":16}]. Maximum 5 segments. Each segment's start time must be less than or equal to its end time. The interval between start and end must be >= 5 seconds. The end time must not exceed the video duration. |
timeFrame Parameter Description
| Field | Type | Description |
|---|---|---|
| start | Integer | Start time, in seconds |
| end | Integer | End time, in seconds |
Example
http://api.polyv.net/v2/video/1b448be323/clip
Form parameters:
vid=1b448be323631e6e80e12e0790609f68_1&sign=004B30AE72BF5E96624A6FF81370FCCE64F379B1&title=美食&ptime=1617765720251&timeFrame=[{"start":1,"end":6},{"start":10,"end":16}]
Response Parameters
| Parameter | Type | Description |
|---|---|---|
| code | Integer | Response status code. 200 indicates success, non-200 indicates failure. See global error description |
| status | String | Response status text |
| message | String | Response description. Provides error details when code is 400 or 500. |
| data | String | Returns the new video ID on success, or an empty string on failure. |
Error Code List
| Error Code | message | Description |
|---|---|---|
| 400 | sign can not be empty. | Signature is empty. |
| 400 | ptime is too old. | Timestamp has expired. |
| 400 | ptime is illegal. | Timestamp format is invalid or exceeds 3 minutes from current time. |
| 400 | Could not find user by userid. | User ID does not exist. |
| 400 | the sign is not right. | Signature is incorrect. |
| 410 | vid is blank. | Video ID is empty. |
| 411 | timeFrame is blank. | Time frame is empty. |
| 412 | vid doesn't exist. | Video ID does not exist. |
| 413 | illegal timeFrames. | JSON format of timeFrame is invalid. |
| 414 | timeFrames's size exceed 5. | Number of timeFrame segments exceeds 5. |
| 415 | illegal timeFrames. | End time is less than start time in timeFrame. |
| 416 | illegal timeFrames. | TimeFrame segment length is less than 5 seconds. |
| 417 | illegal timeFrames. | End time in timeFrame exceeds video duration. |
| 418/419 | inital clip task filed. | Task initialization failed. Check backend logs for details. |
| 500 | save clip task failed. | Backend program threw an exception. |
Java Request Example
For quick integration, download the related dependency source code. Click to download source code. After downloading, add it to your project. The test cases include HttpUtil.java and VodSignUtil.java in the downloaded file.
It is strongly recommended to use the VOD Java SDK for API integration. The VOD Java SDK provides unified encapsulation and optimization for API call logic, exception handling, data signing, and HTTP request thread pools.
private static final Logger log = LoggerFactory.getLogger(VodClipTest.class);
/**
* 裁剪视频
* @throws Exception
* @throws NoSuchAlgorithmException
*/
@Test
public void testUploadWatermark() throws Exception, NoSuchAlgorithmException {
//公共参数,填写自己的实际参数
String secretKey = super.secretKey;
String userId = super.userId;
String ptime = String.valueOf(System.currentTimeMillis());
//业务参数
String url = "http://api.polyv.net/v2/video/"+userId+"/clip";
String vid = "1b448be323631e6e80e12e0790609f68_1";
String title="美食";
String timeFrame = "[{\"start\":1,\"end\":6},{\"start\":10,\"end\":16}]";
Map<String, String> requestMap = new HashMap<>();
requestMap.put("ptime", ptime);
requestMap.put("vid", vid);
requestMap.put("title", title);
requestMap.put("timeFrame", timeFrame);
requestMap.put("sign", VodSignUtil.getSign(requestMap, secretKey));
String response = HttpUtil.postFormBody(url,requestMap);
log.debug("测试裁剪视频,{}", response);
//do somethings
}
Response Example
For global system error descriptions, see Global Error Description
Success Example
{
"code":200,
"status":"success",
"message":"success",
"data":"1b448be323615635294a548b3c8a9953"
}
Error Example
{
code: 400,
status: "error",
message: "ptime is too old.",
data: ""
}
