Skip to content

Instantly share code, notes, and snippets.

@alexdelprete
Forked from justcallmelarry/Dockerfile
Last active September 28, 2025 23:53
Show Gist options
  • Save alexdelprete/cca5cef612162b157afb77bdbf4fcb1e to your computer and use it in GitHub Desktop.
Save alexdelprete/cca5cef612162b157afb77bdbf4fcb1e to your computer and use it in GitHub Desktop.
ffmpeg-builder (for audiobookshelf)

ffmpeg and ffprobe generation script for use with audiobookshelf

  1. copy the Dockerfile (original effort and kudos goes to dymk) and the shell script to a folder on your machine (I keep min close to my docker compose for ABS)
  2. make shell script executable
  3. run shell script, this should ues docker to build ffmpeg and ffprobe with xHE-AAC support and copy the binaries to the current folder
  4. volume in the built ffmpeg and ffprobe to the audiobookshelf container (see the latest additions to volumes in the example compose):
### EXAMPLE DOCKER COMPOSE ###
services:
  audiobookshelf:
    image: ghcr.io/advplyr/audiobookshelf:latest
    # ABS runs on port 13378 by default. If you want to change
    # the port, only change the external port, not the internal port
    ports:
      - 13378:80
    volumes:
      # These volumes are needed to keep your library persistent
      # and allow media to be accessed by the ABS server.
      # The path to the left of the colon is the path on your computer,
      # and the path to the right of the colon is where the data is
      # available to ABS in Docker.
      # You can change these media directories or add as many as you want
      - ./audiobooks:/audiobooks
      - ./podcasts:/podcasts
      # The metadata directory can be stored anywhere on your computer
      - ./metadata:/metadata
      # The config directory needs to be on the same physical machine
      # you are running ABS on
      - ./config:/config
      - /path/to/generated/ffmpeg:/usr/bin/ffmpeg:ro
      - /path/to/generated/ffprobe:/usr/bin/ffprobe:ro
    restart: unless-stopped
    # You can use the following user directive to run the ABS
    # docker container as a specific user. You will need to change
    # the UID and GID to the correct values for your user.
    # user: 1000:1000
  1. start your abs as normal

Notes

I've added both binaries with the read only flag (:ro) in order to not overwrite the binaries from inside the container for whatever reason.

If and when ABS updates the version of ffmpeg used, you also need to generate a new version of ffprobe, which you can do by changing the targeted version in the Dockerfile

FROM ubuntu:22.04 AS builder
# Install essential tools and dependencies (excluding libfdk-aac-dev)
RUN --mount=type=cache,target=/var/cache/apt --mount=type=cache,target=/var/lib/apt/lists \
apt-get update && \
apt-get install -y --no-install-recommends ca-certificates wget sed git && \
sed -i 's/main$/main universe multiverse/' /etc/apt/sources.list && \
apt-get update && \
apt-get install -y --no-install-recommends \
autoconf \
automake \
build-essential \
libbz2-dev \
libmp3lame-dev \
libtool \
pkg-config \
tar \
yasm \
nasm \
libwebp-dev \
zlib1g-dev
# Build fdk-aac from source
RUN git clone --depth 1 https://github.com/mstorsjo/fdk-aac /usr/src/fdk-aac && \
cd /usr/src/fdk-aac && \
autoreconf -fiv && \
./configure --prefix=/usr/local/ffmpeg_build --disable-shared && \
make -j$(nproc) && \
make install && \
cd / && \
rm -rf /usr/src/fdk-aac
# Download and build ffmpeg
ARG FFMPEG_VERSION=7.1.1
RUN wget https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.bz2 && \
tar xjvf ffmpeg-${FFMPEG_VERSION}.tar.bz2 && \
rm ffmpeg-${FFMPEG_VERSION}.tar.bz2 && \
cd ffmpeg-${FFMPEG_VERSION} && \
export PKG_CONFIG_PATH="/usr/local/ffmpeg_build/lib/pkgconfig:${PKG_CONFIG_PATH:-}" && \
./configure \
--prefix=/usr/local/ffmpeg_build \
--pkg-config-flags="--static" \
--extra-cflags="-I/usr/local/ffmpeg_build/include" \
--extra-ldflags="-L/usr/local/ffmpeg_build/lib" \
--disable-shared \
--enable-static \
--disable-debug \
--disable-doc \
--enable-bzlib \
--enable-libmp3lame \
--enable-nonfree \
--enable-libfdk_aac \
--enable-decoder=libfdk_aac \
--enable-encoder=libfdk_aac \
--disable-encoder=aac \
--disable-encoder=aac_mf \
--disable-decoder=aac \
--disable-decoder=aac_fixed \
--disable-decoder=aac_latm \
--enable-zlib \
--enable-libwebp \
--extra-ldflags="-static -L/usr/local/ffmpeg_build/lib" && \
make -j$(nproc) && \
cp ffmpeg /ffmpeg && \
cp ffprobe /ffprobe && \
cd / && \
rm -rf ffmpeg-${FFMPEG_VERSION} /usr/local/ffmpeg_build
# Create a minimal image with just the binaries
FROM alpine:3.19 AS final
COPY --from=builder /ffmpeg /ffmpeg
COPY --from=builder /ffprobe /ffprobe
# Add a default command so container can be created
CMD ["/bin/sh"]
#!/bin/bash
set -e
# Build the Docker image
echo "Building the Docker image..."
docker build -t ffmpeg-builder .
# Create a temporary container from the image
echo "Creating a temporary container..."
CONTAINER_ID=$(docker create ffmpeg-builder)
# Extract the binaries to the current directory
echo "Extracting ffmpeg and ffprobe binaries to current directory..."
docker cp $CONTAINER_ID:/ffmpeg ./ffmpeg
docker cp $CONTAINER_ID:/ffprobe ./ffprobe
# Make the binaries executable
chmod +x ./ffmpeg ./ffprobe
# Clean up the temporary container
echo "Cleaning up..."
docker rm $CONTAINER_ID
echo "Done! ffmpeg and ffprobe binaries are now in the current directory."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment