clipVideo

2020-02-14 15:32 更新

GameRecorderManager.clipVideo(Object object)

剪輯精彩的視頻片段。


輸入

屬性類型默認值是否必填說明支持版本
pathstringpath 的值為停止錄屏拿到的視頻地址
timeRangeArray裁剪的范圍,用法含義與recordClip 中的timeRange,完全相同,只是記錄時相對的當(dāng)前時刻規(guī)定為錄屏結(jié)束時刻1.13.9
clipRangeArray指定要裁剪的范圍,數(shù)組中每一項為調(diào)用 recordClip 得到返回值1.20.0
successfunction剪輯成功的回調(diào)函數(shù)
failfunction剪輯失敗的回調(diào)函數(shù)

clipRange 詳細說明

  • 若不傳clipRange字段,會按照默認的recordClip的調(diào)用順訊裁剪視頻并合并,對于 recordClip 調(diào)用時 timeRange字段可能產(chǎn)生交集的部分會自動合并,確保生成的視頻內(nèi)容是無重復(fù)且順序符合記錄順序。
  • 若指定了clipRange字段,平臺將只會按 clipRange 數(shù)據(jù)的順序裁剪合并視頻,并對于重復(fù)的部分不做處理,開發(fā)者可利用該功能實現(xiàn)自定義裁剪片段、自定義拼接順序(若同時指定了 timeRange,該片段將依舊作為最后一段拼接),對于最終視頻可能出現(xiàn)的重復(fù)內(nèi)容,需要開發(fā)者自己保證。


輸出

success返回對象參數(shù)的擴展屬性:

名稱數(shù)據(jù)類型描述
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)
  }
})

結(jié)合 recordClip,順序拼接剪輯

const recorder = tt.getGameRecorderManager();
recorder.start({ duration: 60 });

// start 之后 5 秒調(diào)用
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 = []; // 剪輯索引列表

// 監(jiān)聽錄屏結(jié)束事件
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秒后執(zhí)行,記錄 5s 之前到當(dāng)前時刻的剪輯時間
recorder.recordClip({
  timeRange: [5, 0],
  success(res) {
    clipIndexList.push(res.index);
  }
});

// stop 之前調(diào)用表示裁剪錄屏中的最后10s
recorder.recordClip({
  timeRange: [10, 0],
  success(res) {
    clipIndexList.push(res.index);
    recorder.stop();
  }
});
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號