GameRecorderManager.clipVideo
基础库版本 1.6.1 开始支持。
剪辑精彩的视频片段。
语法
GameRecorderManager.clipVideo(options)
参数说明
options
为 object 类型,属性如下:
属性名 | 类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
---|---|---|---|---|---|
path | string | 是 | path 的值为停止录屏拿到的视频地址 | 1.6.1 | |
timeRange | Array | 否 | 裁剪的范围,用法含义与recordClip 中的timeRange ,完全相同,只是记录时相对的当前时刻规定为录屏结束时刻 | 1.13.9 | |
clipRange | Array | 否 | 指定要裁剪的范围,数组中每一项为调用 recordClip 得到返回值 | 1.20.0 | |
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 |
扫码体验
请使用字节宿主APP扫码
代码示例
简单裁剪,生成最后 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);
},
});
结合 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);
},
});
});
自定义拼接顺序:
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();
},
});
点击纠错
该文档是否对你的开发有所帮助?
有帮助
没帮助
该文档是否对你的开发有所帮助?
有帮助
没帮助