From 071396b4f27c85716675e3653e435635c43c2c9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Mon, 11 Nov 2024 19:06:33 +0100 Subject: [PATCH] feat: Add generate_iframe_playlist option (#205) --- streamer/output_stream.py | 8 ++++++++ streamer/packager_node.py | 5 ++++- streamer/pipeline_configuration.py | 3 +++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/streamer/output_stream.py b/streamer/output_stream.py index ac9de99..fa5541e 100644 --- a/streamer/output_stream.py +++ b/streamer/output_stream.py @@ -88,6 +88,14 @@ def get_single_seg_file(self) -> Pipe: path_templ = SINGLE_SEGMENT[self.type].format(**self.features) return Pipe.create_file_pipe(path_templ, mode='w') + def get_identification(self) -> str: + SINGLE_SEGMENT = { + MediaType.AUDIO: '{language}_{channels}c_{bitrate}_{codec}_{format}', + MediaType.VIDEO: '{resolution_name}_{bitrate}_{codec}_{format}', + MediaType.TEXT: '{language}_{format}', + } + return SINGLE_SEGMENT[self.type].format(**self.features) + class AudioOutputStream(OutputStream): diff --git a/streamer/packager_node.py b/streamer/packager_node.py index db18b61..37ec102 100644 --- a/streamer/packager_node.py +++ b/streamer/packager_node.py @@ -21,7 +21,7 @@ from . import node_base from . import pipeline_configuration -from streamer.bitrate_configuration import AudioCodec +from streamer.bitrate_configuration import AudioCodec, VideoCodec from streamer.input_configuration import MediaType from streamer.output_stream import OutputStream from streamer.pipeline_configuration import EncryptionMode, PipelineConfig @@ -141,6 +141,9 @@ def _setup_stream(self, stream: OutputStream) -> str: if stream.type == MediaType.AUDIO: dict['hls_group_id'] = str(cast(AudioCodec, stream.codec).value) + if stream.type == MediaType.VIDEO and self._pipeline_config.generate_iframe_playlist: + dict['iframe_playlist_name'] = 'iframe_' + stream.get_identification() + '.m3u8' + if stream.input.drm_label: dict['drm_label'] = stream.input.drm_label diff --git a/streamer/pipeline_configuration.py b/streamer/pipeline_configuration.py index 8ce8aba..99f5a65 100644 --- a/streamer/pipeline_configuration.py +++ b/streamer/pipeline_configuration.py @@ -307,6 +307,9 @@ class PipelineConfig(configuration.Base): Must be true for live content. """ + generate_iframe_playlist = configuration.Field(bool, default=False).cast() + """If true, the iFrame playlist will be generated.""" + availability_window = configuration.Field(int, default=300).cast() """The number of seconds a segment remains available."""