@darco2903/ffmpeg-ts
v1.0.6
Published
TypeScript FFMPEG CLI Wrapper
Downloads
342
Maintainers
Readme
FFMPEG TS
This library provides a TypeScript wrapper around the FFMPEG command-line tool, allowing you to easily run FFMPEG commands, monitor progress, and handle output in a TypeScript environment.
Installation
npm install @darco2903/ffmpeg-tsExample
import { FFMPEG } from "@darco2903/ffmpeg-ts";
const args: string[] = ["-i", "input.mp4", "-c:v", "libx264", "-preset", "fast", "-c:a", "aac", "-b:a", "128k", "output.mp4", "-y"];
const ffmpeg = new FFMPEG(args);
// or specify a custom FFMPEG executable path
const ffmpeg = new FFMPEG(args, { execPath: "/path/to/ffmpeg" });
// Listen to progress events
ffmpeg.on("progress", (progress) => {
console.log(`Progress: ${progress.percent?.toFixed(2)}%`);
});
const res = await ffmpeg.start();
if (res.isOk()) {
console.log("FFMPEG processing completed successfully.");
} else {
console.error(`FFMPEG processing failed with code ${res.error.code}: ${res.error.message}`);
}You can stop the FFMPEG process at any time by ffmpeg.stop().
// Stop the FFMPEG process with default signal (SIGTERM)
ffmpeg.stop();
// or with a specific signal
ffmpeg.stop("SIGINT");