Skip to content

Commit 045859a

Browse files
78cursoragent
andcommitted
feat: add h264_nvenc support to static FFmpeg build
Install nv-codec-headers (SDK 11.1.5.3) before FFmpeg so that h264_nvenc is compiled into the static libavcodec. FFmpeg uses dlopen to load libnvidia-encode.so.1 at runtime, so no GPU or CUDA toolkit is needed in the build container. On hosts without an NVIDIA driver tenboxd falls back to libx264 automatically. Pin to nv-codec-headers 11.1.x (not 12.x) because FFmpeg 6.1.1's nvenc.c still references _PL buffer format names that were removed in SDK 12.0; upgrading to 12.x headers causes compile errors. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent ec78932 commit 045859a

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

packaging/build-base/Dockerfile.bullseye

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ ARG OPUS_VERSION=1.5.2
8181
# static archive bit-for-bit reproducible across runs.
8282
ARG LIBYUV_REF=b438739c8b08eba2c562a62ea5961f6215d525ed
8383
ARG FFMPEG_VERSION=6.1.1
84+
# nv-codec-headers: header-only stubs for the NVENC/NVDEC SDK. FFmpeg
85+
# uses dlopen at runtime to load the actual NVIDIA driver libraries
86+
# (libnvidia-encode.so.1), so no GPU or CUDA toolkit is needed at build
87+
# time — only these headers.
88+
# Pin to the SDK 11.1 line: FFmpeg 6.1.x's nvenc.c uses the _PL buffer
89+
# format names (NV_ENC_BUFFER_FORMAT_NV12_PL etc.) which were removed in
90+
# SDK 12.0. Using 12.x headers here causes compile errors against FFmpeg
91+
# 6.1.1. If FFmpeg is ever bumped to 7.x this can be updated to 12.x.
92+
ARG NV_CODEC_HEADERS_VERSION=11.1.5.3
8493
ARG CURL_VERSION=8.10.1
8594
# OpenSSL 3.0 is the LTS line (security support through 2026-09).
8695
# Static-linking it means the deb no longer needs libssl3/libssl3t64 in
@@ -152,8 +161,22 @@ RUN git clone https://chromium.googlesource.com/libyuv/libyuv \
152161
&& cmake --build libyuv/build --target install \
153162
&& rm -rf libyuv
154163

164+
# nv-codec-headers (MIT): header-only NVENC/NVDEC SDK stubs. Install
165+
# before FFmpeg so ./configure detects ffnvcodec and enables h264_nvenc.
166+
# FFmpeg dlopen()s libnvidia-encode.so.1 at runtime; no GPU or CUDA
167+
# toolkit is required here in the build container.
168+
RUN curl -fsSL "https://github.com/FFmpeg/nv-codec-headers/releases/download/n${NV_CODEC_HEADERS_VERSION}/nv-codec-headers-${NV_CODEC_HEADERS_VERSION}.tar.gz" \
169+
| tar xz \
170+
&& cd nv-codec-headers-${NV_CODEC_HEADERS_VERSION} \
171+
&& make install PREFIX=$DEPS_PREFIX \
172+
&& cd .. && rm -rf nv-codec-headers-${NV_CODEC_HEADERS_VERSION}
173+
155174
# FFmpeg: only the codecs tenbox actually uses (libx264 encode, h264
156-
# decode, libopus encode/decode). everything else off, static-only.
175+
# decode, libopus encode/decode, h264_nvenc hardware encode).
176+
# h264_nvenc is compiled in via ffnvcodec (header-only at build time);
177+
# the actual libnvidia-encode.so.1 is dlopen'd at runtime on hosts that
178+
# have an NVIDIA driver installed. On hosts without a GPU the codec is
179+
# silently unavailable and tenboxd falls back to libx264.
157180
RUN curl -fsSL "https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.xz" \
158181
| tar xJ \
159182
&& cd ffmpeg-${FFMPEG_VERSION} \
@@ -171,7 +194,9 @@ RUN curl -fsSL "https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.xz" \
171194
--enable-muxer=null --enable-demuxer=null \
172195
--enable-encoder=libx264 --enable-decoder=h264 \
173196
--enable-encoder=libopus --enable-decoder=opus \
197+
--enable-encoder=h264_nvenc \
174198
--enable-libx264 --enable-libopus \
199+
--enable-ffnvcodec \
175200
--enable-gpl \
176201
&& make -j"$(nproc)" \
177202
&& make install \

0 commit comments

Comments
 (0)