Files
One-KVM/build/cross/Dockerfile.x86_64
mofeng-git e670f1ffd1 refactor: 升级依赖版本并优化构建系统
- 升级核心依赖 (axum 0.8, tower-http 0.6, alsa 0.11 等)
- 简化交叉编译配置,切换至 Debian 11 提高兼容性
- 新增 Debian 包打包支持 (debuerreotype 模板)
- 移除独立的 mjpeg 解码器,简化视频模块
- 静态链接 libx264/libx265/libopus 到二进制
2026-01-10 10:59:00 +08:00

211 lines
6.4 KiB
Docker

# Cross-compilation image for x86_64 based on Debian 11
# Build on Debian 11 (GLIBC 2.31) for maximum runtime compatibility
FROM debian:11
# Set Rustup mirrors (Aliyun)
ENV RUSTUP_UPDATE_ROOT=https://mirrors.aliyun.com/rustup/rustup \
RUSTUP_DIST_SERVER=https://mirrors.aliyun.com/rustup
# Install Rust toolchain
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
ca-certificates \
&& curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable \
&& rm -rf /var/lib/apt/lists/*
ENV PATH="/root/.cargo/bin:${PATH}"
# Install build dependencies
# Note: libyuv, libvpx, libx264, libx265, libopus are built from source below for static linking
RUN apt-get update && apt-get install -y --no-install-recommends \
# Build tools
build-essential \
pkg-config \
cmake \
nasm \
yasm \
git \
libclang-dev \
llvm \
wget \
# Autotools for libopus (requires autoreconf)
autoconf \
automake \
libtool \
# Core system libraries
libasound2-dev \
libv4l-dev \
libudev-dev \
zlib1g-dev \
# Note: libjpeg-turbo, libx264, libx265, libopus are built from source below for static linking
libva-dev \
libdrm-dev \
libmfx-dev \
# X11 libraries (for VAAPI)
libx11-dev \
libxcb1-dev \
libxau-dev \
libxdmcp-dev \
&& rm -rf /var/lib/apt/lists/*
# Build static libjpeg-turbo from source (needed by libyuv)
RUN git clone --depth 1 https://github.com/libjpeg-turbo/libjpeg-turbo /tmp/libjpeg-turbo \
&& cd /tmp/libjpeg-turbo \
&& mkdir build && cd build \
&& cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DENABLE_SHARED=OFF -DENABLE_STATIC=ON \
&& make -j$(nproc) \
&& make install \
&& rm -rf /tmp/libjpeg-turbo
# Build static libyuv from source (uses libjpeg-turbo headers)
RUN git clone --depth 1 https://github.com/lemenkov/libyuv /tmp/libyuv \
&& cd /tmp/libyuv \
&& mkdir build && cd build \
&& cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
&& make -j$(nproc) \
&& make install \
&& rm -rf /tmp/libyuv
# Build static libvpx from source
RUN git clone --depth 1 https://github.com/webmproject/libvpx /tmp/libvpx \
&& cd /tmp/libvpx \
&& ./configure \
--enable-static --disable-shared --enable-pic \
--disable-examples --disable-tools --disable-docs \
&& make -j$(nproc) \
&& make install \
&& rm -rf /tmp/libvpx
# Build static libx264 from source
RUN git clone --depth 1 https://code.videolan.org/videolan/x264.git /tmp/x264 \
&& cd /tmp/x264 \
&& ./configure --enable-static --disable-cli \
&& make -j$(nproc) \
&& make install \
&& rm -rf /tmp/x264
# Build static libx265 from source
RUN git clone --depth 1 https://bitbucket.org/multicoreware/x265_git /tmp/x265 \
&& cd /tmp/x265 \
&& cd source \
&& mkdir -p build \
&& cd build \
&& cmake .. -DCMAKE_BUILD_TYPE=Release \
-DENABLE_SHARED=OFF \
-DENABLE_CLI=OFF \
-DBUILD_SHARED_LIBS=OFF \
&& make -j$(nproc) \
&& make install \
&& rm -rf /tmp/x265
# Create pkg-config file for x265 (required by FFmpeg)
# Fix: Added -lstdc++ -lm -ldl -lpthread to Libs for static linking compatibility
RUN mkdir -p /usr/local/lib/pkgconfig && \
cat > /usr/local/lib/pkgconfig/x265.pc <<EOF
prefix=/usr/local
exec_prefix=\${prefix}
libdir=\${exec_prefix}/lib
includedir=\${prefix}/include
Name: x265
Description: H.265/HEVC video encoder
Version: 199
Libs: -L\${libdir} -lx265 -lstdc++ -lm -ldl -lpthread
Cflags: -I\${includedir}
EOF
# Build static libopus from source
RUN git clone --depth 1 https://github.com/xiph/opus /tmp/opus \
&& cd /tmp/opus \
&& ./autogen.sh \
&& ./configure \
--enable-static --disable-shared \
--disable-doc \
&& make -j$(nproc) \
&& make install \
&& rm -rf /tmp/opus
# Download and build FFmpeg with minimal configuration for encoding only
RUN mkdir -p /tmp/ffmpeg-build && cd /tmp/ffmpeg-build \
&& wget -q https://files.mofeng.run/src/image/other/ffmpeg.tar.gz \
&& tar -xzf ffmpeg.tar.gz \
&& cd ffmpeg/ffmpeg-rockchip \
&& ./configure \
--enable-gpl \
--enable-version3 \
--disable-shared \
--enable-static \
--enable-pic \
# Hardware acceleration
--enable-libdrm \
--enable-vaapi \
--enable-libmfx \
# Software encoding libraries
--enable-libx264 \
--enable-libx265 \
--enable-libvpx \
# Disable programs and docs
--disable-programs \
--disable-doc \
--disable-htmlpages \
--disable-manpages \
--disable-podpages \
--disable-txtpages \
# Disable network
--disable-network \
--disable-protocols \
# Disable unused libraries
--disable-avformat \
--disable-swscale \
--disable-swresample \
--disable-avfilter \
--disable-avdevice \
--disable-postproc \
# Disable all decoders
--disable-decoders \
# Disable all encoders, enable only needed ones
--disable-encoders \
--enable-encoder=h264_vaapi \
--enable-encoder=hevc_vaapi \
--enable-encoder=vp8_vaapi \
--enable-encoder=vp9_vaapi \
--enable-encoder=h264_qsv \
--enable-encoder=hevc_qsv \
--enable-encoder=libx264 \
--enable-encoder=libx265 \
--enable-encoder=libvpx_vp8 \
--enable-encoder=libvpx_vp9 \
# Disable muxers/demuxers
--disable-muxers \
--disable-demuxers \
# Disable parsers except needed ones
--disable-parsers \
--enable-parser=h264 \
--enable-parser=hevc \
--enable-parser=vp8 \
--enable-parser=vp9 \
# Disable BSFs except needed ones
--disable-bsfs \
--enable-bsf=h264_mp4toannexb \
--enable-bsf=hevc_mp4toannexb \
# Disable hardware decoding
--disable-hwaccels \
# Disable other unused features
--disable-indevs \
--disable-outdevs \
--disable-filters \
--disable-debug \
&& make -j$(nproc) \
&& make install \
&& cd / \
&& rm -rf /tmp/ffmpeg-build
# Add Rust target
RUN rustup target add x86_64-unknown-linux-gnu
# Configure environment for static linking
ENV PKG_CONFIG_ALLOW_CROSS=1\
FFMPEG_STATIC=1 \
LIBYUV_STATIC=1