GameRecorderManager.clipVideo
收藏我的收藏
基础库 1.6.1 开始支持本方法,这是一个异步方法。
剪辑精彩的视频片段。
前提条件 | 无 |
业务背景 | 无 |
使用限制 | 无 |
注意事项 | 无 |
相关教程 | 无 |
语法
GameRecorderManager.clipVideo(options)
参数说明
options 为 object 类型,属性如下:
属性名 | 类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
---|---|---|---|---|---|
path | string | 是 | path 的值为停止录屏拿到的视频地址 | 1.6.1 | |
timeRange | Array<number> | 否 | 裁剪的范围,用法含义与 recordClip 中的 timeRange 完全相同,只是记录时相对的当前时刻规定为录屏结束时刻 | 1.6.1 | |
clipRange | Array<number> | 否 | 指定要裁剪的范围,数组中每一项为调用 recordClip 得到返回值 | 1.6.1 | |
success | function | 否 | 接口调用成功的回调函数 | 1.6.1 | |
fail | function | 否 | 接口调用失败的回调函数 | 1.6.1 | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | 1.6.1 |
clipRange 参数说明
- 若不传 clipRange 字段,会按照默认的 recordClip 的调用顺序裁剪视频并合并,对于 recordClip 调 用时 timeRange 字段可能产生交集的部分会自动合并,确保生成的视频内容是无重复且顺序符合记录顺序。
- 若指定了 clipRange 字段,平台将只会按 clipRange 数据的顺序裁剪合并视频,并对于重复的部分不做处理,开发者可利用该功能实现自定义裁剪片段、自定义拼接顺序(若同时指定了 timeRange,该片段将依旧作为最后一段拼接),对于最终视频可能出现的重复内容,需要开发者自己保证。
- 若指定了 clipRange 字段,需要保证 clipRange 参数的长度需要大于 1。再同时指定了 timeRange 的情况下,timeRange 参数会在内部生成为 recordClip 得到返回值 ,并加入到 clipRange 数组中,即 timeRange 会在内部转换为 clipRange 数组的一项追加到数组末尾。
回调成功
object 类型,属性如下:
属性名 | 类型 | 说明 | 最低支持版本 |
---|---|---|---|
videoPath | string | 剪辑的视频地址 | 1.6.1 |
错误码
errNo | errMsg | 说明 | 最低支持版本 |
---|---|---|---|
20000 | not record yet | 1.6.1 | |
20000 | single record video can only be cliped once | 1.6.1 | |
20000 | param:trimParam illegal | 1.6.1 | |
20000 | param:range illegal | 1.6.1 | |
20000 | param:videoPath illegal | 1.6.1 | |
20000 | param:operationType illegal | 1.6.1 | |
10402 | App can not call recorder | 小游戏框架内部错误,有需要请创建工单咨询 | 1.6.1 |
21000 | Recording is not over | 1.6.1 | |
20000 | video url is nil | 小游戏框架内部错误,有需要请创建工单咨询 | 1.6.1 |
代码示例
【代码示例1】简单裁剪,生成最后 10 秒的视频:
const recorder = tt.getGameRecorderManager(); recorder.start({ duration: 60 }); recorder.clipVideo({ path: res.videoPath, timeRange: [10, 0], success(res) { console.log(res.videoPath); // 生成最后10秒的视频 }, fail(e) { console.error(e); }, });
【代码示例2】结合 recordClip,顺序拼接剪辑:
const recorder = tt.getGameRecorderManager(); recorder.start({ duration: 60 }); // start 之后 5 秒调用 recorder.recordClip({ timeRange: [5, 0], }); recorder.onStop((res) => { recorder.clipVideo({ path: res.videoPath, timeRange: [10, 0], success(res) { // 由开始5秒 +最后10秒 拼接合成的视频 console.log(res.videoPath); }, fail(e) { console.error(e); }, }); });
【代码示例3】自定义拼接顺序:
const recorder = tt.getGameRecorderManager(); const clipIndexList = []; // 剪辑索引列表 // 监听录屏结束事件 recorder.onStop((res) => { // 对录制完成的视频进行剪辑 recorder.clipVideo({ path: res.videoPath, clipRange: clipIndexList.reverse(), // 倒序拼接 success(res) { console.log(res.videoPath); // 生成 最后10秒 + 开始5秒 的视频 }, fail(e) { console.error(e); }, }); }); recorder.start({ duration: 30, }); // 录屏开始 5秒后执行,记录 5s 之前到当前时刻的剪辑时间 recorder.recordClip({ timeRange: [5, 0], success(res) { clipIndexList.push(res.index); }, }); // stop 之前调用表示裁剪录屏中的最后10s recorder.recordClip({ timeRange: [10, 0], success(res) { clipIndexList.push(res.index); recorder.stop(); }, });