From 68806e119070aa5d05771380887cb4b027e9987e Mon Sep 17 00:00:00 2001 From: yumoqing Date: Mon, 29 Jun 2026 23:58:31 +0800 Subject: [PATCH] fix: use fragmented MP4 for crash-safe HLS live stream recording MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -movflags +faststart requires ffmpeg to write moov atom at the end, which fails when SIGINT interrupts a live HLS recording — the mp4 file has no moov atom and is unplayable (0 bytes effective). Switch to -movflags +frag_keyframe+empty_moov+default_base_moof (fragmented MP4): moov atom written immediately at file start, each segment is self-contained. Even if ffmpeg is killed mid-recording, the file remains fully playable with both video and audio intact. Verified: HLS live stream (CBS News) → 45s 1280x720 h264 + AAC 48kHz, 13MB, SIGINT-safe. Local files unaffected. --- Sources/StreamRecorderKit/FFmpegRecorder.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/StreamRecorderKit/FFmpegRecorder.swift b/Sources/StreamRecorderKit/FFmpegRecorder.swift index 2481e36..2a10ce1 100644 --- a/Sources/StreamRecorderKit/FFmpegRecorder.swift +++ b/Sources/StreamRecorderKit/FFmpegRecorder.swift @@ -59,7 +59,7 @@ public final class FFmpegRecorder: StreamRecorderEngine { "-c:v", "copy", "-c:a", "aac", "-b:a", "192k", - "-movflags", "+faststart", + "-movflags", "+frag_keyframe+empty_moov+default_base_moof", outputPath ] proc.arguments = args