@@ -10,6 +10,8 @@ import fs from "node:fs";
1010import path from "node:path" ;
1111import { fileURLToPath } from "node:url" ;
1212import { pathToFileURL } from "node:url" ;
13+ import * as ffmpegInstaller from "@ffmpeg-installer/ffmpeg" ;
14+ import * as ffprobeInstaller from "@ffprobe-installer/ffprobe" ;
1315
1416const __filename = fileURLToPath ( import . meta. url ) ;
1517const __dirname = path . dirname ( __filename ) ;
@@ -18,6 +20,29 @@ const useDevServer = process.env.VITE_DEV_SERVER_URL !== undefined;
1820const runMode = process . env . FRAMESCRIPT_RUN_MODE ?? ( useDevServer ? "dev" : "bin" ) ;
1921const useBinaries = runMode !== "dev" ;
2022
23+ const resolveBundledBinaryPath = ( installer : unknown ) => {
24+ const candidate =
25+ ( installer as { path ?: string ; default ?: { path ?: string } } | undefined ) ?. path ??
26+ ( installer as { default ?: { path ?: string } } | undefined ) ?. default ?. path ;
27+ if ( typeof candidate === "string" && candidate . trim ( ) . length > 0 ) {
28+ return candidate ;
29+ }
30+ return null ;
31+ } ;
32+
33+ function getFfmpegEnv ( ) : NodeJS . ProcessEnv {
34+ const env : NodeJS . ProcessEnv = { } ;
35+ const ffmpegPath = process . env . FRAMESCRIPT_FFMPEG_PATH ?? resolveBundledBinaryPath ( ffmpegInstaller ) ;
36+ const ffprobePath = process . env . FRAMESCRIPT_FFPROBE_PATH ?? resolveBundledBinaryPath ( ffprobeInstaller ) ;
37+ if ( ffmpegPath ) {
38+ env . FRAMESCRIPT_FFMPEG_PATH = ffmpegPath ;
39+ }
40+ if ( ffprobePath ) {
41+ env . FRAMESCRIPT_FFPROBE_PATH = ffprobePath ;
42+ }
43+ return env ;
44+ }
45+
2146let mainWindow : BrowserWindow | null = null ;
2247let backendProcess : ChildProcess | null = null ;
2348let backendHealthyPromise : Promise < void > | null = null ;
@@ -88,6 +113,10 @@ function startBackend(): Promise<void> {
88113 backendProcess = spawn ( "cargo" , [ "run" ] , {
89114 cwd : backendCwd ,
90115 stdio : "pipe" ,
116+ env : {
117+ ...process . env ,
118+ ...getFfmpegEnv ( ) ,
119+ } ,
91120 } ) ;
92121
93122 console . log ( "[backend] spawn: cargo run (dev)" ) ;
@@ -103,6 +132,10 @@ function startBackend(): Promise<void> {
103132
104133 backendProcess = spawn ( info . path , [ ] , {
105134 stdio : "pipe" ,
135+ env : {
136+ ...process . env ,
137+ ...getFfmpegEnv ( ) ,
138+ } ,
106139 } ) ;
107140
108141 console . log ( "[backend] spawn:" , info . path ) ;
@@ -224,6 +257,7 @@ function startRenderProcess(payload: RenderStartPayload) {
224257 cwd : renderCwd ,
225258 env : {
226259 ...process . env ,
260+ ...getFfmpegEnv ( ) ,
227261 RENDER_PAGE_URL : getRenderPageUrl ( ) ,
228262 RENDER_OUTPUT_PATH : getRenderOutputPath ( ) ,
229263 } ,
@@ -257,6 +291,7 @@ function startRenderProcess(payload: RenderStartPayload) {
257291 renderChild = spawn ( binPath , [ argsString ] , {
258292 env : {
259293 ...process . env ,
294+ ...getFfmpegEnv ( ) ,
260295 RENDER_PAGE_URL : getRenderPageUrl ( ) ,
261296 RENDER_OUTPUT_PATH : getRenderOutputPath ( ) ,
262297 } ,
0 commit comments