diff options
| author | wuhei <wuhei@users.noreply.github.com> | 2026-11-19 12:43:33 +0100 |
|---|---|---|
| committer | wuhei <wuhei@users.noreply.github.com> | 2026-11-19 12:43:33 +0100 |
| commit | d991dca38bd8676c2fc0fe4bc4356d62ccc8e1b1 (patch) | |
| tree | 374e2f16936d3e7ddf1157c7cadec6f4059fea8f | |
| parent | a5b77eb48974cfae45bac65ceb4880752444eb47 (diff) | |
| download | lilchinese-d991dca38bd8676c2fc0fe4bc4356d62ccc8e1b1.tar.gz | |
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.
| -rw-r--r-- | main.go | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -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 } |
