---
name: "clipVideo"
mode: "kit"
versionRequirements:
  - { name: "BaseKit", version: "3.14.2" }
  - { name: "@ray-js/ray", version: "1.5.33" }
platform:
  - "iOS"
  - "Android"
async: true
title: "clipVideo"
---

## clipVideo

> [VERSION] BaseKit >= 3.14.2 | @ray-js/ray >= 1.5.33

> [PLATFORM] iOS, Android

> ⚡ **Supports Promise** — Returns a Promise when success / fail / complete callbacks are omitted.

### Description

Trim video

### Parameters

| Property | Type | Required | Default | Since | Description |
| --- | --- | --- | --- | --- | --- |
| `filePath` | `string` | Yes | - | `3.14.2` | Video file path; can be a temporary file path or a permanent file path (local path) |
| `startTime` | `number` | Yes | - | `3.14.2` | Start time, in milliseconds |
| `endTime` | `number` | Yes | - | `3.14.2` | End time, in milliseconds |
| `level` | `number` | Yes | - | `3.14.2` | Target compressed resolution 1 - 480x854  Bitrate: 1572x1000 2 - 540x960  Bitrate: 2128x1000 3 - 720x1280  Bitrate: 3145x1000 4 - 1080x1920  Bitrate: 3500x1000 |
| `complete` | `() => void` | No | - | - | Completion callback (executed on both success and failure) |
| `success` | `(params: Object) => void` ↓see below | No | - | - | Callback on successful API call |
| `fail` | `(params: Object) => void` ↓see below | No | - | - | Failure callback |

#### success callback parameters

| Property | Type | Since | Description |
| --- | --- | --- | --- |
| `videoClipPath` | `string` | `3.14.2` | Trimmed video path |

#### fail callback parameters

| Property | Type | Description |
| --- | --- | --- |
| `errorMsg` | `string` | Error message |
| `errorCode` | `string \| number` | Error code |
| `innerError` | `Object` | Error extension |

##### fail(params).innerError properties

| Property | Type | Description |
| --- | --- | --- |
| `errorCode` | `string \| number` | Error extension code |
| `errorMsg` | `string` | Error extension message |


### Examples

#### Demo

```tsx
import { downloadFile, clipVideo } from '@ray-js/ray'

// Trim video: download the video first, then call with the protocol path tempFilePath; level 1–4 corresponds to resolution presets (1=480×854)
downloadFile({
  url: "https://airtake-public-data-1254153901.cos.ap-shanghai.myqcloud.com/ttttestfile/test_video.mp4",
  success: ({ tempFilePath }) => {
    clipVideo({
      filePath: tempFilePath,
      startTime: 0,
      endTime: 3000,
      level: 1,
      success: data => console.log("Trimmed video path:", data.videoClipPath),
      fail: error => console.error("Trim failed:", JSON.stringify(error)),
    });
  },
  fail: error => console.error("Download failed:", JSON.stringify(error)),
});
```
