# This image forms the base for the final image and is not meant to be used directly
# NOTE that the dev add-on is also based on this base image
-FROM python:3.13-alpine3.21
+FROM python:3.13-slim-bookworm AS ffmpeg-builder
+# Enable non-free and contrib repositories for FDK-AAC and other codecs
+RUN echo "deb http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \
+ echo "deb http://deb.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
+ echo "deb http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list
+
+# Install build dependencies for FFmpeg
+RUN apt-get update && apt-get install -y --no-install-recommends \
+ build-essential \
+ pkg-config \
+ yasm \
+ nasm \
+ git \
+ wget \
+ ca-certificates \
+ # Audio codec libraries
+ libfdk-aac-dev \
+ libmp3lame-dev \
+ libopus-dev \
+ libvorbis-dev \
+ libsoxr-dev \
+ libspeex-dev \
+ libtwolame-dev \
+ libvo-amrwbenc-dev \
+ libopencore-amrnb-dev \
+ libopencore-amrwb-dev \
+ libshine-dev \
+ # Additional audio processing
+ libbluray-dev \
+ libxml2-dev \
+ # SSL/TLS support for HTTPS
+ libssl-dev \
+ && rm -rf /var/lib/apt/lists/*
+
+# Build FFmpeg 7.1.2 from source with comprehensive audio codec support
+ARG FFMPEG_VERSION=7.1.2
+RUN set -x \
+ && wget -q "https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.xz" -O /tmp/ffmpeg.tar.xz \
+ && tar -xJf /tmp/ffmpeg.tar.xz -C /tmp \
+ && cd /tmp/ffmpeg-${FFMPEG_VERSION} \
+ && ./configure \
+ --prefix=/usr/local \
+ --enable-gpl \
+ --enable-nonfree \
+ --enable-version3 \
+ # Audio codecs (comprehensive support)
+ --enable-libfdk-aac \
+ --enable-libmp3lame \
+ --enable-libopus \
+ --enable-libvorbis \
+ --enable-libspeex \
+ --enable-libtwolame \
+ --enable-libshine \
+ --enable-libopencore-amrnb \
+ --enable-libopencore-amrwb \
+ --enable-libvo-amrwbenc \
+ # Audio filters and resampling
+ --enable-libsoxr \
+ # SSL/TLS support for HTTPS
+ --enable-openssl \
+ # Protocols needed for streaming
+ --enable-protocol=file \
+ --enable-protocol=http \
+ --enable-protocol=https \
+ --enable-protocol=tcp \
+ --enable-protocol=udp \
+ --enable-protocol=rtp \
+ # Optimizations
+ --enable-small \
+ --enable-runtime-cpudetect \
+ # Disable unnecessary features for smaller build
+ --disable-doc \
+ --disable-htmlpages \
+ --disable-manpages \
+ --disable-podpages \
+ --disable-txtpages \
+ --disable-debug \
+ --disable-static \
+ --enable-shared \
+ && make -j$(nproc) \
+ && make install \
+ && strip /usr/local/bin/ffmpeg /usr/local/bin/ffprobe \
+ && rm -rf /tmp/ffmpeg*
+
+##################################################################################################
+
+FROM python:3.13-slim-bookworm
+
+# Enable non-free and contrib repositories for codec libraries
+RUN echo "deb http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \
+ echo "deb http://deb.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
+ echo "deb http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list
+
+# Install runtime dependencies
RUN set -x \
- && apk add --no-cache \
+ && apt-get update \
+ && apt-get install -y --no-install-recommends \
ca-certificates \
- jemalloc \
+ libjemalloc2 \
tzdata \
- dnscache \
# cifs utils and libnfs are needed for smb and nfs support (file provider)
cifs-utils \
- libnfs \
- # openssl-dev is needed for airplay
- openssl-dev \
- # install snapcast so the snapcast provider can run the builtin snapcast server
- snapcast \
- # build tools and llvm support needed for librosa/numba/llvmlite (smartfades)
- build-base \
- llvm15-dev \
+ libnfs13 \
+ # openssl is needed for airplay
+ openssl \
+ libssl-dev \
# libsndfile needed for librosa audio file support (smartfades)
- libsndfile-dev
+ libsndfile1 \
+ # snapcast server and client for snapcast provider
+ snapserver \
+ snapclient \
+ # Audio codec runtime libraries (needed for FFmpeg)
+ libfdk-aac2 \
+ libmp3lame0 \
+ libopus0 \
+ libvorbis0a \
+ libvorbisenc2 \
+ libsoxr0 \
+ libspeex1 \
+ libtwolame0 \
+ libshine3 \
+ libopencore-amrnb0 \
+ libopencore-amrwb0 \
+ libvo-amrwbenc0 \
+ libbluray2 \
+ libxml2 \
+ && apt-get clean \
+ && rm -rf /var/lib/apt/lists/*
+
+# Copy FFmpeg binaries and libraries from builder stage
+COPY --from=ffmpeg-builder /usr/local/bin/ffmpeg /usr/local/bin/
+COPY --from=ffmpeg-builder /usr/local/bin/ffprobe /usr/local/bin/
+COPY --from=ffmpeg-builder /usr/local/lib/libav*.so* /usr/local/lib/
+COPY --from=ffmpeg-builder /usr/local/lib/libsw*.so* /usr/local/lib/
+COPY --from=ffmpeg-builder /usr/local/lib/libpostproc.so* /usr/local/lib/
-# Get static ffmpeg builds from https://hub.docker.com/r/mwader/static-ffmpeg/
-COPY --from=mwader/static-ffmpeg:7.1.1 /ffmpeg /usr/local/bin/
-COPY --from=mwader/static-ffmpeg:7.1.1 /ffprobe /usr/local/bin/
+# Update shared library cache and verify FFmpeg
+RUN ldconfig && ffmpeg -version && ffprobe -version
# Copy widevine client files to container
RUN mkdir -p /usr/local/bin/widevine_cdm
COPY widevine_cdm/* /usr/local/bin/widevine_cdm/
# JEMalloc for more efficient memory management
-ENV LD_PRELOAD="/usr/lib/libjemalloc.so.2"
-
-# Set LLVM config for llvmlite/numba
-ENV LLVM_CONFIG="/usr/bin/llvm-config-15"
+# Dynamically set the correct path based on architecture
+ARG TARGETARCH
+RUN set -x \
+ && if [ "$TARGETARCH" = "arm64" ]; then \
+ echo "/usr/lib/aarch64-linux-gnu/libjemalloc.so.2" > /etc/ld.so.preload; \
+ else \
+ echo "/usr/lib/x86_64-linux-gnu/libjemalloc.so.2" > /etc/ld.so.preload; \
+ fi
# we need to set (very permissive) permissions to the workdir
# and /tmp to allow running the container as non-root