Spawn ffprobe with given args, return stdout. Throws on non-zero exit or missing binary.
(args: string[])
| 6 | |
| 7 | /** Spawn ffprobe with given args, return stdout. Throws on non-zero exit or missing binary. */ |
| 8 | function runFfprobe(args: string[]): Promise<string> { |
| 9 | return new Promise((resolve, reject) => { |
| 10 | const command = getFfprobeBinary(); |
| 11 | const proc = spawn(command, args); |
| 12 | let stdout = ""; |
| 13 | let stderr = ""; |
| 14 | proc.stdout.on("data", (data) => { |
| 15 | stdout += data.toString(); |
| 16 | }); |
| 17 | proc.stderr.on("data", (data) => { |
| 18 | stderr += data.toString(); |
| 19 | }); |
| 20 | proc.on("close", (code) => { |
| 21 | if (code !== 0) { |
| 22 | reject(new Error(`[FFmpeg] ffprobe exited with code ${code}: ${stderr}`)); |
| 23 | } else { |
| 24 | resolve(stdout); |
| 25 | } |
| 26 | }); |
| 27 | proc.on("error", (err) => { |
| 28 | if ((err as NodeJS.ErrnoException).code === "ENOENT") { |
| 29 | const configured = process.env[FFPROBE_PATH_ENV]?.trim(); |
| 30 | reject( |
| 31 | new Error( |
| 32 | configured |
| 33 | ? `[FFmpeg] ffprobe not found at ${FFPROBE_PATH_ENV}="${configured}". Please install FFmpeg.` |
| 34 | : "[FFmpeg] ffprobe not found. Please install FFmpeg.", |
| 35 | ), |
| 36 | ); |
| 37 | } else { |
| 38 | reject(err); |
| 39 | } |
| 40 | }); |
| 41 | }); |
| 42 | } |
| 43 | |
| 44 | function parseProbeJson(stdout: string): FFProbeOutput { |
| 45 | try { |
no test coverage detected