gpac / mp4box.js

JavaScript version of GPAC's MP4Box tool
https://gpac.github.io/mp4box.js/
BSD 3-Clause "New" or "Revised" License
1.98k stars 333 forks source link

MP4box.js and onSegment callback is not called, unclear documentation #214

Closed YordinsonPolar closed 3 years ago

YordinsonPolar commented 4 years ago

I dont undestarnd, unclear documentation `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, sampleNum) => { 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 });

} `

cconcolato commented 3 years ago

Can you be more specific as to what you want to be clarified?

cconcolato commented 3 years ago

I added an example of simple file segmenter. It completely ignores MSE (there is already documentation on the web for MSE). Maybe it will help.