simply-ffmpeg
v0.1.0
Published
An type-safe and easy-to-use abstraction for FFmpeg
Readme
simply-ffmpeg
Still very early development
An type-safe and easy-to-use abstraction for FFmpeg.
Installation
npm install simply-ffmpeg
# or
pnpm add simply-ffmpeg
# or
yarn add simply-ffmpeg
# or
bun add simply-ffmpegYou must also have ffmpeg and ffprobe installed and available on path. This can be verified using validateFfmpegAvailable() and validateFfprobeAvailable.
Usage
Still very early development, better documentation coming
import ffmpeg from "simply-ffmpeg";
ffmpeg(); // Returns a new instance of Ffmpeg(Or with cjs)
const { ffmpeg } = require("simply-ffmpeg/cjs");
ffmpeg(); // Returns a new instance of FfmpegExamples
Create a new video file using video from one file and the audio from another file
await ffmpeg()
.input("./path/to/video.mp4", "vid") // Inputs video file, name it "vid"
.input("./path/to/audio.m4a", "aud") // Inputs audio file, name it "aud"
.map("vid", "v") // Use video stream from input "vid"
.map("aud", "a") // Use audio stream from input "aud"
.codec("copy", "v") // Copy the video stream codec
// Start the process and print a completion percentage to console on every update
.exec("./path/to/output.mp4", {
onUpdate: (cur, tot) => console.log(`${Math.floor((cur / tot) * 100)}%`),
});# The code above will produce the same result as running this ffmpeg command:
ffmpeg -i ./path/to/video.mp4 -i ./path/to/audio.m4a -m 0:v -m 1:a -c:v copy ./path/to/output.mp4Create a new video file with metadata about audio streams languages
await ffmpeg()
.input("./path/to/video.mp4", "vid") // Import video file, name it "vid"
.metadata("language=eng", "a", 0) // Adds metadata setting language to "eng" for the first (0) audio stream
.metadata("language=fra", "a", 1) // Adds metadata setting language to "fra" for the second (1) audio stream
// Start the process and print a completion percentage to console on every update
.exec("./path/to/output.mp4", {
onUpdate: (cur, tot) => console.log(`${Math.floor((cur / tot) * 100)}%`),
});# The code above will produce the same result as running this ffmpeg command:
ffmpeg -i ./path/to/video.mp4 -metatada:s:a:0 language=eng -metatada:s:a:1 language=fra ./path/to/output.mp4