Add ffmpeg to n8n docker image

The idea is:

To include the ffmpeg package pre-installed in the official n8n Docker image. Currently, users who need to process audio or video files must create a custom Dockerfile (extending the official image) or install it manually every time the container restarts, which is inefficient and adds unnecessary complexity to the deployment.

My use case:

I use n8n to automate media workflows. Specifically, when a file is received via a webhook or downloaded from a cloud storage service, I need to:

  • Convert audio formats (e.g., .ogg to .mp3) for better compatibility.
  • Extract audio from video files.
  • Compress or resize videos before uploading them to social media or sending them via messaging apps (like Telegram or WhatsApp).
  • Generate thumbnails from video files.

Currently, I have to maintain a custom Docker image just to have access to the ffmpeg binary within the Execute Command node.

I think it would be beneficial to add this because:

  • Media Processing is Common: As AI and multimedia automation grow (transcriptions, auto-editing, etc.), ffmpeg has become an essential tool for many n8n users.
  • Lower Entry Barrier: It eliminates the need for users to learn how to build custom Docker images or manage persistent binary installations.
  • Small Footprint vs. High Value: While it adds a bit to the image size, the utility it provides for “Execute Command” nodes is massive compared to the overhead.
  • Consistency: It ensures that workflows involving media processing are portable and work out-of-the-box across different environments (local, VPS, Cloud).

Any resources to support this?

  • FFmpeg Official Site: https://ffmpeg.org/
  • Alpine Linux Package (for the Alpine image): apk add ffmpeg
  • Debian/Ubuntu Package: apt-get install ffmpeg

Are you willing to work on this?

I can make the neccesary changes and create a MR on Github.

1 Like

Just to add some context: I’ve been running a custom n8n Docker image with ffmpeg pre-installed in a production environment for about a year now. It has been working flawlessly, handling multiple media conversion tasks daily without any stability issues or performance overhead on the core n8n process. It’s a battle-tested setup that would bring a lot of value to the community if made official.

2 Likes

Can you please help me with the latest update. I tried everything every video on youtube but no luck

Hello @Abhijeet_Singh , nice to meet you.

We’re currently working with version 1.123.18, so I don’t have much experience with version 2 yet, as we haven’t migrated. I suggest you post your question in a separate thread so other members of this community can help you. Best regards.

love it. i started using ffmpeg recently. though self-hosted. Im going to start rolling out videos and posts here of my work. Social media stuff. but ffmpeg a must have. I learned early on to download all media files that ffmpeg will pick up and edit - never input a url. And I run right in code node if needed, no problem. Has enough resources with a couple env settings allowed for it. like N8N_RUNNERS_MAX_OLD_SPACE_SIZE

I was able to update to the latest version recently. Here is the Dockerfile I’m using:

# STAGE 1: We bring in the static FFmpeg binaries from a specialized image
FROM mwader/static-ffmpeg:6.0 AS ffmpeg-source

# STAGE 2: We used the latest official (distro-less) version of n8n
FROM n8nio/n8n:2.28.6

# We temporarily switched to root to be able to copy files to system folders
USER root

# We copy the FFmpeg and FFprobe binaries from the first stage to the n8n path
COPY --from=ffmpeg-source /ffmpeg /usr/local/bin/ffmpeg
COPY --from=ffmpeg-source /ffprobe /usr/local/bin/ffprobe

# We are restoring permissions to the default n8n user for security reasons
USER node

Then, build your new custom image:

$ docker build -t n8n-custom:2.28.6 .

Finally, use this custom image on your docker-compose file:

services:
  n8n:
    image: n8n-custom:2.28.6
    . . .

It’s working in production without any problems. Furthermore, this same procedure can be used to add any other tool not pre-installed in the official n8n Docker image. Also tested on version 1.123.63

2 Likes

One thing to add to the Dockerfile above if anyone uses it for subtitles or drawtext: the n8n image has no fonts, and libass needs one. I only noticed because a render came back with no text on it and exit code 0.

docker exec <container> fc-list

if that’s empty, add

RUN apk add --no-cache fontconfig font-dejavu

I tested this with the apk-installed ffmpeg, not with the static build, so no idea if that one behaves the same (it links libass as well, so probably).

