import { FfmpegClass } from "https://deno.land/x/deno_ffmpeg@v3.1.0/src/ffmpegClass.ts";
Constructors
new
FfmpegClass(options?: Spawn)Create a new instance of ffmpeg
Example
import { FfmpegClass } from "../mod.ts";
const ffmpeg = new FfmpegClass({
// Optional
threads: 5,
// Optional. can be set via `FfmpegClass#setFfmpegPath()`
ffmpegDir: "ffmpeg",
// Ignored on windows (should range between -20 and 20)
niceness: 20,
// Optional. can be set via `FfmpegClass#addInput()`
input: "./tests/videos/input.mp4",
});
Methods
private
__clear(input: "audio" | "video"): voidprivate
__closeProcess(hasProgress: boolean): Promise<void | Uint8Array>private
__errorCheck(): voidprivate
__formatting(): string[]private
__getProgress(): AsyncGenerator<Progress>addInput(input: string, options?: Record<string, string | undefined>): this
Add a input
Example
import { FfmpegClass } from "../mod.ts"
const ffmpeg = new FfmpegClass();
ffmpeg.addInput("file.mp4");
ffmpeg.addInput("https://some.link/file.mp4");
ffmpeg.addInput("./tests/videos/concat.txt", { f: "concat" });
addInput(input: Uint8Array, options?: Record<string, string | undefined>): this
Add a input
Example
import { FfmpegClass } from "../mod.ts"
const ffmpeg = new FfmpegClass();
const binaryData = await Deno.readFile("file.mp4");
ffmpeg.addInput(binaryData);
audioBitrate(bitrate: number): this
Set the audio bitrate in kbps
Example
import { FfmpegClass } from "../mod.ts"
const ffmpeg = new FfmpegClass();
ffmpeg.audioBitrate(128);
audioCodec(codec: string, options?: Record<string, string | number | undefined>): this
Set the audio codec
Example
import { FfmpegClass } from "../mod.ts"
const ffmpeg = new FfmpegClass();
ffmpeg.audioCodec("libmp3lame");
audioFilters(...filters: Filters[]): this
Set audio filters
Example
import { FfmpegClass } from "../mod.ts"
const ffmpeg = new FfmpegClass();
ffmpeg.audioFilters(
{
filterName: "afade",
options: {
t: "in",
ss: 0,
d: 15,
},
},
{
filterName: "afade",
options: {
t: "out",
ss: 0,
d: 15,
},
},
);
complexFilters(...Filters: Filters[]): this
Set complex filters
Example
import { FfmpegClass } from "../mod.ts"
const ffmpeg = new FfmpegClass();
ffmpeg.complexFilters(
{
filterName: "overlay",
options: {
x: "150",
},
},
);
noAudio(): this
Disable audio
Example
import { FfmpegClass } from "../mod.ts"
const ffmpeg = new FfmpegClass();
ffmpeg.noAudio();
noVideo(): this
Disable video
Example
import { FfmpegClass } from "../mod.ts"
const ffmpeg = new FfmpegClass();
ffmpeg.noVideo();
outputFPS(fps: number): this
Set output framerate
Example
import { FfmpegClass } from "../mod.ts"
const ffmpeg = new FfmpegClass();
ffmpeg.outputFPS(60);
save(): Promise<Uint8Array>
output: "pipe:1",
iterator?: false,
options?: Record<string, string | number | undefined>,
Start render and get Uint8Array
Example
import { FfmpegClass } from "../mod.ts"
const ffmpeg = new FfmpegClass();
const data = await ffmpeg.save("pipe:1");
save(): Promise<void>
output: string,
iterator?: false,
options?: Record<string, string | number | undefined>,
Start render and save to disk
Example
import { FfmpegClass } from "../mod.ts"
const ffmpeg = new FfmpegClass();
await ffmpeg.save("outputfile.mp4");
save(): Promise<AsyncGenerator<Progress>>
output: "pipe:1",
iterator?: true,
options?: Record<string, string | number | undefined>,
NOT SUPPORTED!
save(): Promise<AsyncGenerator<Progress>>
output: string,
iterator?: true,
options?: Record<string, string | number | undefined>,
Start render with iterator
Example
import { FfmpegClass } from "../mod.ts"
const ffmpeg = new FfmpegClass();
const iterator = await ffmpeg.save("outputfile.mp4", true);
for await (const iter of iterator) {
console.log(iter.percentage)
}
setFfmpegPath(ffmpegPath: string): this
Set ffmpeg path
Example
import { FfmpegClass } from "../mod.ts"
const ffmpeg = new FfmpegClass();
ffmpeg.setFfmpegPath("./somedir/binary");
ffmpeg.setFfmpegPath("ffmpeg"); // this works as long as ffmpeg is in your PATH
setHeight(height: number): this
Set the frame height
Example
import { FfmpegClass } from "../mod.ts"
const ffmpeg = new FfmpegClass();
ffmpeg.setHeight(720);
ffmpeg.setHeight(-1); // Auto scales to aspect ratio
setWidth(width: number): this
Set the frame width
Example
import { FfmpegClass } from "../mod.ts"
const ffmpeg = new FfmpegClass();
ffmpeg.setWidth(720);
ffmpeg.setWidth(-1); // Auto scales to aspect ratio
threads(amount: number): this
Set amount of threads
Example
import { FfmpegClass } from "../mod.ts"
const ffmpeg = new FfmpegClass();
ffmpeg.threads(1);
ffmpeg.threads(16);
videoBitrate(bitrate: string, cbr?): this
Set the video bitrate in kbps or mbps
Example
import { FfmpegClass } from "../mod.ts"
const ffmpeg = new FfmpegClass();
ffmpeg.videoBitrate("10m"); // 10 mbps with cbr enabled
ffmpeg.videoBitrate("1000k"); // 1000 kbps with cbr enabled
ffmpeg.videoBitrate("1000k", true); // 1000 kbps with cbr enabled
ffmpeg.videoBitrate("1000k", false); // 1000 kbps with vbr enabled
videoCodec(codec: string, options?: Record<string, string | undefined>): this
Set the video codec
Example
import { FfmpegClass } from "../mod.ts"
const ffmpeg = new FfmpegClass();
ffmpeg.videoCodec("libx264");
videoFilters(...Filters: Filters[]): this
Set video filters
Example
import { FfmpegClass } from "../mod.ts"
const ffmpeg = new FfmpegClass();
ffmpeg.videoFilters(
{
filterName: "drawtext",
options: {
text: "thingy",
fontsize: "60",
x: (856 / 2 - 30 * "thingy".length / 2),
y: "H-240",
fontcolor: "white",
shadowcolor: "black",
shadowx: "2",
shadowy: "2",
},
},
);