From 0f8332bef155046b1e0c557b173effb01f0b3896 Mon Sep 17 00:00:00 2001 From: Michalis Dimopoulos Date: Tue, 13 Jan 2026 02:45:45 +0200 Subject: [PATCH] fix: resolve errors when building GStreamer from source in docker with Ubuntu 24.04 --- docker/Dockerfile | 77 +++++++++++++++++++++++++++++++++----------- docker/README.md | 20 ++++-------- docker/run-docker.sh | 10 +++--- 3 files changed, 71 insertions(+), 36 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 105052ab..c6e1895a 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -21,12 +21,16 @@ ARG UBUNTU_VERSION=24.04 FROM ubuntu:${UBUNTU_VERSION} +# A user is required by Ubuntu 24.04 to install meson as non-root +ARG USERNAME='mock' +ARG PASSWORD='mock' + # Re-declare args after FROM to make them available in build stages ARG UBUNTU_VERSION ARG NVIDIA_DRIVER_VERSION # FFmpeg installation method: "system" (default), "static", "source" ARG FFMPEG_INSTALL_METHOD=system -# FFmpeg version for "static" and "source" methods +# FFmpeg version for "source" method ARG FFMPEG_VERSION=8.0 # GStreamer installation method: "system" (default), "source" ARG GSTREAMER_INSTALL_METHOD=system @@ -47,6 +51,7 @@ RUN apt-get update && apt-get install -y \ curl \ ca-certificates \ software-properties-common \ + sudo \ python3 \ python3-pip \ python3-venv \ @@ -190,12 +195,12 @@ RUN if [ "${FFMPEG_INSTALL_METHOD}" = "source" ]; then \ && ldconfig \ && cd / && rm -rf /tmp/ffmpeg /tmp/ffmpeg_sources; \ elif [ "${FFMPEG_INSTALL_METHOD}" = "static" ]; then \ - wget -q https://johnvansickle.com/ffmpeg/releases/ffmpeg-${FFMPEG_VERSION}-linux64-gpl.tar.xz && \ - tar -xf ffmpeg-${FFMPEG_VERSION}-linux64-gpl.tar.xz && \ - mv ffmpeg-${FFMPEG_VERSION}-linux64-gpl /opt/ffmpeg && \ + wget -q https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz && \ + tar -xf ffmpeg-release-amd64-static.tar.xz && \ + mv ffmpeg-*-amd64-static /opt/ffmpeg && \ ln -sf /opt/ffmpeg/ffmpeg /usr/local/bin/ffmpeg && \ ln -sf /opt/ffmpeg/ffprobe /usr/local/bin/ffprobe && \ - rm ffmpeg-${FFMPEG_VERSION}-linux64-gpl.tar.xz; \ + rm ffmpeg-release-amd64-static.tar.xz; \ else \ apt-get update && \ apt-get install -y --no-install-recommends \ @@ -207,6 +212,39 @@ RUN if [ "${FFMPEG_INSTALL_METHOD}" = "source" ]; then \ && rm -rf /var/lib/apt/lists/*; \ fi +# Update python packages depending on Ubuntu version +RUN if [ "${GSTREAMER_INSTALL_METHOD}" = "source" ]; then \ + if [ "${UBUNTU_VERSION}" = "24.04" ]; then \ + pip3 install --upgrade pip setuptools; \ + apt update && apt install -y pipx ninja-build && rm -rf /var/lib/apt/lists/*; \ + else \ + pip3 install --upgrade pip setuptools meson; \ + fi; \ + fi + + +# Ubuntu 24.04: Remove default user +RUN if [ "${UBUNTU_VERSION}" = "24.04" ] && id ubuntu &>/dev/null;; then \ + userdel -r ubuntu; \ + fi + +# Create USERNAME user and add it to sudoers without password +RUN addgroup ${USERNAME} && \ + useradd -rm -s /bin/bash -m -g ${USERNAME} -u 1000 -G sudo ${USERNAME} && \ + echo ${USERNAME}':'${PASSWORD} | chpasswd && echo "${USERNAME} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers; + +# Change to USERNAME user +USER ${USERNAME} + +# Set PATH to include pipx bin directory - only necessary for meson in Ubuntu 24.04 +ARG PATH="/home/${USERNAME}/.local/bin:${PATH}" + +# Ubuntu 24.04: install python packages for non-root user +RUN if [ "${GSTREAMER_INSTALL_METHOD}" = "source" ] && [ "${UBUNTU_VERSION}" = "24.04" ]; then \ + echo "export PATH=/home/${USERNAME}/.local/bin:\${PATH}" >> /home/${USERNAME}/.bashrc; \ + pipx install meson; \ + fi + # GStreamer installation (2 methods: system, source) # Method "source": Build GStreamer from source (needed for new versions on old distros) # Note: gst-libav is disabled when building from source to avoid FFmpeg API incompatibilities @@ -214,7 +252,7 @@ RUN if [ "${FFMPEG_INSTALL_METHOD}" = "source" ]; then \ # Use GStreamer native decoders or FFmpeg directly for decoding. # Method "system": Install GStreamer from system packages (default) RUN if [ "${GSTREAMER_INSTALL_METHOD}" = "source" ]; then \ - apt-get update && apt-get install -y --no-install-recommends \ + sudo apt-get update && sudo apt-get install -y --no-install-recommends \ build-essential \ cmake \ ninja-build \ @@ -228,6 +266,7 @@ RUN if [ "${GSTREAMER_INSTALL_METHOD}" = "source" ]; then \ libpthread-stubs0-dev \ libva-dev \ libvdpau-dev \ + libmfx-dev \ libx11-dev \ libxext-dev \ libxv-dev \ @@ -240,8 +279,8 @@ RUN if [ "${GSTREAMER_INSTALL_METHOD}" = "source" ]; then \ libvpx-dev \ libpng-dev \ libjpeg-dev \ - && rm -rf /var/lib/apt/lists/* \ - && pip3 install --upgrade pip setuptools meson \ + libxml2-dev \ + && sudo rm -rf /var/lib/apt/lists/* \ && mkdir -p /tmp/gstreamer && cd /tmp/gstreamer \ && curl -L "https://gitlab.freedesktop.org/gstreamer/gstreamer/-/archive/${GSTREAMER_VERSION}/gstreamer-${GSTREAMER_VERSION}.tar.gz" | tar xz \ && cd gstreamer-${GSTREAMER_VERSION} \ @@ -267,15 +306,15 @@ RUN if [ "${GSTREAMER_INSTALL_METHOD}" = "source" ]; then \ -Dintrospection=disabled \ -Ddoc=disabled \ -Dqt5=disabled \ - -Dqt6=disabled \ && meson compile -C build -j$(nproc) \ - && meson install -C build \ - && ldconfig \ - && cd / && rm -rf /tmp/gstreamer \ - && apt-get purge -y 'libgstreamer*' 'gstreamer1.0-*' 2>/dev/null || true \ - && apt-get autoremove -y 2>/dev/null || true; \ + && sudo ninja install -C build \ + && sudo ldconfig \ + && cd / && sudo rm -rf /tmp/gstreamer \ + && sudo apt-get purge -y 'libgstreamer*' 'gstreamer1.0-*' 2>/dev/null || true \ + && sudo apt-get autoremove -y 2>/dev/null || true; \ else \ - apt-get update && apt-get install -y \ + sudo DEBIAN_FRONTEND=noninteractive apt-get update && \ + sudo DEBIAN_FRONTEND=noninteractive apt-get install -y \ libgstreamer1.0-dev \ libgstreamer-plugins-base1.0-dev \ libgstreamer-plugins-bad1.0-dev \ @@ -286,11 +325,13 @@ RUN if [ "${GSTREAMER_INSTALL_METHOD}" = "source" ]; then \ gstreamer1.0-libav \ gstreamer1.0-tools \ gstreamer1.0-vaapi \ - && (apt-get install -y gstreamer1.0-va || true) \ - && (apt-get install -y gstreamer1.0-msdk || true) \ - && rm -rf /var/lib/apt/lists/*; \ + && (sudo apt-get install -y gstreamer1.0-va || true) \ + && (sudo apt-get install -y gstreamer1.0-msdk || true) \ + && sudo rm -rf /var/lib/apt/lists/*; \ fi +USER root + # Set library paths - /usr/local MUST come first to prioritize compiled versions ENV LD_LIBRARY_PATH=/usr/local/lib/x86_64-linux-gnu:/usr/local/lib:/usr/lib/x86_64-linux-gnu \ GST_PLUGIN_PATH=/usr/local/lib/x86_64-linux-gnu/gstreamer-1.0:/usr/local/lib/gstreamer-1.0:/usr/lib/x86_64-linux-gnu/gstreamer-1.0 \ diff --git a/docker/README.md b/docker/README.md index 61d117f2..16ca9ec6 100644 --- a/docker/README.md +++ b/docker/README.md @@ -7,7 +7,7 @@ Docker configuration for Fluster with comprehensive codec support including **FF - **Customizable Ubuntu version**: 20.04, 22.04, or 24.04 - **Three FFmpeg installation options**: 1. **System packages** (default) - Fast build, but older versions - 2. **Static binaries** (7.x, 8.x) - Newer FFmpeg, but limited backend support + 2. **Static binaries** (7.x) - Newer FFmpeg, but limited backend support 3. **Build from source** (recommended) - Latest FFmpeg with all backends enabled - **Hardware Acceleration Support**: - **VAAPI** (Intel, AMD, NVIDIA (only on Ubuntu 24.04)) @@ -45,11 +45,8 @@ This Docker setup provides three ways to install FFmpeg, each with different tra **Cons**: Limited hardware backend support (no QuickSync/libmfx) ```bash -# Build with FFmpeg 7.0 static binary -docker build --build-arg FFMPEG_STATIC_VERSION=7.0 -t fluster:ffmpeg7 -f docker/Dockerfile . - -# Build with FFmpeg 8.0 static binary -docker build --build-arg FFMPEG_STATIC_VERSION=8.0 -t fluster:ffmpeg8 -f docker/Dockerfile . +# Build with FFmpeg static binary +docker build --build-arg FFMPEG_INSTALL_METHOD=static -t fluster:ffmpeg-static -f docker/Dockerfile . ``` **Note**: Static binaries from johnvansickle.com lack libmfx (QuickSync) support. @@ -66,7 +63,7 @@ docker build --build-arg FFMPEG_STATIC_VERSION=8.0 -t fluster:ffmpeg8 -f docker/ # Or manually specify version docker build \ - --build-arg BUILD_FFMPEG_FROM_SOURCE=1 \ + --build-arg FFMPEG_INSTALL_METHOD=source \ --build-arg FFMPEG_VERSION=8.0 \ -t fluster:ffmpeg-full \ -f docker/Dockerfile . @@ -157,14 +154,11 @@ Build FFmpeg from source with all backends (recommended for production): By default, FFmpeg from Ubuntu repositories is used. To test with newer FFmpeg versions (e.g., for future VVC support), use static binaries: ```bash -# Build with FFmpeg 7.0 static binary -docker build --build-arg FFMPEG_STATIC_VERSION=7.0 -t fluster:ffmpeg7 -f docker/Dockerfile . - -# Build with FFmpeg 8.0 static binary -docker build --build-arg FFMPEG_STATIC_VERSION=8.0 -t fluster:ffmpeg8 -f docker/Dockerfile . +# Build with FFmpeg static binary +docker build --build-arg FFMPEG_INSTALL_METHOD=static -t fluster:ffmpeg-static -f docker/Dockerfile . # Verify version -docker run --rm fluster:ffmpeg7 ffmpeg -version | head -1 +docker run --rm fluster:ffmpeg-static ffmpeg -version | head -1 ``` **Note:** Static binaries may have limited hardware acceleration support compared to system packages. Use only when testing specific features not available in system FFmpeg. diff --git a/docker/run-docker.sh b/docker/run-docker.sh index c14f15e9..e031320a 100755 --- a/docker/run-docker.sh +++ b/docker/run-docker.sh @@ -44,8 +44,8 @@ Usage: $0 [OPTIONS] [COMMAND] Build Options: --ubuntu VERSION Ubuntu version: 20.04, 22.04, or 24.04 (default: 24.04) --build-ffmpeg Build FFmpeg from source (VAAPI, VDPAU, QuickSync - no NVDEC/CUDA) - --ffmpeg-static Use static FFmpeg binary (default version: 8.0) - --ffmpeg-version Specify FFmpeg version for --build-ffmpeg or --ffmpeg-static + --ffmpeg-static Use static FFmpeg binary (latest version in https://johnvansickle.com/ffmpeg) + --ffmpeg-version Specify FFmpeg version for --build-ffmpeg --build-gstreamer Build GStreamer from source (useful for new versions on old distros) --gstreamer-version Specify GStreamer version for --build-gstreamer (default: 1.24.2) --rebuild Force rebuilding of Docker image @@ -70,7 +70,6 @@ Examples: $0 --build-ffmpeg --rebuild list -c $0 --build-ffmpeg --ffmpeg-version 7.1 --rebuild list -c $0 --ffmpeg-static --rebuild list -c - $0 --ffmpeg-static --ffmpeg-version 7.0 --rebuild list -c $0 --build-gstreamer --gstreamer-version 1.24.10 --rebuild list -c $0 --ubuntu 20.04 --build-gstreamer --rebuild list -c $0 --ubuntu 22.04 --rebuild list -c @@ -121,7 +120,6 @@ while [[ $# -gt 0 ]]; do ;; --ffmpeg-static) FFMPEG_INSTALL_METHOD="static" - FFMPEG_VERSION="${2:-8.0}" shift if [[ $# -gt 0 && ! "$1" =~ ^-- ]]; then shift @@ -184,7 +182,7 @@ if [[ "$(docker images -q $DOCKER_IMAGE 2> /dev/null)" == "" ]] || [ -n "$REBUIL if [ "$FFMPEG_INSTALL_METHOD" = "source" ]; then echo -e "${BLUE}Building FFmpeg ${FFMPEG_VERSION} from source with all backends...${NC}" elif [ "$FFMPEG_INSTALL_METHOD" = "static" ]; then - echo -e "${BLUE}Using static FFmpeg ${FFMPEG_VERSION} binary...${NC}" + echo -e "${BLUE}Using latest static FFmpeg binary...${NC}" else echo -e "${BLUE}Using system FFmpeg packages...${NC}" fi @@ -265,6 +263,8 @@ DOCKER_RUN_OPTS="$DOCKER_RUN_OPTS -v $PROJECT_ROOT/test_suites:/fluster/test_sui DOCKER_RUN_OPTS="$DOCKER_RUN_OPTS -e TERM=xterm-256color" DOCKER_RUN_OPTS="$DOCKER_RUN_OPTS -e LANG=C.UTF-8" DOCKER_RUN_OPTS="$DOCKER_RUN_OPTS -e LC_ALL=C.UTF-8" +# X11 forwarding for VDPAU (requires Xvfb on host) +[ -d /tmp/.X11-unix ] && DOCKER_RUN_OPTS="$DOCKER_RUN_OPTS -v /tmp/.X11-unix:/tmp/.X11-unix:rw -e DISPLAY=${DISPLAY:-:99}" [ -n "$GPU_ENV" ] && DOCKER_RUN_OPTS="$DOCKER_RUN_OPTS $GPU_ENV" DOCKER_RUN_OPTS="$DOCKER_RUN_OPTS --workdir /fluster"