From ed78a761fed521ecd5603bd1423db3094d463539 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Wed, 27 Aug 2025 15:57:39 +0200 Subject: [PATCH] CI Linux FFmpeg: consolidate to a single script in similar fashion as already done for install_sdl.sh As a bonus, we do not need to depend on whole prepare.sh for cache rebuild but only on this script, which is perhaps cleaner and may yield less rebuilds. Also prepare.sh is slightly easier. --- .../scripts/Linux/download_build_ffmpeg.sh | 75 ---------- .github/scripts/Linux/install_ffmpeg.sh | 134 ++++++++++++++++-- .github/scripts/Linux/prepare.sh | 8 +- .github/workflows/ccpp.yml | 6 +- 4 files changed, 128 insertions(+), 95 deletions(-) delete mode 100755 .github/scripts/Linux/download_build_ffmpeg.sh diff --git a/.github/scripts/Linux/download_build_ffmpeg.sh b/.github/scripts/Linux/download_build_ffmpeg.sh deleted file mode 100755 index 40a31e9d5..000000000 --- a/.github/scripts/Linux/download_build_ffmpeg.sh +++ /dev/null @@ -1,75 +0,0 @@ -#!/bin/bash -eux - -install_aom() {( - git clone --depth 1 https://aomedia.googlesource.com/aom - mkdir -p aom/build - cd aom/build - cmake -DBUILD_SHARED_LIBS=1 .. - cmake --build . --parallel "$(nproc)" - sudo cmake --install . -)} - -install_libvpx() { - ( - git clone --depth 1 https://github.com/webmproject/libvpx.git - cd libvpx - ./configure --enable-pic --disable-examples --disable-install-bins --disable-install-srcs --enable-vp9-highbitdepth - make -j "$(nproc)" - sudo make install - ) -} - -FFMPEG_GIT_DEPTH=5000 # greater depth is useful for 3-way merges -install_svt() { - ( git clone --depth 1 https://github.com/OpenVisualCloud/SVT-HEVC && cd SVT-HEVC/Build/linux && ./build.sh release && cd Release && sudo cmake --install . || exit 1 ) - ( git clone --depth 1 https://gitlab.com/AOMediaCodec/SVT-AV1.git && cd SVT-AV1 && cd Build && cmake .. -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Release && cmake --build . --parallel && sudo cmake --install . || exit 1 ) - ( git clone --depth 1 https://github.com/OpenVisualCloud/SVT-VP9.git && cd SVT-VP9/Build && cmake .. -DCMAKE_BUILD_TYPE=Release && cmake --build . --parallel && sudo cmake --install . || exit 1 ) - # libsvtav1 in FFmpeg upstream, for SVT-HEVC now our custom patch in ffmpeg-patches - # if patch apply fails, try increasing $FFMPEG_GIT_DEPTH - git am -3 SVT-VP9/ffmpeg_plugin/master-*.patch - # TOD TOREMOVE when not needed - sed 's/\* avctx->ticks_per_frame//' libavcodec/libsvt_vp9.c >fix - mv fix libavcodec/libsvt_vp9.c -} - -# The NV Video Codec SDK headers version 12.0 implies driver v520.56.06 in Linux -install_nv_codec_headers() { - git clone --depth 1 -b sdk/12.0 https://github.com/FFmpeg/nv-codec-headers - ( cd nv-codec-headers && make && sudo make install || exit 1 ) -} - -install_onevpl() {( - git clone --depth 1 https://github.com/oneapi-src/oneVPL - mkdir oneVPL/build - cd oneVPL/build - cmake -DBUILD_TOOLS=OFF .. - cmake --build . --config Release --parallel - sudo cmake --build . --config Release --target install -)} - -rm -rf /var/tmp/ffmpeg -git clone --depth $FFMPEG_GIT_DEPTH https://github.com/FFmpeg/FFmpeg.git \ - /var/tmp/ffmpeg -cd /var/tmp/ffmpeg -install_aom -install_libvpx -install_nv_codec_headers -install_onevpl -install_svt -# apply patches -find "$GITHUB_WORKSPACE/.github/scripts/Linux/ffmpeg-patches" -name '*.patch' -print0 | sort -z | xargs -0 -n 1 git am -3 -./configure --disable-static --enable-shared --enable-gpl --enable-libx264 --enable-libx265 --enable-libopus --enable-nonfree --enable-nvenc --enable-libaom --enable-libvpx --enable-libspeex --enable-libmp3lame \ - --enable-libdav1d \ - --enable-libde265 \ - --enable-libopenh264 \ - --enable-librav1e \ - --enable-libsvtav1 \ - --enable-libsvthevc \ - --enable-libsvtvp9 \ - --enable-libvpl \ - --disable-sdl2 \ - --enable-vulkan \ - -make -j "$(nproc)" -sudo make install -sudo ldconfig diff --git a/.github/scripts/Linux/install_ffmpeg.sh b/.github/scripts/Linux/install_ffmpeg.sh index b14f135aa..a2b212491 100755 --- a/.github/scripts/Linux/install_ffmpeg.sh +++ b/.github/scripts/Linux/install_ffmpeg.sh @@ -1,13 +1,127 @@ #!/bin/bash -eux -cd /var/tmp/ffmpeg -( cd libvpx && sudo make install ) -( cd nv-codec-headers && sudo make install ) -( cd aom/build && sudo cmake --install . ) -sudo cmake --install SVT-AV1/Build -sudo cmake --install SVT-HEVC/Build/linux/Release -sudo cmake --install SVT-VP9/Build -sudo cmake --build oneVPL/build --config Release --target install +dir=$(dirname "$0") +# shellcheck source=/dev/null +. "$dir/common.sh" # for get_build_deps_excl -sudo make install -sudo ldconfig +# build dir that will be restored from cache +cache_dir=/var/tmp/ffmpeg + +# install the deps - runs always (regardless the cache) +deps() { + ffmpeg_build_dep=$(get_build_deps_excl ffmpeg 'libsdl') + # shellcheck disable=SC2086 # intentional + sudo apt install $ffmpeg_build_dep libdav1d-dev libde265-dev \ + libopenh264-dev + sudo apt-get -y remove 'libavcodec*' 'libavutil*' 'libswscale*' \ + libvpx-dev nginx +} + +install_aom() {( + git clone --depth 1 https://aomedia.googlesource.com/aom + mkdir -p aom/build + cd aom/build + cmake -DBUILD_SHARED_LIBS=1 .. + cmake --build . --parallel "$(nproc)" + sudo cmake --install . +)} + +install_libvpx() {( + git clone --depth 1 https://github.com/webmproject/libvpx.git + cd libvpx + ./configure --enable-pic --disable-examples --disable-install-bins \ + --disable-install-srcs --enable-vp9-highbitdepth + make -j "$(nproc)" + sudo make install +)} + +install_svt() { + ( git clone --depth 1 https://github.com/OpenVisualCloud/SVT-HEVC && + cd SVT-HEVC/Build/linux && ./build.sh release && cd Release && + sudo cmake --install . || exit 1 ) + ( git clone --depth 1 https://gitlab.com/AOMediaCodec/SVT-AV1.git && + cd SVT-AV1 && cd Build && + cmake .. -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Release && + cmake --build . --parallel && sudo cmake --install . || exit 1 ) + ( git clone --depth 1 https://github.com/OpenVisualCloud/SVT-VP9.git && + cd SVT-VP9/Build && cmake .. -DCMAKE_BUILD_TYPE=Release && + cmake --build . --parallel && sudo cmake --install . || exit 1 ) + # libsvtav1 in FFmpeg upstream, for SVT-HEVC now our custom patch in ffmpeg-patches + # if patch apply fails, try increasing $FFMPEG_GIT_DEPTH + git am -3 SVT-VP9/ffmpeg_plugin/master-*.patch + # TOD TOREMOVE when not needed + sed 's/\* avctx->ticks_per_frame//' libavcodec/libsvt_vp9.c >fix + mv fix libavcodec/libsvt_vp9.c +} + +# The NV Video Codec SDK headers version 12.0 implies driver v520.56.06 in Linux +install_nv_codec_headers() { + git clone --depth 1 -b sdk/12.0 https://github.com/FFmpeg/nv-codec-headers + ( cd nv-codec-headers && make && sudo make install || exit 1 ) +} + +install_onevpl() {( + git clone --depth 1 https://github.com/oneapi-src/oneVPL + mkdir oneVPL/build + cd oneVPL/build + cmake -DBUILD_TOOLS=OFF .. + cmake --build . --config Release --parallel + sudo cmake --build . --config Release --target install +)} + +# build FFmpeg deps + FFmpeg itself +build_install() { + rm -rf $cache_dir + FFMPEG_GIT_DEPTH=5000 # greater depth is useful for 3-way merges + git clone --depth $FFMPEG_GIT_DEPTH https://github.com/FFmpeg/FFmpeg.git \ + $cache_dir + cd $cache_dir + install_aom + install_libvpx + install_nv_codec_headers + install_onevpl + install_svt + # apply patches + find "$GITHUB_WORKSPACE/.github/scripts/Linux/ffmpeg-patches" \ + -name '*.patch' -print0 | sort -z | xargs -0 -n 1 git am -3 + ./configure --disable-static --enable-shared --enable-gpl --enable-nonfree \ + --disable-sdl2 \ + --enable-libaom \ + --enable-libdav1d \ + --enable-libde265 \ + --enable-libmp3lame \ + --enable-libopenh264 \ + --enable-libopus \ + --enable-librav1e \ + --enable-libspeex \ + --enable-libsvtav1 \ + --enable-libsvthevc \ + --enable-libsvtvp9 \ + --enable-libvpl \ + --enable-libvpx \ + --enable-libx264 \ + --enable-libx265 \ + --enable-nvenc \ + --enable-vulkan \ + + make -j "$(nproc)" + sudo make install + sudo ldconfig +} + +# if cache is successfully restored, just install the builds +install_cached() { + cd $cache_dir + ( cd libvpx && sudo make install ) + ( cd nv-codec-headers && sudo make install ) + ( cd aom/build && sudo cmake --install . ) + sudo cmake --install SVT-AV1/Build + sudo cmake --install SVT-HEVC/Build/linux/Release + sudo cmake --install SVT-VP9/Build + sudo cmake --build oneVPL/build --config Release --target install + + sudo make install + sudo ldconfig +} + +"${1?action required!}" diff --git a/.github/scripts/Linux/prepare.sh b/.github/scripts/Linux/prepare.sh index 1cca80726..39b67d7a0 100755 --- a/.github/scripts/Linux/prepare.sh +++ b/.github/scripts/Linux/prepare.sh @@ -1,8 +1,6 @@ #!/bin/bash -eux dir=$(dirname "$0") -# shellcheck source=/dev/null -. "$dir/common.sh" # for get_build_deps_excl export PKG_CONFIG_PATH=/usr/local/qt/lib/pkgconfig:/usr/local/lib/pkgconfig export LIBRARY_PATH=/usr/local/lib:/usr/local/qt/lib @@ -38,11 +36,7 @@ sudo apt install libcurl4-openssl-dev # for RTSP client (vidcap) sudo apt install i965-va-driver-shaders libva-dev # instead of i965-va-driver "$dir/install_sdl.sh" deps - -ffmpeg_build_dep=$(get_build_deps_excl ffmpeg 'libsdl') -# shellcheck disable=SC2086 # intentional -sudo apt install $ffmpeg_build_dep libdav1d-dev libde265-dev libopenh264-dev -sudo apt-get -y remove 'libavcodec*' 'libavutil*' 'libswscale*' libvpx-dev nginx +"$dir/install_ffmpeg.sh" deps sudo apt install qt6-base-dev qt6-wayland . /etc/os-release # source ID and VERSION_ID diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 02b09c930..66348c88a 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -84,13 +84,13 @@ jobs: uses: actions/cache@main with: path: '/var/tmp/ffmpeg' - key: cache-ffmpeg-${{ runner.os }}-${{ hashFiles( '.github/scripts/Linux/prepare.sh', '.github/scripts/Linux/download_build_ffmpeg.sh', '.github/scripts/Linux/ffmpeg-patches/*') }} + key: cache-ffmpeg-${{ runner.os }}-${{ hashFiles( '.github/scripts/Linux/install_ffmpeg.sh', '.github/scripts/Linux/ffmpeg-patches/*') }} - name: Build FFmpeg if: steps.cache-ffmpeg.outputs.cache-hit != 'true' - run: .github/scripts/Linux/download_build_ffmpeg.sh + run: .github/scripts/Linux/install_ffmpeg.sh build_install - name: Install Cached FFmpeg if: steps.cache-ffmpeg.outputs.cache-hit == 'true' - run: .github/scripts/Linux/install_ffmpeg.sh + run: .github/scripts/Linux/install_ffmpeg.sh install_cached - name: Cache SDL id: cache-sdl uses: actions/cache@main