How to Use FFmpeg with Deno (No Installation Required)

typescript dev.to

Originally published at ffmpeg-micro.com

You're building something in Deno and you need video processing. Thumbnail generation, format conversion, transcoding user uploads. You search for "ffmpeg deno" and quickly realize the ecosystem isn't like Node.js. There's no fluent-ffmpeg equivalent.

Deno's security model makes this worse. By default, Deno sandboxes your code. No file system access, no subprocess execution, no network calls unless you explicitly grant permissions.

There are three realistic paths.

Using Deno.Command with a Local FFmpeg Binary

const command = new Deno.Command("ffmpeg", {
  args: ["-i", "input.mp4", "-c:v", "libx264", "-crf", "23", "-preset", "medium", "-c:a", "aac", "-b:a", "192k", "output.mp4"],
  stderr: "piped",
});
const process = command.spawn();
const { code } = await process.status;
Enter fullscreen mode Exit fullscreen mode

You must run this with --allow-run=ffmpeg and --allow-read / --allow-write flags. Works for local scripts but breaks on Deno Deploy.

Using FFmpeg WASM in Deno

import { FFmpeg } from "npm:@ffmpeg/ffmpeg";
import { fetchFile } from "npm:@ffmpeg/util";

const ffmpeg = new FFmpeg();
await ffmpeg.load();
await ffmpeg.writeFile("input.mp4", await fetchFile("./input.mp4"));
await ffmpeg.exec(["-i", "input.mp4", "-c:v", "libx264", "output.mp4"]);
const data = await ffmpeg.readFile("output.mp4");
await Deno.writeFile("output.mp4", data);
Enter fullscreen mode Exit fullscreen mode

No binary needed, but 10-20x slower than native FFmpeg. Fine for lightweight operations only.

Using a Cloud API (FFmpeg Micro)

const response = await fetch("https://api.ffmpeg-micro.com/v1/transcodes", {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${Deno.env.get("FFMPEG_MICRO_API_KEY")}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    inputs: [{ url: "https://example.com/video.mp4" }],
    outputFormat: "mp4",
    preset: { quality: "high", resolution: "1080p" },
  }),
});
const job = await response.json();
Enter fullscreen mode Exit fullscreen mode

No npm packages. No binary dependencies. Works everywhere Deno runs, including Deno Deploy.

Read the full guide with polling, download, and advanced examples.

Source: dev.to

arrow_back Back to Tutorials