Update IPFS playlist CID in database during streaming for live HLS
- Add on_playlist_update callback to IPFSHLSOutput - Pass callback through StreamInterpreter to output - Update database with playlist CID as segments are created - Enables live HLS redirect to IPFS before rendering completes Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -645,6 +645,7 @@ class IPFSHLSOutput(Output):
|
||||
preset: str = "fast",
|
||||
audio_source: str = None,
|
||||
ipfs_gateway: str = "https://ipfs.io/ipfs",
|
||||
on_playlist_update: callable = None,
|
||||
):
|
||||
self.output_dir = Path(output_dir)
|
||||
self.output_dir.mkdir(parents=True, exist_ok=True)
|
||||
@@ -653,6 +654,7 @@ class IPFSHLSOutput(Output):
|
||||
self.segment_duration = segment_duration
|
||||
self.ipfs_gateway = ipfs_gateway.rstrip("/")
|
||||
self._is_open = True
|
||||
self._on_playlist_update = on_playlist_update # Callback when playlist CID changes
|
||||
|
||||
# Auto-detect NVENC
|
||||
if codec == "auto":
|
||||
@@ -792,6 +794,12 @@ class IPFSHLSOutput(Output):
|
||||
if cid:
|
||||
self._playlist_cid = cid
|
||||
print(f"IPFS: playlist updated -> {cid} ({len(self.segment_cids)} segments)", file=sys.stderr)
|
||||
# Notify callback (e.g., to update database for live HLS redirect)
|
||||
if self._on_playlist_update:
|
||||
try:
|
||||
self._on_playlist_update(cid)
|
||||
except Exception as e:
|
||||
print(f"IPFS: playlist callback error: {e}", file=sys.stderr)
|
||||
|
||||
def write(self, frame: np.ndarray, t: float):
|
||||
"""Write frame to HLS stream and upload segments to IPFS."""
|
||||
|
||||
Reference in New Issue
Block a user