clipVideo

Requires:
BaseKit≥3.14.2@ray-js/ray≥1.5.33
Platforms:
iOSAndroid
import { clipVideo } from '@ray-js/ray';

// Promise usage
try {
  const res = await clipVideo({ ...params });
  console.log(res);
} catch (err) {
  console.log(err.errorMsg);
}

Method signature
clipVideo(params: )
Minimum SDK versions
iOSThingSmartBaseKitBizBundle
≥ 6.0.3
Androidcom.thingclips.smart:thingsmart-bizbundle-basekit
≥ 6.0.0

Description

Trim video

Parameters

PropertyTypeRequiredDescriptionBaseKit SinceMinimum SDK versions
filePathstringYesVideo file path; can be a temporary file path or a permanent file path (local path)-—
startTimenumberYesStart time, in milliseconds-—
endTimenumberYesEnd time, in milliseconds-—
levelnumberYesTarget compressed resolution 1 - 480x854 Bitrate: 1572x1000 2 - 540x960 Bitrate: 2128x1000 3 - 720x1280 Bitrate: 3145x1000 4 - 1080x1920 Bitrate: 3500x1000-—
maxResolutionstringNoMaximum resolution, in a format such as "1920*1080", matching skill.resolution reported by the device. Interpreted as "long side*short side", regardless of video orientation. The output is scaled proportionally to fit within these dimensions without upscaling, up to 1920*1080. When provided, the output resolution no longer depends on level; otherwise, it is calculated based on level.v3.42.3—
maxBitratenumberNoMaximum bitrate, in bps. The output bitrate is the lower of the recommended bitrate for the output resolution and this value. If omitted, the recommended bitrate is used.v3.42.3—
maxFpsnumberNoMaximum frame rate. The output frame rate is the lowest of the source frame rate, this value, and 30. If omitted, it is fixed at 30.v3.42.3—
maxFileSizenumberNoMaximum output file size, in bytes. When provided, the video bitrate is allocated based on the trimmed duration, without exceeding maxBitrate or the recommended bitrate. The actual file size is checked after export. If the limit is exceeded, the video is exported once more at a lower bitrate. A failure is returned if the file still exceeds the limit or if the duration is too long to maintain a video bitrate of at least 300 kbps. If omitted, no file size limit is applied.v3.42.3—
complete() => voidNoCompletion callback (executed on both success and failure)-—
success(params: Object) => voidNoCallback on successful API call-—
fail(params: Object) => voidNoFailure callback-—
success callback parameters
PropertyTypeDescriptionBaseKit SinceMinimum SDK versions
videoClipPathstringTrimmed video path-—
widthnumberOutput video width, in pixelsv3.42.3—
heightnumberOutput video height, in pixelsv3.42.3—
frameRatenumberOutput video frame ratev3.42.3—
bitratenumberTarget output video bitrate, in bpsv3.42.3—
fileSizenumberActual output file size, in bytesv3.42.3—
fail callback parameters
PropertyTypeDescription
errorMsgstringError message
errorCodestring | numberError code
Error extension

Return Value

None

Examples

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)),
});