From d991dca38bd8676c2fc0fe4bc4356d62ccc8e1b1 Mon Sep 17 00:00:00 2001 From: wuhei Date: Thu, 19 Nov 2026 12:43:33 +0100 Subject: recorder: run ffmpeg and the audio source in their own process group A terminal Ctrl+C signals the whole foreground process group, so ffmpeg got a second SIGINT while it was writing the mp4 trailer and truncated the file ('moov atom not found'). Setpgid keeps our single SIGINT the only one. --- main.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index ab20108..d58aaa6 100644 --- a/main.go +++ b/main.go @@ -257,13 +257,17 @@ func micCmd(source string) *exec.Cmd { if source != "" { args = append(args, "--device="+source) } - return exec.Command("parec", args...) + c := exec.Command("parec", args...) + c.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} + return c } func fileCmd(path string) *exec.Cmd { - return exec.Command("ffmpeg", "-hide_banner", "-loglevel", "error", + c := exec.Command("ffmpeg", "-hide_banner", "-loglevel", "error", "-re", "-i", path, "-f", "s16le", "-acodec", "pcm_s16le", "-ac", "1", "-ar", "16000", "-") + c.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} + return c } func runASR(cmd *exec.Cmd, rec *sherpa.OnlineRecognizer, stream *sherpa.OnlineStream, pres *presenter) error { @@ -388,6 +392,9 @@ func startRecorder(path, source string) (*exec.Cmd, error) { } cmd := exec.Command("ffmpeg", args...) cmd.Stderr = os.Stderr + // Own process group: a terminal Ctrl+C signals the whole group, and ffmpeg + // receiving a second SIGINT while finalizing would truncate the mp4. + cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} if err := cmd.Start(); err != nil { return nil, err } -- cgit v1.2.3