mbebenita / Broadway

A JavaScript H.264 decoder.
Other
2.73k stars 426 forks source link

Decode : RangeError: offset is out of bounds #217

Open dezmou opened 4 years ago

dezmou commented 4 years ago

Hello :)

I wants to get all frames from the fox.mp4 as pixels array for each frames, I don't want to display it in any canvas.

When looking in the code of Decode.js I may have figured out that decode() accept Uint8Array as parameters so I've made this code :

(async () => {

    const decoder = new Decoder({
        // rgb: true
    })
    const arrayBuf = await (await fetch("/fox.mp4")).arrayBuffer()
    let uint8 = new Uint8Array(arrayBuf)
    decoder.decode(uint8)
    decoder.onPictureDecoded = (a, b, c, d) => {
        console.log(a, b, c, d);
    }

})()

But I've got an error :

Decoder.js:371 Uncaught (in promise) RangeError: offset is out of bounds
    at Uint8Array.set (<anonymous>)
    at Broadway.decode (Decoder.js:371)
    at index.js:8

Is that a bug from Broadway or my implementation is wrong ?

Thanks a lot !

soliton4 commented 4 years ago

you have to feed single nal units to the decoder. use the mp4 parser but dont instanciate a player, instead feed the nal units to the decode function of your decoder instance