shaka-project / shaka-streamer

A simple config-file based approach to preparing streaming media, based on FFmpeg and Shaka Packager.
https://shaka-project.github.io/shaka-streamer/
Apache License 2.0
199 stars 62 forks source link

Multi period for HLS #83

Closed mariocynicys closed 3 years ago

mariocynicys commented 3 years ago

This PR adds the support for multi-period concatenation for HLS, using #EXT-X-DISCONTINUITY between periods.

The new file m3u8_concater.py has the classes used to parse the m3u8 files and reduce multiple files of them into one concatenated file.

HLSConcater is just an API that is exposed to the PeriodConcatNode for abstraction.

MasterPlaylist is a class representing a master hls playlist, the parsing part happens in the __init__ method, creates a MediaPlaylist object for each media(video,text,audio) playlist found in this master playlist, the stream attributes for each playlist is passed to the MediaPlaylist object and stored in it.

MediaPlaylist is a class representing an hls media playlist, the playlist gets parsed in the __init__ method, the biggest part of the playlist is saved mostly unchanged in the self.content variable, but the media segment paths get updated to point to the new relative path of the media segment.

The playlist concatenation methods are the static methods in the MediaPlaylist class (concat_sub, concat_aud, concat_vid, concat_aud_only(to handle the audio-only stream cases)).

No period concatenation is performed if an inconsistent media in periods is detected(e.g. one period has video and one does not).

Things that need addressing: 1- When Shaka Player gets an HLS master playlist containing unsupported and supported audio codecs, it breaks, this happens with:

2- When Shaka Packager receives an audio-only period to package, it normally creates a stream variant(stream-inf) for each media(audio) playlist generated, but when this audio-only input has one subtitles playlist along with the audio, Shaka-Packager doesn't create the stream-inf playlists, for the current implementation, this will create an error in the HLS concater, we can escape this period as a solution if it has no stream-infs, periods with no stream-inf we can't know its bitrates and codecs and isn't playable in Shaka Player.

joeyparrish commented 3 years ago

Just back from vacation. Will try to take another pass at review today if at all possible.