I use FFmpeg with n8n as well, but I’ve taken a slightly different approach.

Rather than adding FFmpeg to the main n8nio/n8n image, I put it in the external task-runners image. That keeps the main n8n container close to stock and puts the media-processing tools alongside the isolated Code-node runtime.

A simplified version of the setup would look something like this:

ARG N8N_TAG
FROM mwader/static-ffmpeg:latest AS ffmpeg

FROM n8nio/runners:${N8N_TAG}

USER root

COPY --from=ffmpeg /ffmpeg /usr/local/bin/ffmpeg
COPY --from=ffmpeg /ffprobe /usr/local/bin/ffprobe

USER runner

Then in Compose:

services:
  n8n:
    image: n8nio/n8n:${N8N_TAG}
    environment:
      N8N_RUNNERS_MODE: external
      N8N_RUNNERS_AUTH_TOKEN: ${N8N_RUNNERS_AUTH_TOKEN}
      N8N_RUNNERS_BROKER_LISTEN_ADDRESS: 0.0.0.0

  task-runners:
    build:
      context: .
      dockerfile: Dockerfile.runners
      args:
        N8N_TAG: ${N8N_TAG}
    environment:
      N8N_RUNNERS_AUTH_TOKEN: ${N8N_RUNNERS_AUTH_TOKEN}
      N8N_RUNNERS_TASK_BROKER_URI: http://n8n:5679
    depends_on:
      - n8n

The important part is that ${N8N_TAG} is the same for both images.

If FFmpeg is being launched from JavaScript in a Code node, the runner also needs the relevant built-in Node module allowed, for example child_process. That permission should be deliberate because you’re effectively allowing Code-node scripts to start processes inside the runner container.

The Dockerfile posted previously is still a perfectly valid pattern if the goal is to use FFmpeg from Execute Command, because in that case the binary needs to exist in the n8n container or worker executing the workflow.

That is really the distinction I think matters in n8n 2.x.

If you use Execute Command, put FFmpeg in the n8n/worker image.

If you use Code nodes with external task runners, put FFmpeg in the runner image.

In my actual setup the runner image contains FFmpeg, ImageMagick, Ghostscript and a few other tools used by Code-node workloads, while the main n8n image stays lean. I also keep the n8n and runner versions locked together.

That’s why I’m not convinced FFmpeg needs to be added to the official n8n image for everyone. I think an officially documented FFmpeg runner example, or perhaps an optional media-enabled image, would solve the problem without adding another large dependency to every n8n installation.

One small caution with the “same procedure can be used to add any other tool” point: copying static binaries works very well for FFmpeg, but not every CLI tool is self-contained. Some need shared libraries, fonts, certificates, configuration files or other runtime dependencies.

So I agree strongly with the use case. I’d just separate the feature request from the deployment pattern: FFmpeg is extremely useful in n8n, but the right container to install it in depends on how the workflow is actually executing it.

Correcting myself from above, and a note on @Michael_Long’s runner setup, because the two are connected.

I said the n8n image has no fonts. That is wrong for the main image. I checked 2.39.8 yesterday: /usr/share/fonts holds 118 files (the base image installs the MS core fonts), so with the static build from the Dockerfile above both subtitles= and drawtext= render text. You get Fontconfig error: Cannot load default config file on stderr every time, but the text is there.

It is true for the runner image though. n8nio/runners:2.39.8 is plain Alpine 3.24 with nothing in /usr/share/fonts. Michael’s Dockerfile builds fine against 2.39.8 (ffmpeg 9.0.1, runs as runner), and then:

  • subtitles=file.srt exits with code 0 and gives you frames with no text on them
  • drawtext=... fails with exit 254

The first one is the nasty one, because nothing tells you. [NILS: ein Satz, wie dir das leere Rendering zuerst aufgefallen ist]

The runner image has no apk either, so I copy fonts and the fontconfig config in from an Alpine stage:

ARG N8N_TAG
FROM mwader/static-ffmpeg:latest AS ffmpeg
FROM alpine:3.24 AS fonts
RUN apk add --no-cache fontconfig font-dejavu

