gpac / mp4box.js

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

`onReady` method is not called while creating segment from video frames #326

Closed UIcoder511 closed 1 year ago

UIcoder511 commented 1 year ago

The app I am building has a requirement to create a segment with 90 frames ( 30fps@3 seconds). With the below code, I am trying to create segments from encoded frames with WebCodec. However, the onReady method is not called.

this.encoder = encoder = new VideoEncoder({
          output: (chunk, cfg) => {
            console.log(chunk);
             const chunkData = new Uint8Array(chunk.byteLength);
            chunk.copyTo(chunkData);
            const buffer = chunkData.buffer;
            buffer.fileStart = that.filePos; //start from 0
            that.filePos += chunk.byteLength;
            that.mp4Box.appendBuffer(chunkData.buffer);
            ...
            chunk structure:
            EncodedVideoChunk 
            {deltaframeIndex : 32 keyframeIndex : 1 seqNo : 33 temporalLayerId : 0 byteLength : 22360 duration : 0 timestamp : 1135936 type : "delta"}
cconcolato commented 1 year ago

The appendBuffer method takes bytes formatted according to the ISO Base Media File Format. VideoEncoder's output is https://developer.mozilla.org/en-US/docs/Web/API/EncodedVideoChunk. This is not the same syntax. You should have a look at https://github.com/gpac/mp4box.js/issues/243 and other similar resources.