从hls.js的buffer中保存音频数据时, 出现失真的问题

发布于 2022-09-13 00:02:37 字数 1637 浏览 29 评论 0

我尝试通过修改hls.js的源代码, 从hls的buffer中提取原始的音频和视频数据. 我将hls原始的appendExecutor函数:

private appendExecutor(data: Uint8Array, type: SourceBufferName) {
  const { operationQueue, sourceBuffer } = this;
  const sb = sourceBuffer[type];
  if (!sb) {
    logger.warn(
      `[buffer-controller]: Attempting to append to the ${type} SourceBuffer, but it does not exist`
    );
    operationQueue.shiftAndExecuteNext(type);
    return;
  }

  sb.ended = false;
  console.assert(!sb.updating, `${type} sourceBuffer must not be updating`);
  console.log(data);
  sb.appendBuffer(data);
}

修改成:

private appendExecutor(data: Uint8Array, type: SourceBufferName) {
  const { operationQueue, sourceBuffer } = this;
  const sb = sourceBuffer[type];
  if (!sb) {
    logger.warn(
      `[buffer-controller]: Attempting to append to the ${type} SourceBuffer, but it does not exist`
    );
    operationQueue.shiftAndExecuteNext(type);
    return;
  }

  sb.ended = false;
  console.assert(!sb.updating, `${type} sourceBuffer must not be updating`);
  console.log(data);

  const blob = new Blob([data]);
  var a = document.createElement("a");
  a.href = URL.createObjectURL(blob);
  a.download = "1";
  a.click();
  URL.revokeObjectURL(a.href);
  
  sb.appendBuffer(data);
}

来进行数据流的提取, 但是保存后的文件(尤其是音频文件)出现了一定程度的失真, 其中音频文件的问题较为明显, 存在较大噪音以及音调变得很低的问题. 使用ffmpeg查看音频信息时会出现[mov,mp4,m4a,3gp,3g2,mj2 @ 0x557ff36a1fc0] Duplicated SDTP atom的问题. 请问这种问题有办法解决么?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文