FROM n8nio/runners:${N8N_TAG}
USER root
COPY --from=ffmpeg /ffmpeg /usr/local/bin/ffmpeg
COPY --from=ffmpeg /ffprobe /usr/local/bin/ffprobe
COPY --from=fonts /usr/share/fonts /usr/share/fonts
COPY --from=fonts /etc/fonts /etc/fonts
USER runner

With that both filters render and the Fontconfig warning is gone as well. Quick check for anyone’s image: docker run --rm --entrypoint sh <image> -c 'ls /usr/share/fonts'.

On the feature request itself I agree with Michael, a documented runner example would help more than ffmpeg in every image. If n8n writes one, fonts should be in it.

1 Like

@Biboo, Good catch, and thanks for actually testing it against 2.39.8.

One clarification from my side: the Dockerfile I posted above was deliberately a simplified example to show the runner pattern, not my full production runner image. My actual runner image already includes fontconfig plus DejaVu and Noto fonts along with ffmpeg and the other media tools.

So I think your finding is still very useful, especially because the subtitles case is exactly the kind of failure that can be missed. An ffmpeg command returning exit code 0 while producing frames with no visible subtitles is much worse than an obvious hard failure.

It also strengthens the point about documentation. If n8n ever publishes an official ffmpeg runner example, it probably shouldn’t stop at copying ffmpeg and ffprobe. It should include fontconfig and at least one sane font family, otherwise common filters like subtitles and drawtext can behave unexpectedly.

I’d probably also copy the generated fontconfig cache from the Alpine stage, just to make the runner image a little more deterministic for the non-root runner user.

And yes, I agree with the broader conclusion. A documented runner example seems more useful than putting ffmpeg into every n8n image by default.

Thanks for taking the time to actually build and test the example rather than just theorising about it.

Fair, and good to know your production image already has them. I took the simplified example at face value because that is what the next reader will do too.

The cache copy is a good call. The runner user cannot write to /var/cache/fontconfig, so without it every fresh container rebuilds the cache into the runner’s home on first use. I will add the fc-cache step and the copy to the fonts stage and report the before/after.

Agreed on the documentation point. If n8n publishes a runner example, ffmpeg plus ffprobe alone would reproduce exactly the silent-subtitle case.

Measured the cache copy today, single fonts stage, cache copied into n8nio/runners:2.39.8 next to the fonts.

It does not stick. Fontconfig records the font directory’s mtime in the cache file, and after COPY --from the directory has a different mtime, so FcCacheTimeValid rejects the copied cache and the runner rebuilds it into /home/runner/.cache/fontconfig on first use, same as without the copy. First run 40 to 50 ms either way, later runs 10 to 40 ms, all noise.

So I would leave the copy out. The one case where a baked cache matters is a read-only root filesystem, and there it would need fc-cache run inside the final image, not a copy.

That makes sense. I went back and pulled the actual Dockerfile.runners from my server rather than relying on the simplified example I posted earlier.

This is what I’m actually running:

# syntax=docker/dockerfile:1
ARG N8N_TAG
FROM n8nio/runners:${N8N_TAG}

USER root

RUN ARCH=$(uname -m) && \
    wget -qO- "http://dl-cdn.alpinelinux.org/alpine/latest-stable/main/${ARCH}/" | \
    grep -o 'href="apk-tools-static-[^"]*\.apk"' | head -1 | cut -d'"' -f2 | \
    xargs -I {} wget -q "http://dl-cdn.alpinelinux.org/alpine/latest-stable/main/${ARCH}/{}" && \
    tar -xzf apk-tools-static-*.apk && \
    ./sbin/apk.static -X http://dl-cdn.alpinelinux.org/alpine/latest-stable/main \
        -U --allow-untrusted add apk-tools && \
    rm -rf sbin apk-tools-static-*.apk

# System packages (binaries + utilities)
RUN apk add --no-cache \
  python3 \
  py3-pip \
  bash curl git jq openssl tar unzip wget zip \
  nodejs npm \
  ffmpeg imagemagick ghostscript fontconfig ttf-dejavu font-noto-emoji

# JS deps used by Code node
WORKDIR /opt/runners-js
COPY runners.package.json package.json
RUN npm install --omit=dev && npm cache clean --force

# Make node_modules available to JS runner
ENV NODE_PATH=/opt/runners-js/node_modules

# Working dir for CLI ops
RUN mkdir -p /data

