Broadway icon indicating copy to clipboard operation
Broadway copied to clipboard

Framerate and resolution

Open pquarme opened this issue 9 years ago • 16 comments

How do i cap the framerate and change the resolution? I'm currently using css to change the canvas width and height(which works).

pquarme avatar Jun 02 '15 16:06 pquarme

The code is probably using requestAnimationFrame (rAF) to play back video frames as quickly as possible. You should be able to use setInterval or rAF with manual frame rate throttling.

mbebenita avatar Jun 02 '15 17:06 mbebenita

Thank you for quick response. To be honest, i think i'm using the wrong approach. I'm following the example in "broadway/player/" folder. I've included all the js files in my project as well. What is a better approach, I've never worked with canvas before.

pquarme avatar Jun 02 '15 17:06 pquarme

Player will give you the ability to decode h264 nal units and have a function called when ever a frame is being decoded.

have a look at https://github.com/mbebenita/Broadway/blob/master/Player/Player.js#L103

you see that you can pass render to false and use your own implementation of rendering to canvas. you can simply copy paste the code in player and modify it to your needs.

i recommend buffering decoded frames and for long video streams maybe pause decoding when a certain amount of decoded frames exist.

the decoded frames you can then display at the frame rate of your choice

soliton4 avatar Jun 02 '15 17:06 soliton4

Thank you, I'll spend sometime using your approach and see how it works out.

pquarme avatar Jun 02 '15 17:06 pquarme

var p = new Player({
          useWorker: true,
          workerFile: "js/libs/broadway/Decoder.js", // give path to Decoder.js
          webgl: "auto" // defaults to "auto"
        });

p.decode();

p.canvas;

What do i pass into p.decode() ? Also how do I attach p.canvas to the dom and when does onPictureDecoded() come into play?

pquarme avatar Jun 02 '15 18:06 pquarme

Any idea on how to optimize framerate on mobile devices?

pquarme avatar Jun 09 '15 19:06 pquarme

it completely depends on the asm.js implementation of your browser. if you try running the demo on internet explorer for example you can actually crush it ;)

soliton4 avatar Jun 09 '15 21:06 soliton4

Haha thats good to know. Is there any chance this could be production viable?

pquarme avatar Jun 09 '15 21:06 pquarme

For what it's worth, I've tested this on several versions of Android and iOS with great success. Now, I just need to get audio working...

krillr avatar Jun 11 '15 14:06 krillr

That's great. How did you set it up? I was also thinking about how to integrate audio but wanted to at least get video working first.

pquarme avatar Jun 11 '15 15:06 pquarme

I modified the Broadway object to convert all

krillr avatar Jun 11 '15 15:06 krillr

Does the resolution of the video impact performance and what resolution did you use for your tests?

pquarme avatar Jun 11 '15 15:06 pquarme

It does, but not /hugely/. I'm using 300x250 videos, so nothing big. I'm seeing 60-70fps max on most hardware I've tested with.

krillr avatar Jun 11 '15 15:06 krillr

Nice, that's really good. Thank you.

pquarme avatar Jun 11 '15 15:06 pquarme

@krillr Have you made any progress on implementing audio?

pquarme avatar Jun 12 '15 20:06 pquarme

Only use the decoder function, then render yourself on canvas at the speed you want, and add buffer to play with the same timestamp

zhubinsheng avatar Oct 14 '20 07:10 zhubinsheng