video-dev / hls.js

HLS.js is a JavaScript library that plays HLS in browsers with support for MSE.
https://hlsjs.video-dev.org/demo
Other
14.93k stars 2.59k forks source link

Manage buffering with HLS #2088

Closed AyoubBani closed 5 years ago

AyoubBani commented 5 years ago

What do you want to do with Hls.js? I'm setting up a web page that can play from m3u8 playlist (HLS). I want to handle video chunks like in this example with MSE https://github.com/bitmovin/mse-demo/blob/master/index.html. Is there any possibility to do it with hls.js. and if it's possible to clear buffer after playing 5 segments for example.

itsjamie commented 5 years ago

Hello!

The hls.js library does what you linked in the Bitmovin example is showing a very simplified DASH player, for the Apple HLS format. It utilizes the MSE API to append your content into the source buffer API.

For the basic example, the https://github.com/video-dev/hls.js#getting-started section of the README gives a good overview of passing an m3u8 resource to the hls.js API.

When you say you want to handle video chunks, is that because you need access to the AV segments as they are added to the SourceBuffer that hls.js manages for you? If not, you should be able to follow the getting started bit to getting playback going.

For controlling what is in the buffer, there are options in the API such as: https://github.com/video-dev/hls.js/blob/master/docs/API.md#maxmaxbufferlength that you can pass to the configuration for an hls.js player that will limit how much content will stay in the SourceBuffer before buffer eviction starts to be done targeting VOD content. If you are doing live video playback, an option like https://github.com/video-dev/hls.js/blob/master/docs/API.md#livebackbufferlength could be more appropriate.

Hope this helps.

AyoubBani commented 5 years ago

Thank you so much for your answer. It's very helpful.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.