diff --git a/electrobun.config.ts b/electrobun.config.ts index dddb809..47e99c4 100644 --- a/electrobun.config.ts +++ b/electrobun.config.ts @@ -4,7 +4,7 @@ export default { app: { name: "yafw", identifier: "yafw.electrobun.dev", - version: "0.7.1", + version: "0.7.3", }, build: { // Vite builds to dist/, Electrobun copies from there into the bundle diff --git a/src/bun/index.ts b/src/bun/index.ts index 5b63f52..bbf4613 100644 --- a/src/bun/index.ts +++ b/src/bun/index.ts @@ -4,6 +4,25 @@ import { basename, dirname, extname, join } from "path"; import { homedir } from "os"; import { update } from "./updater"; +const getBinaryPathAsync = async (name: "ffmpeg" | "ffprobe"): Promise => { + if (process.platform === "darwin") { + const paths = [ + `/opt/homebrew/bin/${name}`, + `/usr/local/bin/${name}`, + `/opt/local/bin/${name}`, + ]; + for (const p of paths) { + if (await Bun.file(p).exists()) { + return p; + } + } + } + return name; +} + +const ffmpegPathPromise = getBinaryPathAsync("ffmpeg"); +const ffprobePathPromise = getBinaryPathAsync("ffprobe"); + const DEV_SERVER_PORT = 5173; const DEV_SERVER_URL = `http://localhost:${DEV_SERVER_PORT}`; @@ -125,7 +144,7 @@ const rpc = BrowserView.defineRPC({ ]; console.log(`[FFmpeg] ffmpeg ${fullArgs.join(" ")}`); - const proc = Bun.spawn(["ffmpeg", ...fullArgs], { + const proc = Bun.spawn([await ffmpegPathPromise, ...fullArgs], { stdout: "pipe", stderr: "pipe", }); @@ -192,7 +211,7 @@ const rpc = BrowserView.defineRPC({ console.log("[YAFW] probeVideo:", inputPath); try { const proc = Bun.spawn([ - "ffprobe", + await ffprobePathPromise, "-v", "error", "-select_streams", "v:0", "-show_entries", "stream=r_frame_rate,width,height,bit_rate,duration:format=duration", @@ -231,7 +250,7 @@ const rpc = BrowserView.defineRPC({ detectHardwareAccelerators: async () => { console.log("[YAFW] detectHardwareAccelerators called"); try { - const proc = Bun.spawn(["ffmpeg", "-encoders"], { + const proc = Bun.spawn([await ffmpegPathPromise, "-encoders"], { stdout: "pipe", stderr: "pipe", });