Using MP4box.js and onSegment callback is not called no websocket

353 views Asked by At

So I'm trying to use MP4Box.js. On its readme page it states: it has a demo: "A player that performs on-the-fly fragmentation".

However the onSegment callbacks which should feed MSE are not called at all:

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 });

    
}

Now putting this into an HTML file would result this in the JavaScript console:

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

But nothing happens afterwards. Why is the onSegment not called here?

0

There are 0 answers