From 5835344e30557087e409845d9e967347402533b8 Mon Sep 17 00:00:00 2001 From: giles Date: Wed, 4 Feb 2026 20:50:14 +0000 Subject: [PATCH] Add audio support to MultiResolutionHLSOutput --- streaming/multi_res_output.py | 14 ++++++++++++++ streaming/stream_sexp_generic.py | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/streaming/multi_res_output.py b/streaming/multi_res_output.py index 85988da..142e8bf 100644 --- a/streaming/multi_res_output.py +++ b/streaming/multi_res_output.py @@ -58,6 +58,7 @@ class MultiResolutionHLSOutput: segment_duration: float = 4.0, ipfs_gateway: str = "https://ipfs.io/ipfs", on_playlist_update: callable = None, + audio_source: str = None, ): self.output_dir = Path(output_dir) self.output_dir.mkdir(parents=True, exist_ok=True) @@ -66,6 +67,7 @@ class MultiResolutionHLSOutput: self.segment_duration = segment_duration self.ipfs_gateway = ipfs_gateway.rstrip("/") self._on_playlist_update = on_playlist_update + self.audio_source = audio_source self._is_open = True self._frame_count = 0 @@ -187,6 +189,10 @@ class MultiResolutionHLSOutput: "-i", "-", ] + # Add audio input if provided + if self.audio_source: + cmd.extend(["-i", str(self.audio_source)]) + # Scale if not original resolution if quality.width != self.source_width or quality.height != self.source_height: cmd.extend([ @@ -206,6 +212,14 @@ class MultiResolutionHLSOutput: "-sc_threshold", "0", # Disable scene change detection for consistent segments ]) + # Add audio encoding if audio source provided + if self.audio_source: + cmd.extend([ + "-c:a", "aac", + "-b:a", "128k", + "-shortest", # Stop when shortest stream ends + ]) + # HLS output cmd.extend([ "-f", "hls", diff --git a/streaming/stream_sexp_generic.py b/streaming/stream_sexp_generic.py index 4b0fe0e..8cf0ae9 100644 --- a/streaming/stream_sexp_generic.py +++ b/streaming/stream_sexp_generic.py @@ -966,7 +966,8 @@ class StreamInterpreter: source_size=(w, h), fps=fps, ipfs_gateway=ipfs_gateway, - on_playlist_update=self.on_playlist_update + on_playlist_update=self.on_playlist_update, + audio_source=audio, ) # Fallback to GPU single-resolution if multi-res not available elif GPUHLSOutput is not None and check_gpu_encode_available():