@@ -101,6 +101,32 @@ RUN set -x \
101101
102102##################################################################################################
103103
104+ # PyAV wheel builder - builds PyAV against the custom FFmpeg
105+ FROM python:3.13-slim-bookworm AS pyav-builder
106+
107+ RUN apt-get update && apt-get install -y --no-install-recommends \
108+ gcc g++ python3-dev pkg-config && rm -rf /var/lib/apt/lists/*
109+
110+ COPY --from=ffmpeg-builder /usr/local/lib/libav*.so* /usr/local/lib/
111+ COPY --from=ffmpeg-builder /usr/local/lib/libsw*.so* /usr/local/lib/
112+ COPY --from=ffmpeg-builder /usr/local/lib/libpostproc.so* /usr/local/lib/
113+ COPY --from=ffmpeg-builder /usr/local/include/ /usr/local/include/
114+ COPY --from=ffmpeg-builder /usr/local/lib/pkgconfig/ /usr/local/lib/pkgconfig/
115+
116+ RUN ldconfig
117+ ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
118+
119+ # Resolve PyAV version from aioresonate's dependencies and build wheel
120+ RUN PYAV_VERSION=$(pip install --dry-run aioresonate 2>&1 | grep -oP 'av-\K[0-9.]+' | head -1) && \
121+ if [ -z "$PYAV_VERSION" ]; then \
122+ echo "ERROR: Failed to detect PyAV version from aioresonate dependencies" >&2; \
123+ exit 1; \
124+ fi && \
125+ echo "Building PyAV version: ${PYAV_VERSION}" && \
126+ pip wheel --no-binary av av==${PYAV_VERSION} -w /wheels/
127+
128+ ##################################################################################################
129+
104130FROM python:3.13-slim-bookworm
105131
106132# Enable non-free and contrib repositories for codec libraries
@@ -169,8 +195,6 @@ RUN set -x \
169195 # AirPlay receiver dependencies (shairport-sync)
170196 libconfig9 \
171197 libpopt0 \
172- # pkg-config needed for PyAV (for aioresonate) to find system FFmpeg
173- pkg-config \
174198 && apt-get clean \
175199 && rm -rf /var/lib/apt/lists/*
176200
@@ -195,12 +219,8 @@ COPY --from=ffmpeg-builder /usr/local/lib/libav*.so* /usr/local/lib/
195219COPY --from=ffmpeg-builder /usr/local/lib/libsw*.so* /usr/local/lib/
196220COPY --from=ffmpeg-builder /usr/local/lib/libpostproc.so* /usr/local/lib/
197221
198- # Copy FFmpeg headers and pkg-config files needed for PyAV compilation (adds around 2 MB)
199- COPY --from=ffmpeg-builder /usr/local/include/ /usr/local/include/
200- COPY --from=ffmpeg-builder /usr/local/lib/pkgconfig/ /usr/local/lib/pkgconfig/
201-
202- # Set PKG_CONFIG_PATH so pkg-config can find FFmpeg
203- ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
222+ # Copy pre-built PyAV wheel for use by downstream images
223+ COPY --from=pyav-builder /wheels/ /usr/local/share/pyav-wheels/
204224
205225# Update shared library cache and verify FFmpeg
206226RUN ldconfig && ffmpeg -version && ffprobe -version
0 commit comments