clipVideo

2020-02-14 15:32 更新

GameRecorderManager.clipVideo(Object object)

剪辑精彩的视频片段。


输入

属性类型默认值是否必填说明支持版本
pathstringpath 的值为停止录屏拿到的视频地址
timeRangeArray裁剪的范围,用法含义与recordClip 中的timeRange,完全相同,只是记录时相对的当前时刻规定为录屏结束时刻1.13.9
clipRangeArray指定要裁剪的范围,数组中每一项为调用 recordClip 得到返回值1.20.0
successfunction剪辑成功的回调函数
failfunction剪辑失败的回调函数

clipRange 详细说明

  • 若不传clipRange字段,会按照默认的recordClip的调用顺讯裁剪视频并合并,对于 recordClip 调用时 timeRange字段可能产生交集的部分会自动合并,确保生成的视频内容是无重复且顺序符合记录顺序。
  • 若指定了clipRange字段,平台将只会按 clipRange 数据的顺序裁剪合并视频,并对于重复的部分不做处理,开发者可利用该功能实现自定义裁剪片段、自定义拼接顺序(若同时指定了 timeRange,该片段将依旧作为最后一段拼接),对于最终视频可能出现的重复内容,需要开发者自己保证。


输出

success返回对象参数的扩展属性:

名称数据类型描述
videoPathstring剪辑的视频地址


示例

简单裁剪,生成最后 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();
  }
});
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号