소스 검색

Removing ffmpeg build stage

penta 1 개월 전
부모
커밋
dec5523079
1개의 변경된 파일과 169개의 추가작업 그리고 109개의 파일을 삭제
  1. 169 109
      Dockerfile

+ 169 - 109
Dockerfile

@@ -9,88 +9,31 @@ ARG NVIDIA_DRIVER_BRANCH=580
 ARG NVIDIA_DRIVER_VERSION=580.173.02
 ARG NVIDIA_DRIVER_PACKAGE_VERSION=580.173.02-1ubuntu1
 
+# Sunshine version currently used by the image.
 ARG SUNSHINE_REF=f0ea536
 ARG SUNSHINE_VERSION=v2026.914.233613
+
+# IMPORTANT:
+# This build-deps release contains FFmpeg 9 with dynamic NVENC API selection.
+# It can select SDK 11/12/13 at runtime depending on the installed NVIDIA
+# driver, which is required for our 580.x driver.
 ARG BUILD_DEPS_VERSION=v2026.910.121303
 
 
-# ============================================================================
-# Build du FFmpeg utilisé par Sunshine
+# =============================================================================
+# Build Sunshine
 #
-# build-deps gère désormais lui-même les différentes versions de
-# nv-codec-headers ainsi que la sélection dynamique de l'API NVENC.
-# Ne pas forcer manuellement une version de nv-codec-headers ici.
-# ============================================================================
-FROM docker.io/library/ubuntu:24.04 AS ffmpeg-build
-
-ARG BUILD_DEPS_VERSION
-
-ENV DEBIAN_FRONTEND=noninteractive
-
-RUN apt-get update && \
-    apt-get install -y --no-install-recommends \
-        autoconf \
-        automake \
-        build-essential \
-        ca-certificates \
-        cmake \
-        git \
-        libass-dev \
-        libfreetype6-dev \
-        libgnutls28-dev \
-        libmp3lame-dev \
-        libnuma-dev \
-        libopus-dev \
-        libsdl2-dev \
-        libtool \
-        libvorbis-dev \
-        libxcb1-dev \
-        libxcb-shm0-dev \
-        libxcb-xfixes0-dev \
-        libx11-xcb-dev \
-        libxcb-dri3-dev \
-        make \
-        meson \
-        nasm \
-        ninja-build \
-        pkg-config \
-        texinfo \
-        wget \
-        zlib1g-dev && \
-    rm -rf /var/lib/apt/lists/*
+# FFmpeg is NOT compiled here.
+#
+# Sunshine's CMake downloads the prebuilt FFmpeg archive published by the
+# selected build-deps release.
+# =============================================================================
 
-RUN git clone \
-        --branch "${BUILD_DEPS_VERSION}" \
-        --depth 1 \
-        --recurse-submodules \
-        https://github.com/LizardByte/build-deps.git \
-        /src/build-deps
-
-RUN cmake \
-        -S /src/build-deps \
-        -B /src/build-deps/build \
-        -G "Unix Makefiles" \
-        -DCMAKE_BUILD_TYPE=Release \
-        -DCMAKE_INSTALL_PREFIX=/opt/build-deps \
-        -DBUILD_ALL=OFF \
-        -DBUILD_FFMPEG=ON \
-        -DBUILD_FFMPEG_ALL_PATCHES=ON \
-        -DBUILD_FFMPEG_NV_CODEC_HEADERS=ON \
-        -DBUILD_FFMPEG_NV_CODEC_HEADERS_PATCHES=ON \
-        -DBUILD_FFMPEG_CUDA_LLVM=OFF \
-        -DBUILD_TESTS=OFF \
-        -DBUILD_DOCS=OFF && \
-    cmake --build /src/build-deps/build --parallel "$(nproc)" && \
-    cmake --install /src/build-deps/build
-
-
-# ============================================================================
-# Build de Sunshine avec notre FFmpeg
-# ============================================================================
 FROM docker.io/nvidia/cuda:12.9.2-devel-ubuntu24.04 AS sunshine-build
 
 ARG SUNSHINE_REF
 ARG SUNSHINE_VERSION
+ARG BUILD_DEPS_VERSION
 
 ENV DEBIAN_FRONTEND=noninteractive
 
@@ -100,6 +43,11 @@ RUN apt-get update && \
         git && \
     rm -rf /var/lib/apt/lists/*
 
+
+# =============================================================================
+# Sunshine sources
+# =============================================================================
+
 RUN git clone \
         --filter=blob:none \
         https://github.com/LizardByte/Sunshine.git \
@@ -108,16 +56,102 @@ RUN git clone \
     git checkout "${SUNSHINE_REF}" && \
     git submodule update --init --recursive --depth 1
 
-# Installation des dépendances de compilation de Sunshine.
-# --skip-cuda désactive NVFBC/CUDA dans Sunshine, PAS NVENC via FFmpeg.
+
+# =============================================================================
+# Override Sunshine's build-deps revision
+#
+# f0ea536 normally points to an older build-deps release.
+#
+# Force v2026.910.121303 so Sunshine's ffmpeg.cmake downloads:
+#
+#   https://github.com/LizardByte/build-deps/releases/download/
+#   v2026.910.121303/Linux-x86_64-ffmpeg.tar.gz
+#
+# That FFmpeg build includes dynamic NVENC API selection for SDK 11/12/13.
+# =============================================================================
+
+RUN set -eux; \
+    git -C /src/sunshine/third-party/build-deps fetch \
+        --depth 1 \
+        --force \
+        origin \
+        "refs/tags/${BUILD_DEPS_VERSION}:refs/tags/${BUILD_DEPS_VERSION}"; \
+    git -C /src/sunshine/third-party/build-deps checkout \
+        --detach \
+        "${BUILD_DEPS_VERSION}"; \
+    ACTUAL_BUILD_DEPS_VERSION="$( \
+        git -C /src/sunshine/third-party/build-deps \
+        describe --tags --exact-match \
+    )"; \
+    echo "Selected build-deps: ${ACTUAL_BUILD_DEPS_VERSION}"; \
+    test "${ACTUAL_BUILD_DEPS_VERSION}" = "${BUILD_DEPS_VERSION}"
+
+
+# =============================================================================
+# Sunshine f0ea536 -> FFmpeg 9 NVENC preset compatibility
+#
+# f0ea536 still converts:
+#
+#   nvenc_preset=1 -> numeric preset 12
+#
+# FFmpeg 9 uses a different internal numeric range (P1..P7 = 3..9).
+#
+# Current Sunshine solves this by passing the symbolic FFmpeg preset ("p1",
+# "p2", ... "p7") instead of relying on FFmpeg's numeric enum.
+#
+# Apply the minimal equivalent backport here.
+#
+# The grep checks intentionally make the build fail if the source no longer
+# matches what we expect.
+# =============================================================================
+
+RUN set -eux; \
+    grep -Fq \
+        '      int preset;' \
+        /src/sunshine/src/config.h; \
+    grep -Fq \
+        '    video.nv_legacy.preset = video.nv.quality_preset + 11;' \
+        /src/sunshine/src/config.cpp; \
+    sed -i \
+        's/      int preset;/      std::string preset;/' \
+        /src/sunshine/src/config.h; \
+    sed -i \
+        's/video\.nv_legacy\.preset = video\.nv\.quality_preset + 11;/video.nv_legacy.preset = std::format("p{}", video.nv.quality_preset);/' \
+        /src/sunshine/src/config.cpp; \
+    grep -Fq \
+        '      std::string preset;' \
+        /src/sunshine/src/config.h; \
+    grep -Fq \
+        '    video.nv_legacy.preset = std::format("p{}", video.nv.quality_preset);' \
+        /src/sunshine/src/config.cpp; \
+    ! grep -Fq \
+        'video.nv_legacy.preset = video.nv.quality_preset + 11;' \
+        /src/sunshine/src/config.cpp; \
+    echo "FFmpeg 9 NVENC preset compatibility patch: OK"
+
+
+# =============================================================================
+# Sunshine build dependencies
+#
+# The CUDA toolkit already exists in the nvidia/cuda base image.
+# --skip-cuda prevents linux_build.sh from downloading/installing another one.
+#
+# Do NOT disable CUDA during the CMake step below: we still use CUDA/NvFBC.
+# =============================================================================
+
 RUN cd /src/sunshine && \
     ./scripts/linux_build.sh \
         --sudo-off \
         --skip-cuda \
         --step=deps
 
-# Remplacement du FFmpeg précompilé de LizardByte par le nôtre.
-COPY --from=ffmpeg-build /opt/build-deps/ffmpeg /tmp/custom-ffmpeg
+
+# =============================================================================
+# Configure Sunshine
+#
+# During this step Sunshine detects BUILD_DEPS_VERSION and downloads the
+# corresponding PREBUILT FFmpeg archive.
+# =============================================================================
 
 RUN cd /src/sunshine && \
     BRANCH=master \
@@ -127,11 +161,41 @@ RUN cd /src/sunshine && \
         --sudo-off \
         --step=cmake
 
-RUN rm -rf /src/sunshine/build/_deps/ffmpeg && \
-    mkdir -p /src/sunshine/build/_deps/ffmpeg && \
-    cp -a \
-        /tmp/custom-ffmpeg/. \
-        /src/sunshine/build/_deps/ffmpeg/
+
+# =============================================================================
+# Fail-fast validation
+#
+# Before spending time compiling Sunshine, make sure:
+#
+# 1. CMake really used the requested build-deps tag.
+# 2. The prebuilt FFmpeg archive exists.
+# 3. libavcodec contains the multi-SDK NVENC implementations introduced by
+#    the dynamic NVENC API patch.
+#
+# Presence of 11.0 + 12.0 + 13.0 implementations is what we want for
+# compatibility with the NVIDIA 580 driver.
+# =============================================================================
+
+RUN set -eux; \
+    ACTUAL_BUILD_DEPS_VERSION="$( \
+        git -C /src/sunshine/third-party/build-deps \
+        describe --tags --exact-match \
+    )"; \
+    test "${ACTUAL_BUILD_DEPS_VERSION}" = "${BUILD_DEPS_VERSION}"; \
+    FFMPEG_LIB="/src/sunshine/build/_deps/ffmpeg/lib/libavcodec.a"; \
+    test -s "${FFMPEG_LIB}"; \
+    nm -g --defined-only "${FFMPEG_LIB}" \
+        | grep -F 'ff_nvenc_encode_init_1100' >/dev/null; \
+    nm -g --defined-only "${FFMPEG_LIB}" \
+        | grep -F 'ff_nvenc_encode_init_1200' >/dev/null; \
+    nm -g --defined-only "${FFMPEG_LIB}" \
+        | grep -F 'ff_nvenc_encode_init_1300' >/dev/null; \
+    echo "Prebuilt FFmpeg dynamic NVENC API support: OK"
+
+
+# =============================================================================
+# Build + package Sunshine
+# =============================================================================
 
 RUN cd /src/sunshine && \
     ./scripts/linux_build.sh \
@@ -140,7 +204,9 @@ RUN cd /src/sunshine && \
     ./scripts/linux_build.sh \
         --sudo-off \
         --step=package && \
-    cp /src/sunshine/build/cpack_artifacts/Sunshine.deb /sunshine.deb
+    cp \
+        /src/sunshine/build/cpack_artifacts/Sunshine.deb \
+        /sunshine.deb
 
 
 # =============================================================================
@@ -479,19 +545,21 @@ RUN dpkg --add-architecture i386 \
 # =============================================================================
 
 RUN install -d -m 0755 /etc/apt/keyrings \
-    && curl -fsSL https://packages.mozilla.org/apt/repo-signing-key.gpg \
-       -o /etc/apt/keyrings/packages.mozilla.org.asc \
-    && echo "deb [signed-by=/etc/apt/keyrings/packages.mozilla.org.asc] https://packages.mozilla.org/apt mozilla main" \
-       > /etc/apt/sources.list.d/mozilla.list \
+    && curl -fsSL \
+        https://packages.mozilla.org/apt/repo-signing-key.gpg \
+        -o /etc/apt/keyrings/packages.mozilla.org.asc \
+    && echo \
+        "deb [signed-by=/etc/apt/keyrings/packages.mozilla.org.asc] https://packages.mozilla.org/apt mozilla main" \
+        > /etc/apt/sources.list.d/mozilla.list \
     && printf '%s\n' \
-       'Package: *' \
-       'Pin: origin packages.mozilla.org' \
-       'Pin-Priority: 1000' \
-       > /etc/apt/preferences.d/mozilla \
+        'Package: *' \
+        'Pin: origin packages.mozilla.org' \
+        'Pin-Priority: 1000' \
+        > /etc/apt/preferences.d/mozilla \
     && apt-get update \
     && apt-get install --no-install-recommends -y \
-       firefox \
-       firefox-l10n-fr \
+        firefox \
+        firefox-l10n-fr \
     && apt-get clean
 
 
@@ -539,6 +607,7 @@ RUN dpkg --add-architecture i386 \
         /var/lib/apt/lists/* \
         /var/cache/apt/*
 
+
 # Keep APT package indexes available for Steam's dependency checker.
 RUN apt-get update \
     && apt-get clean
@@ -578,24 +647,15 @@ RUN chown -R \
 # Sanity checks
 # =============================================================================
 
-RUN command -v \
-        steam \
-    && command -v \
-        nvidia-xconfig \
-    && command -v \
-        supervisord \
-    && command -v \
-        pipewire \
-    && command -v \
-        wireplumber \
-    && command -v \
-        Xorg \
-    && command -v \
-        xfce4-session \
-    && test -x \
-        /etc/sunshine-entrypoint.sh \
-    && test -x \
-        /etc/desktop-entrypoint.sh
+RUN command -v steam \
+    && command -v nvidia-xconfig \
+    && command -v supervisord \
+    && command -v pipewire \
+    && command -v wireplumber \
+    && command -v Xorg \
+    && command -v xfce4-session \
+    && test -x /etc/sunshine-entrypoint.sh \
+    && test -x /etc/desktop-entrypoint.sh
 
 
 # =============================================================================