mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-06-14 03:32:00 +08:00
293 lines
9.9 KiB
Docker
293 lines
9.9 KiB
Docker
# Cross-compilation image for x86_64 based on Debian 11
|
|
# Build on Debian 11 (GLIBC 2.31) for maximum runtime compatibility
|
|
|
|
ARG DEBIAN_IMAGE=debian:11
|
|
FROM ${DEBIAN_IMAGE}
|
|
|
|
ARG CHINAMIRRO=0
|
|
ARG GH_PROXY=https://gh-proxy.com/
|
|
ARG RUSTUP_DIST_SERVER_CN=https://rsproxy.cn
|
|
ARG RUSTUP_UPDATE_ROOT_CN=https://rsproxy.cn/rustup
|
|
ARG CARGO_INDEX_CN=https://rsproxy.cn/crates.io-index
|
|
ARG CARGO_REGISTRY_CN=sparse+https://rsproxy.cn/index/
|
|
ARG LIBJPEG_TURBO_VERSION=3.1.4.1
|
|
ARG LIBYUV_REV=957f295ea946cbbd13fcfc46e7066f2efa801233
|
|
ARG LIBVPX_VERSION=1.16.0
|
|
ARG X265_VERSION=3.4
|
|
ARG OPUS_VERSION=1.5.2
|
|
ARG FFMPEG_ROCKCHIP_REV=40c412daccf08164493da0de990eb99a8948116b
|
|
|
|
# Optionally use China mirrors for builds in China.
|
|
RUN if [ "$CHINAMIRRO" = "1" ]; then \
|
|
sed -i -E \
|
|
-e 's|http://deb.debian.org/debian([[:space:]])|http://mirrors.tuna.tsinghua.edu.cn/debian\1|g' \
|
|
/etc/apt/sources.list; \
|
|
fi
|
|
|
|
# Install Rust toolchain
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
curl \
|
|
ca-certificates \
|
|
&& if [ "$CHINAMIRRO" = "1" ]; then \
|
|
export RUSTUP_DIST_SERVER=${RUSTUP_DIST_SERVER_CN}; \
|
|
export RUSTUP_UPDATE_ROOT=${RUSTUP_UPDATE_ROOT_CN}; \
|
|
fi \
|
|
&& curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable \
|
|
&& if [ "$CHINAMIRRO" = "1" ]; then \
|
|
mkdir -p /root/.cargo; \
|
|
printf '%s\n' \
|
|
'[source.crates-io]' \
|
|
"replace-with = 'rsproxy-sparse'" \
|
|
'[source.rsproxy]' \
|
|
"registry = '${CARGO_INDEX_CN}'" \
|
|
'[source.rsproxy-sparse]' \
|
|
"registry = '${CARGO_REGISTRY_CN}'" \
|
|
'[registries.rsproxy]' \
|
|
"index = '${CARGO_INDEX_CN}'" \
|
|
'[net]' \
|
|
'git-fetch-with-cli = true' \
|
|
> /root/.cargo/config.toml; \
|
|
fi \
|
|
&& 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 \
|
|
xz-utils \
|
|
rsync \
|
|
# Autotools for libopus (requires autoreconf)
|
|
autoconf \
|
|
automake \
|
|
libtool \
|
|
# Core system libraries
|
|
libasound2-dev \
|
|
libv4l-dev \
|
|
libudev-dev \
|
|
linux-libc-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 github_prefix="" \
|
|
&& if [ "$CHINAMIRRO" = "1" ]; then github_prefix="${GH_PROXY%/}/"; fi \
|
|
&& git init /tmp/libjpeg-turbo \
|
|
&& cd /tmp/libjpeg-turbo \
|
|
&& git remote add origin "${github_prefix}https://github.com/libjpeg-turbo/libjpeg-turbo.git" \
|
|
&& git fetch --depth 1 origin "refs/tags/${LIBJPEG_TURBO_VERSION}" \
|
|
&& git checkout --detach FETCH_HEAD \
|
|
&& mkdir build && cd build \
|
|
&& cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
|
|
-DCMAKE_INSTALL_PREFIX=/usr/local \
|
|
-DCMAKE_INSTALL_LIBDIR=lib \
|
|
-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 init /tmp/libyuv \
|
|
&& cd /tmp/libyuv \
|
|
&& github_prefix="" \
|
|
&& if [ "$CHINAMIRRO" = "1" ]; then github_prefix="${GH_PROXY%/}/"; fi \
|
|
&& git remote add origin "${github_prefix}https://github.com/lemenkov/libyuv" \
|
|
&& git fetch --depth 1 origin ${LIBYUV_REV} \
|
|
&& git checkout --detach FETCH_HEAD \
|
|
&& mkdir build && cd build \
|
|
&& cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
|
|
-DJPEG_FOUND=TRUE \
|
|
-DJPEG_INCLUDE_DIR=/usr/local/include \
|
|
-DJPEG_LIBRARY=/usr/local/lib/libjpeg.a \
|
|
-DCMAKE_C_FLAGS="-DHAVE_JPEG -I/usr/local/include" \
|
|
-DCMAKE_CXX_FLAGS="-DHAVE_JPEG -I/usr/local/include" \
|
|
&& make -j$(nproc) \
|
|
&& make install \
|
|
&& rm -rf /tmp/libyuv
|
|
|
|
# Build static libvpx from source
|
|
RUN github_prefix="" \
|
|
&& if [ "$CHINAMIRRO" = "1" ]; then github_prefix="${GH_PROXY%/}/"; fi \
|
|
&& git init /tmp/libvpx \
|
|
&& cd /tmp/libvpx \
|
|
&& git remote add origin "${github_prefix}https://github.com/webmproject/libvpx.git" \
|
|
&& git fetch --depth 1 origin "refs/tags/v${LIBVPX_VERSION}" \
|
|
&& git checkout --detach FETCH_HEAD \
|
|
&& ./configure \
|
|
--enable-static --disable-shared --enable-pic \
|
|
--disable-examples --disable-tools --disable-docs \
|
|
--disable-unit-tests \
|
|
&& make -j$(nproc) \
|
|
&& make install \
|
|
&& rm -rf /tmp/libvpx
|
|
|
|
# Build static libx264 from source
|
|
RUN github_prefix="" \
|
|
&& if [ "$CHINAMIRRO" = "1" ]; then github_prefix="${GH_PROXY%/}/"; fi \
|
|
&& git clone --depth 1 "${github_prefix}https://github.com/mirror/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 github_prefix="" \
|
|
&& if [ "$CHINAMIRRO" = "1" ]; then github_prefix="${GH_PROXY%/}/"; fi \
|
|
&& git init /tmp/x265 \
|
|
&& cd /tmp/x265 \
|
|
&& git remote add origin "${github_prefix}https://github.com/videolan/x265.git" \
|
|
&& git fetch --depth 1 origin "refs/tags/${X265_VERSION}" \
|
|
&& git checkout --detach FETCH_HEAD \
|
|
&& cd source \
|
|
&& mkdir -p build \
|
|
&& cd build \
|
|
&& cmake .. -DCMAKE_BUILD_TYPE=Release \
|
|
-DCMAKE_ASM_NASM_FLAGS="-w-macro-params-legacy" \
|
|
-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 github_prefix="" \
|
|
&& if [ "$CHINAMIRRO" = "1" ]; then github_prefix="${GH_PROXY%/}/"; fi \
|
|
&& wget -O /tmp/opus.tar.gz "${github_prefix}https://github.com/xiph/opus/releases/download/v${OPUS_VERSION}/opus-${OPUS_VERSION}.tar.gz" \
|
|
&& tar -xzf /tmp/opus.tar.gz -C /tmp \
|
|
&& mv "/tmp/opus-${OPUS_VERSION}" /tmp/opus \
|
|
&& cd /tmp/opus \
|
|
&& ./configure \
|
|
--enable-static --disable-shared \
|
|
--disable-doc \
|
|
&& make -j$(nproc) \
|
|
&& make install \
|
|
&& rm -rf /tmp/opus /tmp/opus.tar.gz
|
|
|
|
# Download and build FFmpeg with minimal configuration for encoding only
|
|
RUN mkdir -p /tmp/ffmpeg-build && cd /tmp/ffmpeg-build \
|
|
&& github_prefix="" \
|
|
&& if [ "$CHINAMIRRO" = "1" ]; then github_prefix="${GH_PROXY%/}/"; fi \
|
|
&& git init ffmpeg-rockchip \
|
|
&& cd ffmpeg-rockchip \
|
|
&& git remote add origin "${github_prefix}https://github.com/nyanmisaka/ffmpeg-rockchip.git" \
|
|
&& git fetch --depth 1 origin ${FFMPEG_ROCKCHIP_REV} \
|
|
&& git checkout --detach FETCH_HEAD \
|
|
&& ./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 if [ "$CHINAMIRRO" = "1" ]; then \
|
|
export RUSTUP_DIST_SERVER=${RUSTUP_DIST_SERVER_CN}; \
|
|
export RUSTUP_UPDATE_ROOT=${RUSTUP_UPDATE_ROOT_CN}; \
|
|
fi \
|
|
&& 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
|