# Stay as root for compatibility with CLI/Python/FFmpeg/etc.
USER root

This general setup has been running in production for over a year and has been very stable for the media and CLI workloads I use it for.

So that explains why I wasn’t seeing the missing-font behaviour in the real setup. I’m installing fontconfig, DejaVu and Noto Emoji directly into the final runner image alongside ffmpeg. Alpine runs the fontconfig/mkfontscale triggers during that install, so there isn’t a cache being copied from another stage and subsequently invalidated by different directory mtimes.

Your cache measurement still stands. I don’t see any reason to copy /var/cache/fontconfig between stages if fontconfig is just going to reject it and rebuild under the runner user anyway. For a read-only filesystem I agree it becomes a different problem and the cache would need to be generated against the final filesystem.

There’s another part of my setup that may be useful here too. The stock runner image doesn’t leave apk available, so the first block restores apk-tools using Alpine’s static apk package. After that I can install ffmpeg, fonts, ImageMagick, Ghostscript, Python, Node/npm and the other tools normally.

Looking at it again, that bootstrap is something I’d tighten up. Mine currently fetches over HTTP and uses --allow-untrusted. It has worked, but I’d rather use HTTPS and retain package verification. I’d also consider removing apk-tools again after all the packages have been installed, since the running runner container doesn’t need a package manager just because the image build did.

I also leave this runner as root at the moment for compatibility with the CLI/Python/media workloads. That’s a separate hardening decision, but worth stating because this isn’t meant to be presented as the smallest possible runner image.

So the simplified example I posted earlier was definitely too stripped down for media work involving text. Your test caught a real difference between that example and the production image I’m actually using.

This discussion has actually made me look at the setup with fresh eyes. It has been reliable enough that I haven’t had much reason to revisit it, but there are clearly a few areas where I can make it cleaner and tighter without changing the architecture that has been working well.

Thanks for measuring the cache behaviour and pushing on the implementation details. That’s been useful.

One thing I missed in my previous post: the runner image also uses a separate runners.package.json, and that is intentional.

The Dockerfile and runners.package.json are managing two different kinds of dependencies.

The Dockerfile uses apk for operating-system level tools and binaries:

RUN apk add --no-cache \
  python3 \
  py3-pip \
  bash curl git jq openssl tar unzip wget zip \
  nodejs npm \
  ffmpeg imagemagick ghostscript fontconfig ttf-dejavu font-noto-emoji

Those packages become part of the container filesystem. Things like ffmpeg, convert, gs, python3 and jq are executables that Code nodes can call through the OS.

runners.package.json is different. That is only for JavaScript modules that I want Code nodes to be able to require():

{
  "name": "n8n-task-runners-deps",
  "private": true,
  "license": "UNLICENSED",
  "dependencies": {
    "axios": "^1.7.7",
    "crypto-js": "^4.2.0",
    "form-data": "^4.0.0",
    "he": "^1.2.0",
    "libphonenumber-js": "^1.11.7",
    "lodash": "^4.17.21",
    "luxon": "^3.5.0",
    "papaparse": "^5.4.1",
    "qs": "^6.13.0",
    "uuid": "^9.0.1",
    "xml2js": "^0.6.2"
  }
}

The Dockerfile then copies that into /opt/runners-js as package.json, runs npm install, and sets:

ENV NODE_PATH=/opt/runners-js/node_modules

So a Code node can use something like:

const axios = require('axios');

because axios came from runners.package.json.

But if that same Code node wants to launch ffmpeg, the ffmpeg binary has to exist in the container itself, which is why that comes from apk.

So I keep them separate deliberately:

apk builds the OS/tooling layer.

runners.package.json builds the JavaScript library layer.

I could technically use npm wrappers for some native tools, but I prefer installing things like ffmpeg, ImageMagick and Ghostscript at the OS level rather than hiding native binaries behind npm packages.

This setup has been running in production for over a year. The move to n8n v2 complicated the OS side slightly because the runner image no longer leaves apk-tools available, which is why my current Dockerfile restores apk first.

The discussion here has made me go back through a setup that has been stable enough that I haven’t had much reason to revisit it. I can already see a few areas I want to tighten up, particularly the v2 apk bootstrap and some of the runner hardening, while keeping the basic separation between native tools and JS dependencies.