Fix lazy audio path resolution for GPU streaming
Some checks are pending
GPU Worker CI/CD / test (push) Waiting to run
GPU Worker CI/CD / deploy (push) Blocked by required conditions

Audio playback path was being resolved during parsing when database
may not be ready, causing fallback to non-existent path. Now resolves
lazily when stream starts, matching how audio analyzer works.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-04 11:32:04 +00:00
parent ef3638d3cf
commit ed617fcdd6
9 changed files with 159 additions and 57 deletions

View File

@@ -235,6 +235,7 @@ class GPUHLSOutput:
self.ipfs_gateway = ipfs_gateway.rstrip("/")
self._on_playlist_update = on_playlist_update
self._is_open = True
self.audio_source = audio_source
# GPU encoder
self._gpu_encoder = GPUEncoder(size[0], size[1], fps, crf)
@@ -266,14 +267,29 @@ class GPUHLSOutput:
print(f"[GPUHLSOutput] Initialized {size[0]}x{size[1]} @ {fps}fps, GPU encoding", file=sys.stderr)
def _setup_muxer(self):
"""Setup ffmpeg for muxing H.264 to MPEG-TS segments."""
"""Setup ffmpeg for muxing H.264 to MPEG-TS segments with optional audio."""
self.local_playlist_path = self.output_dir / "stream.m3u8"
cmd = [
"ffmpeg", "-y",
"-f", "h264", # Input is raw H.264
"-i", "-",
"-c:v", "copy", # Just copy, no re-encoding
]
# Add audio input if provided
if self.audio_source:
cmd.extend(["-i", str(self.audio_source)])
cmd.extend(["-map", "0:v", "-map", "1:a"])
cmd.extend([
"-c:v", "copy", # Just copy video, no re-encoding
])
# Add audio codec if we have audio
if self.audio_source:
cmd.extend(["-c:a", "aac", "-b:a", "128k", "-shortest"])
cmd.extend([
"-f", "hls",
"-hls_time", str(self.segment_duration),
"-hls_list_size", "0",
@@ -281,12 +297,14 @@ class GPUHLSOutput:
"-hls_segment_type", "mpegts",
"-hls_segment_filename", str(self.output_dir / "segment_%05d.ts"),
str(self.local_playlist_path),
]
])
print(f"[GPUHLSOutput] FFmpeg cmd: {' '.join(cmd)}", file=sys.stderr)
self._muxer = subprocess.Popen(
cmd,
stdin=subprocess.PIPE,
stderr=subprocess.DEVNULL,
stderr=subprocess.PIPE, # Capture stderr for debugging
)
def write(self, frame: Union[np.ndarray, 'cp.ndarray'], t: float = 0):