mbebenita / Broadway

A JavaScript H.264 decoder.
Other
2.72k stars 424 forks source link

can Player.decode one H264 NAL by feeding data multi times? #105

Closed dista closed 6 years ago

dista commented 8 years ago
p = new Player({
  useWorker: <bool>,
  workerFile: <defaults to "Decoder.js"> // give path to Decoder.js
  webgl: true | false | "auto" // defaults to "auto"
});
// canvas property represents the canvas node
// put it somewhere in the dom
p.canvas;
p.webgl; // contains the used rendering mode. if you pass auto to webgl you can see what auto detection resulted in
p.decode(<binary>);

for example: if I have a H264 NAL whose length is 20000, does the following will work?

p.decode(the first 5000 bytes)
p.decode(the next 10000 bytes)
p.decode(the final 5000 bytes)

In my test, it seems do not work, I have a backend which read one raw h264 file(use ffmpeg generated ffmpeg -i "http://10.33.0.68/channels/preview/1/flv:500k" -an -vcodec libx264 -pass 1 -coder 0 -bf 0 -flags -loop -wpredp 0 -vb 500k /tmp/p.h264), I read it every 50 ms and 10240 bytes for each, then send it to browser using websockets.

But the result is it can decode some frame, but stuck after that.

thanks.

OllieJones commented 6 years ago

I have never managed to get this to work. Broadway's decoder wants complete NALUs. mp4 files have one or more complete NALUs in each mdat box. Each NALU is preceded by a four-byte length integer. It's necessary to get rid of those length integers before handing the NALUs to Broadway. webm boxing (generated by browser media capture) is a little more friendly, because the NALUs are in byte stream form with escape data.

soliton4 commented 6 years ago

yeah only complete nals make sense for the c-based decoder. just collect the data in a buffer if you dont send complete nals