From 58caff3209b1ae5c7a9bf9d43f774f9bf8183e27 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 31 Mar 2026 15:58:54 +0000 Subject: [PATCH] fix: auto-fix ffmpeg binary execute permission on startup The bundled ffmpeg-static binary may lose execute permission after npm install on some platforms, causing EACCES errors during playback. Now checks and fixes the permission automatically before spawning ffmpeg. https://claude.ai/code/session_01CqfKgV8GuCmWNpfx86H62X --- src/audio/player.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/audio/player.ts b/src/audio/player.ts index f637c48..f013782 100644 --- a/src/audio/player.ts +++ b/src/audio/player.ts @@ -1,6 +1,7 @@ import { spawn, type ChildProcess } from "node:child_process"; import { EventEmitter } from "node:events"; import { createRequire } from "node:module"; +import { accessSync, chmodSync, constants } from "node:fs"; import { createOpusEncoder, PCM_FRAME_BYTES, type Encoder } from "./encoder.js"; import type { Logger } from "../logger.js"; @@ -8,9 +9,24 @@ import type { Logger } from "../logger.js"; const require = createRequire(import.meta.url); const ffmpegPath: string | null = require("ffmpeg-static"); +/** Ensure the bundled ffmpeg binary has execute permission. */ +function ensureExecutable(binPath: string): boolean { + try { + accessSync(binPath, constants.X_OK); + return true; + } catch { + try { + chmodSync(binPath, 0o755); + return true; + } catch { + return false; + } + } +} + /** Resolve ffmpeg binary: prefer bundled ffmpeg-static, fall back to system PATH. */ function getFfmpegCommand(): string { - if (ffmpegPath) return ffmpegPath; + if (ffmpegPath && ensureExecutable(ffmpegPath)) return ffmpegPath; return "ffmpeg"; // fallback to system-installed ffmpeg }