1

所以我正在尝试使用 MP4Box.js。它在其自述页面上声明:它有一个演示:“一个执行即时碎片的播放器”。

然而,应该提供 MSE 的 onSegment 回调根本不会被调用:

const getVideo = async () => {
    const data = await fetch(url, { headers: { range: 'bytes=0-567139' } });
    let buff = await data.arrayBuffer();
    console.log(buff)

mp4box = MP4Box.createFile();

mp4box.onError = function(e) {
  console.log("mp4box failed to parse data.");
};

mp4box.onMoovStart = function () {
  console.log("Starting to receive File Information");
};

mp4box.onReady = function(info) {
  console.log(info.mime);
  mp4box.onSegment = (id, user, buffer ) =>  {
  setBuffer(buffer)
 }

  mp4box.setSegmentOptions(info.tracks[0].id, null, { nbSamples: 1000 });
  var initSegs = mp4box.initializeSegmentation();
  console.log(initSegs)
  mp4box.start();

};

var nextBufferStart = 0;
buff.fileStart = nextBufferStart;
nextBufferStart = mp4box.appendBuffer(buff);
mp4box.flush();

const mediaSource = new MediaSource();
const mimeCodec = 'video/mp4; codecs="avc1.640029,mp4a.40.2"';
video.src = URL.createObjectURL(mediaSource);


function sourceopen() {
    console.log('open')
    const source = mediaSource.addSourceBuffer(mimeCodec);
    const setBuffer = (buff) => {
        source.appendBuffer(buff)
    };
}
mediaSource.addEventListener('sourceopen', sourceopen, { once: true });

    
}

现在把它放到一个 HTML 文件中会在 JavaScript 控制台中产生这个结果:

Starting to receive File Information
video/mp4; codecs="avc1.4d4028"; profiles="isom,iso2,avc1,iso6,mp41"

但之后什么也没有发生。为什么这里没有调用 onSegment?

4

0 回答 0