# Cross-compilation image for ARMv7 based on Debian 12 # Uses multiarch to install ARMv7 libraries on x86_64 host 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}" # Add armhf architecture RUN dpkg --add-architecture armhf # Install cross-compiler and native build tools RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ pkg-config \ cmake \ nasm \ git \ libclang-dev \ llvm \ protobuf-compiler \ mold \ meson \ ninja-build \ wget \ gcc-arm-linux-gnueabihf \ g++-arm-linux-gnueabihf \ libc6-dev-armhf-cross \ && rm -rf /var/lib/apt/lists/* # Install ARMv7 development libraries (without system ffmpeg) RUN apt-get update && apt-get install -y --no-install-recommends \ libssl-dev:armhf \ libasound2-dev:armhf \ libv4l-dev:armhf \ libudev-dev:armhf \ zlib1g-dev:armhf \ libjpeg62-turbo-dev:armhf \ libyuv-dev:armhf \ libx264-dev:armhf \ libx265-dev:armhf \ libvpx-dev:armhf \ libopus-dev:armhf \ libva-dev:armhf \ libdrm-dev:armhf \ libx11-dev:armhf \ libxcb1-dev:armhf \ libxau-dev:armhf \ libxdmcp-dev:armhf \ && rm -rf /var/lib/apt/lists/* # Download and build FFmpeg with RKMPP support 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 \ # Build RKMPP && mkdir -p rkmpp/build && cd rkmpp/build \ && cmake .. \ -DCMAKE_SYSTEM_NAME=Linux \ -DCMAKE_SYSTEM_PROCESSOR=arm \ -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc \ -DCMAKE_CXX_COMPILER=arm-linux-gnueabihf-g++ \ -DCMAKE_INSTALL_PREFIX=/usr/arm-linux-gnueabihf \ -DCMAKE_BUILD_TYPE=Release \ -DBUILD_SHARED_LIBS=ON \ -DBUILD_TEST=OFF \ && make -j$(nproc) \ && make install \ && cd ../.. \ # Build RKRGA - create cross file for meson && echo '[binaries]' > /tmp/armhf-cross.txt \ && echo "c = 'arm-linux-gnueabihf-gcc'" >> /tmp/armhf-cross.txt \ && echo "cpp = 'arm-linux-gnueabihf-g++'" >> /tmp/armhf-cross.txt \ && echo "ar = 'arm-linux-gnueabihf-ar'" >> /tmp/armhf-cross.txt \ && echo "strip = 'arm-linux-gnueabihf-strip'" >> /tmp/armhf-cross.txt \ && echo "pkgconfig = 'pkg-config'" >> /tmp/armhf-cross.txt \ && echo '[host_machine]' >> /tmp/armhf-cross.txt \ && echo "system = 'linux'" >> /tmp/armhf-cross.txt \ && echo "cpu_family = 'arm'" >> /tmp/armhf-cross.txt \ && echo "cpu = 'armv7'" >> /tmp/armhf-cross.txt \ && echo "endian = 'little'" >> /tmp/armhf-cross.txt \ && cd rkrga \ && meson setup build --prefix=/usr/arm-linux-gnueabihf --libdir=lib \ --cross-file=/tmp/armhf-cross.txt \ --buildtype=release \ -Dcpp_args=-fpermissive \ -Dlibdrm=false \ -Dlibrga_demo=false \ && ninja -C build \ && ninja -C build install \ && cd .. \ # Create pkg-config wrapper for cross-compilation && echo '#!/bin/sh' > /tmp/armhf-pkg-config \ && echo 'export PKG_CONFIG_LIBDIR=/usr/arm-linux-gnueabihf/lib/pkgconfig:/usr/lib/arm-linux-gnueabihf/pkgconfig' >> /tmp/armhf-pkg-config \ && echo 'export PKG_CONFIG_PATH=""' >> /tmp/armhf-pkg-config \ && echo 'export PKG_CONFIG_SYSROOT_DIR=""' >> /tmp/armhf-pkg-config \ && echo 'exec pkg-config "$@"' >> /tmp/armhf-pkg-config \ && chmod +x /tmp/armhf-pkg-config \ # Build FFmpeg with RKMPP (minimal build for encoding only) && cd ffmpeg-rockchip \ && ./configure \ --prefix=/usr/arm-linux-gnueabihf \ --cross-prefix=arm-linux-gnueabihf- \ --arch=arm \ --target-os=linux \ --enable-cross-compile \ --pkg-config=/tmp/armhf-pkg-config \ --enable-gpl \ --enable-version3 \ --enable-shared \ --disable-static \ # Hardware acceleration --enable-libdrm \ --enable-rkmpp \ --enable-rkrga \ --enable-vaapi \ --enable-v4l2-m2m \ # 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_rkmpp \ --enable-encoder=hevc_rkmpp \ --enable-encoder=h264_v4l2m2m \ --enable-encoder=hevc_v4l2m2m \ --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 /tmp/armhf-cross.txt /tmp/armhf-pkg-config # Add Rust target RUN rustup target add armv7-unknown-linux-gnueabihf # Create symlink for mold to work with cross-compiler RUN ln -s /usr/bin/mold /usr/bin/arm-linux-gnueabihf-ld.mold # Configure environment for cross-compilation # Use PKG_CONFIG_LIBDIR to completely replace default search paths # This ensures we use our custom-built FFmpeg instead of system FFmpeg ENV CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc \ CC_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc \ CXX_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-g++ \ AR_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-ar \ PKG_CONFIG_LIBDIR=/usr/arm-linux-gnueabihf/lib/pkgconfig:/usr/lib/arm-linux-gnueabihf/pkgconfig \ PKG_CONFIG_PATH="" \ PKG_CONFIG_ALLOW_CROSS=1 \ RUSTFLAGS="-C linker=arm-linux-gnueabihf-gcc -C link-arg=-fuse-ld=mold"