# Cross-compilation image for x86_64 based on Debian 12 # Matches the runtime environment exactly FROM debian:12 # 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 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 \ mold \ wget \ # Core system libraries libasound2-dev \ libv4l-dev \ libudev-dev \ zlib1g-dev \ # Note: libjpeg-turbo is built from source below for static linking # Video codec libraries (dynamic, for software fallback) libx264-dev \ libx265-dev \ # Audio codec libopus-dev \ # Hardware acceleration 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 \ && cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ -DCMAKE_INSTALL_PREFIX=/opt/one-kvm-libs/x86_64-linux-gnu \ -DENABLE_SHARED=OFF -DENABLE_STATIC=ON \ && cmake --build build -j$(nproc) \ && cmake --install build \ && 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 \ -DCMAKE_PREFIX_PATH=/opt/one-kvm-libs/x86_64-linux-gnu \ -DCMAKE_INSTALL_PREFIX=/opt/one-kvm-libs/x86_64-linux-gnu \ && make -j$(nproc) \ && mkdir -p /opt/one-kvm-libs/x86_64-linux-gnu/lib \ && cp libyuv.a /opt/one-kvm-libs/x86_64-linux-gnu/lib/ \ && cp -r ../include /opt/one-kvm-libs/x86_64-linux-gnu/ \ && 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 --prefix=/opt/one-kvm-libs/x86_64-linux-gnu \ --enable-static --disable-shared --enable-pic \ --disable-examples --disable-tools --disable-docs \ && make -j$(nproc) \ && make install \ && rm -rf /tmp/libvpx # 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 \ && export PKG_CONFIG_PATH="/opt/one-kvm-libs/x86_64-linux-gnu/lib/pkgconfig:$PKG_CONFIG_PATH" \ && ./configure \ --prefix=/opt/one-kvm-libs/x86_64-linux-gnu \ --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 # Copy entrypoint script COPY build/cross/entrypoint.sh /usr/local/bin/cross-entrypoint.sh RUN chmod +x /usr/local/bin/cross-entrypoint.sh # Configure environment for static linking ENV RUSTFLAGS="-C link-arg=-fuse-ld=mold" \ PKG_CONFIG_PATH="/opt/one-kvm-libs/x86_64-linux-gnu/lib/pkgconfig" \ LIBRARY_PATH="/opt/one-kvm-libs/x86_64-linux-gnu/lib" \ CPATH="/opt/one-kvm-libs/x86_64-linux-gnu/include" \ FFMPEG_STATIC=1 \ LIBYUV_STATIC=1 ENTRYPOINT ["/usr/local/bin/cross-entrypoint.sh"]