Add audio support to MultiResolutionHLSOutput
This commit is contained in:
@@ -58,6 +58,7 @@ class MultiResolutionHLSOutput:
|
|||||||
segment_duration: float = 4.0,
|
segment_duration: float = 4.0,
|
||||||
ipfs_gateway: str = "https://ipfs.io/ipfs",
|
ipfs_gateway: str = "https://ipfs.io/ipfs",
|
||||||
on_playlist_update: callable = None,
|
on_playlist_update: callable = None,
|
||||||
|
audio_source: str = None,
|
||||||
):
|
):
|
||||||
self.output_dir = Path(output_dir)
|
self.output_dir = Path(output_dir)
|
||||||
self.output_dir.mkdir(parents=True, exist_ok=True)
|
self.output_dir.mkdir(parents=True, exist_ok=True)
|
||||||
@@ -66,6 +67,7 @@ class MultiResolutionHLSOutput:
|
|||||||
self.segment_duration = segment_duration
|
self.segment_duration = segment_duration
|
||||||
self.ipfs_gateway = ipfs_gateway.rstrip("/")
|
self.ipfs_gateway = ipfs_gateway.rstrip("/")
|
||||||
self._on_playlist_update = on_playlist_update
|
self._on_playlist_update = on_playlist_update
|
||||||
|
self.audio_source = audio_source
|
||||||
self._is_open = True
|
self._is_open = True
|
||||||
self._frame_count = 0
|
self._frame_count = 0
|
||||||
|
|
||||||
@@ -187,6 +189,10 @@ class MultiResolutionHLSOutput:
|
|||||||
"-i", "-",
|
"-i", "-",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Add audio input if provided
|
||||||
|
if self.audio_source:
|
||||||
|
cmd.extend(["-i", str(self.audio_source)])
|
||||||
|
|
||||||
# Scale if not original resolution
|
# Scale if not original resolution
|
||||||
if quality.width != self.source_width or quality.height != self.source_height:
|
if quality.width != self.source_width or quality.height != self.source_height:
|
||||||
cmd.extend([
|
cmd.extend([
|
||||||
@@ -206,6 +212,14 @@ class MultiResolutionHLSOutput:
|
|||||||
"-sc_threshold", "0", # Disable scene change detection for consistent segments
|
"-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
|
# HLS output
|
||||||
cmd.extend([
|
cmd.extend([
|
||||||
"-f", "hls",
|
"-f", "hls",
|
||||||
|
|||||||
@@ -966,7 +966,8 @@ class StreamInterpreter:
|
|||||||
source_size=(w, h),
|
source_size=(w, h),
|
||||||
fps=fps,
|
fps=fps,
|
||||||
ipfs_gateway=ipfs_gateway,
|
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
|
# Fallback to GPU single-resolution if multi-res not available
|
||||||
elif GPUHLSOutput is not None and check_gpu_encode_available():
|
elif GPUHLSOutput is not None and check_gpu_encode_available():
|
||||||
|
|||||||
Reference in New Issue
Block a user