From ffce032b9547f5807290d61addde3fbccb27f2e2 Mon Sep 17 00:00:00 2001 From: FreezyLemon Date: Wed, 23 Aug 2023 15:26:00 +0200 Subject: [PATCH 1/6] Move ffmpeg build scripts into one directory --- .github/workflows/build-ffmpeg.yml | 18 +++--- .../scripts/ffmpeg/BUILDING.md | 63 +++++++++++++++++++ .../scripts/ffmpeg/build-linux.sh | 24 +++++++ .../scripts/ffmpeg/build-macOS.sh | 52 +++++++++++++++ .../scripts/ffmpeg/build-win.sh | 61 ++++++++++++++++++ .../scripts/ffmpeg/combine_dylibs.sh | 13 ++++ .../scripts/ffmpeg/common.sh | 50 ++++++++++----- .../scripts/ffmpeg/linux/BUILDING.md | 16 ----- .../scripts/ffmpeg/linux/fetch_and_build.sh | 16 ----- .../scripts/ffmpeg/macOS/BUILDING.md | 16 ----- .../scripts/ffmpeg/macOS/combine_universal.sh | 9 --- .../scripts/ffmpeg/macOS/fetch_and_build.sh | 53 ---------------- .../scripts/ffmpeg/win/BUILDING.md | 16 ----- .../scripts/ffmpeg/win/fetch_and_build.sh | 54 ---------------- 14 files changed, 255 insertions(+), 206 deletions(-) create mode 100644 osu.Framework.NativeLibs/scripts/ffmpeg/BUILDING.md create mode 100755 osu.Framework.NativeLibs/scripts/ffmpeg/build-linux.sh create mode 100755 osu.Framework.NativeLibs/scripts/ffmpeg/build-macOS.sh create mode 100755 osu.Framework.NativeLibs/scripts/ffmpeg/build-win.sh create mode 100755 osu.Framework.NativeLibs/scripts/ffmpeg/combine_dylibs.sh delete mode 100644 osu.Framework.NativeLibs/scripts/ffmpeg/linux/BUILDING.md delete mode 100755 osu.Framework.NativeLibs/scripts/ffmpeg/linux/fetch_and_build.sh delete mode 100644 osu.Framework.NativeLibs/scripts/ffmpeg/macOS/BUILDING.md delete mode 100755 osu.Framework.NativeLibs/scripts/ffmpeg/macOS/combine_universal.sh delete mode 100755 osu.Framework.NativeLibs/scripts/ffmpeg/macOS/fetch_and_build.sh delete mode 100644 osu.Framework.NativeLibs/scripts/ffmpeg/win/BUILDING.md delete mode 100755 osu.Framework.NativeLibs/scripts/ffmpeg/win/fetch_and_build.sh diff --git a/.github/workflows/build-ffmpeg.yml b/.github/workflows/build-ffmpeg.yml index b4de4b3bc3..b11873effc 100644 --- a/.github/workflows/build-ffmpeg.yml +++ b/.github/workflows/build-ffmpeg.yml @@ -18,7 +18,7 @@ jobs: - uses: ilammy/setup-nasm@v1 - name: Build - run: osu.Framework.NativeLibs/scripts/ffmpeg/macOS/fetch_and_build.sh + run: osu.Framework.NativeLibs/scripts/ffmpeg/build-macOS.sh env: arch: ${{ matrix.arch }} @@ -26,7 +26,7 @@ jobs: uses: actions/upload-artifact@v3 with: name: macOS-${{ matrix.arch }} - path: build-${{ matrix.arch }} + path: macOS-${{ matrix.arch }} combine-macos: name: Combine macOS libs @@ -46,7 +46,7 @@ jobs: path: macOS-arm64 - name: Combine - run: osu.Framework.NativeLibs/scripts/ffmpeg/macOS/combine_universal.sh + run: osu.Framework.NativeLibs/scripts/ffmpeg/combine_dylibs.sh - name: Upload uses: actions/upload-artifact@v3 @@ -73,7 +73,7 @@ jobs: sudo apt-get install make nasm gcc mingw-w64 - name: Build - run: osu.Framework.NativeLibs/scripts/ffmpeg/win/fetch_and_build.sh + run: osu.Framework.NativeLibs/scripts/ffmpeg/build-win.sh env: arch: ${{ matrix.arch }} @@ -81,7 +81,7 @@ jobs: uses: actions/upload-artifact@v3 with: name: win-${{ matrix.arch }} - path: build-${{ matrix.arch }} + path: win-${{ matrix.arch }} # The win-arm64 build runs in a special MinGW container to cross-compile successfully. build-win-arm64: @@ -94,7 +94,7 @@ jobs: uses: actions/checkout@v3 - name: Build - run: osu.Framework.NativeLibs/scripts/ffmpeg/win/fetch_and_build.sh + run: osu.Framework.NativeLibs/scripts/ffmpeg/build-win.sh env: arch: arm64 @@ -102,7 +102,7 @@ jobs: uses: actions/upload-artifact@v3 with: name: win-arm64 - path: build-arm64 + path: win-arm64 build-linux: name: Build Linux (x64) @@ -119,13 +119,13 @@ jobs: uses: actions/checkout@v3 - name: Build - run: osu.Framework.NativeLibs/scripts/ffmpeg/linux/fetch_and_build.sh + run: osu.Framework.NativeLibs/scripts/ffmpeg/build-linux.sh - name: Upload uses: actions/upload-artifact@v3 with: name: linux-x64 - path: build-x64 + path: linux-x64 make-pr: name: Create pull request diff --git a/osu.Framework.NativeLibs/scripts/ffmpeg/BUILDING.md b/osu.Framework.NativeLibs/scripts/ffmpeg/BUILDING.md new file mode 100644 index 0000000000..531ff3030e --- /dev/null +++ b/osu.Framework.NativeLibs/scripts/ffmpeg/BUILDING.md @@ -0,0 +1,63 @@ +# Build Instructions + +1. Install the dependencies for your platform(s) +2. Run the build script for your platform(s) +3. (macOS only) Run `combine_dylibs.sh` to create universal dylibs + +## Build dependencies + +In general, you need `gcc`, `make`, and `nasm`. +If external libraries need to be included in the build, `pkg-config` is also required. + +### Windows Dependencies (compiling on Ubuntu/Debian) + +Targetting x86 and x86_64: + +```sh +sudo apt install make nasm gcc mingw-w64 mingw-w64-tools +``` + +Targetting aarch64: + +```sh +sudo apt install make nasm + +# Downloading a llvm-mingw release and adding it to PATH # +# If host is x86_64: +url="https://github.com/mstorsjo/llvm-mingw/releases/download/20230614/llvm-mingw-20230614-ucrt-ubuntu-20.04-x86_64.tar.xz" +# If host is aarch64: +#url="https://github.com/mstorsjo/llvm-mingw/releases/download/20230614/llvm-mingw-20230614-ucrt-ubuntu-20.04-aarch64.tar.xz" +curl -Lo llvm-mingw.tar.xz "$url" +mkdir llvm-mingw +tar xfJ llvm-mingw.tar.xz --strip 1 -C llvm-mingw +export PATH="$PATH:$PWD/llvm-mingw/bin" +``` + +### macOS Dependencies + +Check [this page](https://trac.ffmpeg.org/wiki/CompilationGuide/macOS#CompilingFFmpegyourself) for instructions on how to install macOS dependencies. +Note that you don't need packages like `x264` or `libvpx`, it is enough to install these packages in addition to Xcode: + +```zsh +brew install gcc make nasm +``` + +### Linux Dependencies (Ubuntu/Debian) + +```sh +sudo apt install make nasm gcc pkg-config libva-dev libvdpau-dev +``` + +## Output files + +For each `-` combination, two directories will be created. The directory called `-` will +contain the resulting shared libraries, and the directory with a `-build` suffix will contain the respective build files. + +### macOS only: Combine arch-specific dylib files into universal dylib files + +The `combine_universal.sh` script will combine the `x86_64` and `arm64` dylibs into universal dylibs. +The universal dylibs are output into a folder named `macOS-universal` and should be copied into `osu.Framework.NativeLibs/runtimes/osx`. + +## Cleanup + +Files are left around for debugging purposes, manually delete the directories to clean up. \ No newline at end of file diff --git a/osu.Framework.NativeLibs/scripts/ffmpeg/build-linux.sh b/osu.Framework.NativeLibs/scripts/ffmpeg/build-linux.sh new file mode 100755 index 0000000000..763058f01e --- /dev/null +++ b/osu.Framework.NativeLibs/scripts/ffmpeg/build-linux.sh @@ -0,0 +1,24 @@ +#!/bin/bash +set -eu + +pushd "$(dirname "$0")" > /dev/null +SCRIPT_PATH=$(pwd) +popd > /dev/null +source "$SCRIPT_PATH/common.sh" + +FFMPEG_FLAGS+=( + --target-os=linux +) + +pushd . > /dev/null +prep_ffmpeg linux-x64 +build_ffmpeg +popd > /dev/null + +# gcc creates multiple symlinks per .so file for versioning. +# We want to delete the symlinks to prevent weird behaviour with GitHub actions. +rm linux-x64/*.so +for f in linux-x64/*.so.*.*.*; do + mv -v "$f" "${f%.*.*.*}" +done +rm linux-x64/*.so.* diff --git a/osu.Framework.NativeLibs/scripts/ffmpeg/build-macOS.sh b/osu.Framework.NativeLibs/scripts/ffmpeg/build-macOS.sh new file mode 100755 index 0000000000..2eb871c2d9 --- /dev/null +++ b/osu.Framework.NativeLibs/scripts/ffmpeg/build-macOS.sh @@ -0,0 +1,52 @@ +#!/bin/bash +set -eu + +pushd "$(dirname "$0")" > /dev/null +SCRIPT_PATH=$(pwd) +popd > /dev/null +source "$SCRIPT_PATH/common.sh" + +if [ -z "${arch-}" ]; then + PS3='Build for which arch? ' + select arch in "arm64" "x86_64"; do + if [ -z "$arch" ]; then + echo "invalid option" + else + break + fi + done +fi + +FFMPEG_FLAGS+=( + --enable-cross-compile + --target-os=darwin + --arch=$arch + --extra-cflags="-arch $arch" + --extra-ldflags="-arch $arch" +) + +pushd . > /dev/null +prep_ffmpeg "macOS-$arch" +build_ffmpeg +popd > /dev/null + +# Rename dylibs that have a full version string (A.B.C) in their filename +# Example: avcodec.58.10.72.dylib -> avcodec.58.dylib +pushd . > /dev/null +cd "macOS-$arch" +for f in *.*.*.*.dylib; do + [ -f "$f" ] || continue + mv -v "$f" "${f%.*.*.*}.dylib" +done +popd > /dev/null + +echo "-> Fixing dylibs paths..." +BUILDPATH="macOS-$arch" +LIBS="libavcodec.58.dylib libavdevice.58.dylib libavfilter.7.dylib libavformat.58.dylib libavutil.56.dylib libswresample.3.dylib libswscale.5.dylib" +for f in $LIBS; do + install_name_tool "$BUILDPATH/$f" -id "@loader_path/$f" \ + -change $BUILDPATH/libavcodec.58.dylib @loader_path/libavcodec.58.dylib \ + -change $BUILDPATH/libavformat.58.dylib @loader_path/libavformat.58.dylib \ + -change $BUILDPATH/libavutil.56.dylib @loader_path/libavutil.56.dylib \ + -change $BUILDPATH/libswscale.5.dylib @loader_path/libswscale.5.dylib +done diff --git a/osu.Framework.NativeLibs/scripts/ffmpeg/build-win.sh b/osu.Framework.NativeLibs/scripts/ffmpeg/build-win.sh new file mode 100755 index 0000000000..bb9d403a7d --- /dev/null +++ b/osu.Framework.NativeLibs/scripts/ffmpeg/build-win.sh @@ -0,0 +1,61 @@ +#!/bin/bash +set -eu + +pushd "$(dirname "$0")" > /dev/null +SCRIPT_PATH=$(pwd) +popd > /dev/null +source "$SCRIPT_PATH/common.sh" + +if [ -z "${arch-}" ]; then + PS3='Build for which arch? ' + select arch in "x86" "x64" "arm64"; do + if [ -z "$arch" ]; then + echo "invalid option" + else + break + fi + done +fi + +cross_arch='' +cross_prefix='' + +case $arch in + x86) + cross_arch='x86' + cross_prefix='i686-w64-mingw32-' + ;; + + x64) + cross_arch='x86_64' + cross_prefix='x86_64-w64-mingw32-' + ;; + + arm64) + cross_arch='aarch64' + cross_prefix='aarch64-w64-mingw32-' + ;; +esac + +FFMPEG_FLAGS+=( + --enable-cross-compile + --target-os=mingw32 + --arch=$cross_arch + --cross-prefix=$cross_prefix +) + +pushd . > /dev/null +prep_ffmpeg "win-$arch" + +# FFmpeg doesn't do this correctly when building, so we do it instead. +# A newer FFmpeg release might make this unnecessary. +echo '-> Creating resource objects...' +make .version +for res in lib*/*res.rc; do + "${cross_prefix}windres" -I. "$res" "${res%.rc}.o" +done + +build_ffmpeg +popd > /dev/null + +find "win-$arch" -not -name "win-$arch" -not -name '*.dll' -delete diff --git a/osu.Framework.NativeLibs/scripts/ffmpeg/combine_dylibs.sh b/osu.Framework.NativeLibs/scripts/ffmpeg/combine_dylibs.sh new file mode 100755 index 0000000000..9eb2ae0372 --- /dev/null +++ b/osu.Framework.NativeLibs/scripts/ffmpeg/combine_dylibs.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -eu + +pushd . > /dev/null +mkdir -p macOS-universal +cd macOS-arm64 +for lib_arm in *.dylib; do + lib_x86="../macOS-x86_64/$lib_arm" + + echo "-> Creating universal $lib_arm..." + lipo -create "$lib_arm" "$lib_x86" -output "../macOS-universal/$lib_arm" +done +popd > /dev/null diff --git a/osu.Framework.NativeLibs/scripts/ffmpeg/common.sh b/osu.Framework.NativeLibs/scripts/ffmpeg/common.sh index 36e5cf2e6d..443f5e1cce 100755 --- a/osu.Framework.NativeLibs/scripts/ffmpeg/common.sh +++ b/osu.Framework.NativeLibs/scripts/ffmpeg/common.sh @@ -1,7 +1,8 @@ #!/bin/bash +set -eu FFMPEG_VERSION=4.3.3 - +FFMPEG_FILE="ffmpeg-$FFMPEG_VERSION.tar.gz" FFMPEG_FLAGS=( --disable-programs --disable-doc @@ -27,28 +28,43 @@ FFMPEG_FLAGS=( --enable-shared ) -function build_ffmpeg() { - if [ ! -d "ffmpeg-$FFMPEG_VERSION" ]; then - echo "-> Downloading source..." - curl https://ffmpeg.org/releases/ffmpeg-$FFMPEG_VERSION.tar.gz | tar zxf - +function prep_ffmpeg() { + FFMPEG_FLAGS+=( + --prefix="$PWD/$1" + --shlibdir="$PWD/$1" + ) + + local build_dir="$1-build" + if [ ! -e "$FFMPEG_FILE" ]; then + echo "-> Downloading $FFMPEG_FILE..." + curl -o "$FFMPEG_FILE" "https://ffmpeg.org/releases/$FFMPEG_FILE" else - echo "-> ffmpeg-$FFMPEG_VERSION already exists, not re-downloading." + echo "-> $FFMPEG_FILE already exists, not re-downloading." fi - echo "-> Configuring..." - - cd ffmpeg-$FFMPEG_VERSION - ./configure "${FFMPEG_FLAGS[@]}" - - CORES=0 - if [[ "$OSTYPE" == "darwin"* ]]; then - CORES=$(sysctl -n hw.ncpu) + if [ ! -d "$build_dir" ]; then + echo "-> Unpacking source to $build_dir..." + mkdir "$build_dir" + tar xzf "$FFMPEG_FILE" --strip 1 -C "$build_dir" else - CORES=$(nproc) + echo "-> $build_dir already exists, skipping unpacking." fi + echo "-> Configuring..." + cd "$build_dir" + ./configure "${FFMPEG_FLAGS[@]}" +} + +function build_ffmpeg() { echo "-> Building using $CORES threads..." make -j$CORES - make install -} \ No newline at end of file + make install-libs +} + +CORES=0 +if [[ "$OSTYPE" == "darwin"* ]]; then + CORES=$(sysctl -n hw.ncpu) +else + CORES=$(nproc) +fi diff --git a/osu.Framework.NativeLibs/scripts/ffmpeg/linux/BUILDING.md b/osu.Framework.NativeLibs/scripts/ffmpeg/linux/BUILDING.md deleted file mode 100644 index d9c98bd52b..0000000000 --- a/osu.Framework.NativeLibs/scripts/ffmpeg/linux/BUILDING.md +++ /dev/null @@ -1,16 +0,0 @@ -# Build Instructions - -## Dependencies - -``` -sudo apt-get update -sudo apt-get install make nasm gcc -``` - -## `fetch_and_build.sh` -This script downloads ffmpeg 4.3.3 from ffmpeg.org and compiles it. - -It outputs libraries into a folder named `linux-x64`. - -## Cleanup -Files are left around for debugging purposes, manually delete the `linux-x64` and `ffmpeg-4.3.3` folders to cleanup. diff --git a/osu.Framework.NativeLibs/scripts/ffmpeg/linux/fetch_and_build.sh b/osu.Framework.NativeLibs/scripts/ffmpeg/linux/fetch_and_build.sh deleted file mode 100755 index 51a34617a3..0000000000 --- a/osu.Framework.NativeLibs/scripts/ffmpeg/linux/fetch_and_build.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -pushd $(dirname $0) > /dev/null -SCRIPT_PATH=$(pwd) -popd > /dev/null -source $SCRIPT_PATH/../common.sh - -FFMPEG_FLAGS+=( - --target-os=linux - --prefix=build-x64 -) - -build_ffmpeg - -mkdir -p ../build-x64 -cp build-x64/lib/*.so ../build-x64/ \ No newline at end of file diff --git a/osu.Framework.NativeLibs/scripts/ffmpeg/macOS/BUILDING.md b/osu.Framework.NativeLibs/scripts/ffmpeg/macOS/BUILDING.md deleted file mode 100644 index 59b0aef343..0000000000 --- a/osu.Framework.NativeLibs/scripts/ffmpeg/macOS/BUILDING.md +++ /dev/null @@ -1,16 +0,0 @@ -# Build Instructions - -## Dependencies - -See: https://trac.ffmpeg.org/wiki/CompilationGuide/macOS#CompilingFFmpegyourself - -## `fetch_and_build.sh` -This script downloads ffmpeg 4.3.3 from ffmpeg.org and compiles it. You should run this twice - once for `x86_64` and for `arm64`. - -It outputs dylibs into folders named `macOS-$arch` depending on the arch that was built. - -## `combine_universal.sh` -Use this script to combine the `x86_64` and `arm64` dylibs built by the previous script into universal dylibs. The universal dylibs are output into a folder named `macOS-universal` and should be copied into `osu.Framework.NativeLibs/runtimes/osx`. - -## Cleanup -Files are left around for debugging purposes, manually delete the `macOS-$arch` and `ffmpeg-4.3.3` folders to cleanup. diff --git a/osu.Framework.NativeLibs/scripts/ffmpeg/macOS/combine_universal.sh b/osu.Framework.NativeLibs/scripts/ffmpeg/macOS/combine_universal.sh deleted file mode 100755 index dab8b5a6ea..0000000000 --- a/osu.Framework.NativeLibs/scripts/ffmpeg/macOS/combine_universal.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -mkdir -p macOS-universal - -lipo -create macOS-arm64/libavcodec.58.dylib macOS-x86_64/libavcodec.58.dylib -output macOS-universal/libavcodec.58.dylib -lipo -create macOS-arm64/libavfilter.7.dylib macOS-x86_64/libavfilter.7.dylib -output macOS-universal/libavfilter.7.dylib -lipo -create macOS-arm64/libavformat.58.dylib macOS-x86_64/libavformat.58.dylib -output macOS-universal/libavformat.58.dylib -lipo -create macOS-arm64/libavutil.56.dylib macOS-x86_64/libavutil.56.dylib -output macOS-universal/libavutil.56.dylib -lipo -create macOS-arm64/libswscale.5.dylib macOS-x86_64/libswscale.5.dylib -output macOS-universal/libswscale.5.dylib diff --git a/osu.Framework.NativeLibs/scripts/ffmpeg/macOS/fetch_and_build.sh b/osu.Framework.NativeLibs/scripts/ffmpeg/macOS/fetch_and_build.sh deleted file mode 100755 index 74f80082b8..0000000000 --- a/osu.Framework.NativeLibs/scripts/ffmpeg/macOS/fetch_and_build.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/bash - -pushd $(dirname $0) > /dev/null -SCRIPT_PATH=$(pwd) -popd > /dev/null -source $SCRIPT_PATH/../common.sh - -if [ -z "$arch" ]; then - PS3='Build for which arch? ' - archs=("arm64" "x86_64") - select arch in "${archs[@]}"; do - case $arch in - "arm64") - break;; - "x86_64") - break;; - *) echo "invalid option";; - esac - done -fi - -FFMPEG_FLAGS+=( - --target-os=darwin - --arch=$arch - --enable-cross-compile - --extra-cflags='-arch $arch' - --extra-ldflags='-arch $arch' - --prefix=build-$arch - --libdir=build-$arch/lib -) - -build_ffmpeg - -mv build-$arch/lib/libavcodec.58.91.100.dylib build-$arch/lib/libavcodec.58.dylib -mv build-$arch/lib/libavfilter.7.85.100.dylib build-$arch/lib/libavfilter.7.dylib -mv build-$arch/lib/libavformat.58.45.100.dylib build-$arch/lib/libavformat.58.dylib -mv build-$arch/lib/libavutil.56.51.100.dylib build-$arch/lib/libavutil.56.dylib -mv build-$arch/lib/libswscale.5.7.100.dylib build-$arch/lib/libswscale.5.dylib - -echo "-> Fixing dylibs paths..." -BUILDPATH=build-$arch/lib -LIBS="libavcodec.58.dylib libavdevice.58.dylib libavfilter.7.dylib libavformat.58.dylib libavutil.56.dylib libswresample.3.dylib libswscale.5.dylib" -for f in $LIBS; do - install_name_tool $BUILDPATH/$f -id @loader_path/$f \ - -change $BUILDPATH/libavcodec.58.dylib @loader_path/libavcodec.58.dylib \ - -change $BUILDPATH/libavfilter.7.dylib @loader_path/libavfilter.7.dylib \ - -change $BUILDPATH/libavformat.58.dylib @loader_path/libavformat.58.dylib \ - -change $BUILDPATH/libavutil.56.dylib @loader_path/libavutil.56.dylib \ - -change $BUILDPATH/libswscale.5.dylib @loader_path/libswscale.5.dylib - - mkdir -p ../build-$arch - cp $BUILDPATH/$f ../build-$arch/$f -done diff --git a/osu.Framework.NativeLibs/scripts/ffmpeg/win/BUILDING.md b/osu.Framework.NativeLibs/scripts/ffmpeg/win/BUILDING.md deleted file mode 100644 index 7833c7a451..0000000000 --- a/osu.Framework.NativeLibs/scripts/ffmpeg/win/BUILDING.md +++ /dev/null @@ -1,16 +0,0 @@ -# Build Instructions - -## Dependencies - -``` -sudo apt-get update -sudo apt-get install make nasm gcc mingw-w64 -``` - -## `fetch_and_build.sh` -This script downloads ffmpeg 4.3.3 from ffmpeg.org and compiles it. You should run this three times - once for `x86`, `x64`, and `arm64`. - -It outputs libraries into folders named `win-$arch` depending on the arch that was built. - -## Cleanup -Files are left around for debugging purposes, manually delete the `win-$arch` and `ffmpeg-4.3.3` folders to cleanup. diff --git a/osu.Framework.NativeLibs/scripts/ffmpeg/win/fetch_and_build.sh b/osu.Framework.NativeLibs/scripts/ffmpeg/win/fetch_and_build.sh deleted file mode 100755 index a0cd697bb8..0000000000 --- a/osu.Framework.NativeLibs/scripts/ffmpeg/win/fetch_and_build.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/bash - -pushd $(dirname $0) > /dev/null -SCRIPT_PATH=$(pwd) -popd > /dev/null -source $SCRIPT_PATH/../common.sh - -if [ -z "$arch" ]; then - PS3='Build for which arch? ' - archs=("x86" "x64" "arm64") - select arch in "${archs[@]}"; do - case $arch in - "x86") - break;; - "x64") - break;; - "arm64") - break;; - *) echo "invalid option";; - esac - done -fi - -cross_arch='' -cross_prefix='' - -case $arch in - x86) - cross_arch='x86' - cross_prefix='i686-w64-mingw32-' - ;; - - x64) - cross_arch='x86' - cross_prefix='x86_64-w64-mingw32-' - ;; - - arm64) - cross_arch='aarch64' - cross_prefix='aarch64-w64-mingw32-' - ;; -esac - -FFMPEG_FLAGS+=( - --arch=$cross_arch - --target-os=mingw32 - --cross-prefix=$cross_prefix - --prefix=build-$arch -) - -build_ffmpeg - -mkdir -p ../build-$arch -cp build-$arch/bin/*.dll ../build-$arch/ \ No newline at end of file From a1337f48c5cd2e476cdfd18b95ab9e5a383bbaf9 Mon Sep 17 00:00:00 2001 From: FreezyLemon Date: Wed, 23 Aug 2023 15:29:54 +0200 Subject: [PATCH 2/6] Delete PR branch automatically --- .github/workflows/build-ffmpeg.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-ffmpeg.yml b/.github/workflows/build-ffmpeg.yml index b11873effc..1b7c7ea448 100644 --- a/.github/workflows/build-ffmpeg.yml +++ b/.github/workflows/build-ffmpeg.yml @@ -166,5 +166,6 @@ jobs: title: Update FFmpeg binaries body: This PR has been auto-generated to update the FFmpeg binaries. branch: update-ffmpeg-binaries + delete-branch: true env: ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true' From d8589c3f855cd9c622522f33146c99dd3848f369 Mon Sep 17 00:00:00 2001 From: FreezyLemon Date: Wed, 23 Aug 2023 15:31:04 +0200 Subject: [PATCH 3/6] Fix CI runner versions --- .github/workflows/build-ffmpeg.yml | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build-ffmpeg.yml b/.github/workflows/build-ffmpeg.yml index 1b7c7ea448..34850915f0 100644 --- a/.github/workflows/build-ffmpeg.yml +++ b/.github/workflows/build-ffmpeg.yml @@ -4,7 +4,7 @@ on: workflow_dispatch jobs: build-macos: name: Build macOS - runs-on: macos-latest + runs-on: macos-12 strategy: fail-fast: false matrix: @@ -30,7 +30,7 @@ jobs: combine-macos: name: Combine macOS libs - runs-on: macos-latest + runs-on: macos-12 needs: build-macos steps: - name: Checkout @@ -56,7 +56,7 @@ jobs: build-win: name: Build Windows - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 strategy: fail-fast: false matrix: @@ -69,8 +69,8 @@ jobs: - name: Install dependencies run: | - sudo apt-get update - sudo apt-get install make nasm gcc mingw-w64 + sudo apt-get update && sudo apt-get upgrade + sudo apt-get install -y make nasm gcc mingw-w64 - name: Build run: osu.Framework.NativeLibs/scripts/ffmpeg/build-win.sh @@ -86,7 +86,7 @@ jobs: # The win-arm64 build runs in a special MinGW container to cross-compile successfully. build-win-arm64: name: Build Windows (arm64) - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 container: image: mstorsjo/llvm-mingw:latest steps: @@ -106,14 +106,12 @@ jobs: build-linux: name: Build Linux (x64) - runs-on: ubuntu-latest - container: - image: ubuntu:16.04 + runs-on: ubuntu-22.04 steps: - name: Install dependencies run: | - apt-get update - apt-get install -y git curl gcc make nasm + sudo apt-get update && sudo apt-get upgrade + sudo apt-get install -y git curl gcc make nasm pkg-config libva-dev libvdpau-dev - name: Checkout uses: actions/checkout@v3 @@ -129,7 +127,7 @@ jobs: make-pr: name: Create pull request - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 needs: - combine-macos - build-win From a453e65572278cbe3f95116d6cac23296eb93079 Mon Sep 17 00:00:00 2001 From: FreezyLemon Date: Wed, 23 Aug 2023 15:32:12 +0200 Subject: [PATCH 4/6] Remove unneeded FFmpeg features Keep pipe protocol even though it's unneeded to suppress some demuxing warnings (at almost zero filesize cost) --- .../scripts/ffmpeg/build-linux.sh | 7 ++++ .../scripts/ffmpeg/build-macOS.sh | 7 +++- .../scripts/ffmpeg/build-win.sh | 8 +++++ .../scripts/ffmpeg/common.sh | 35 ++++++++----------- osu.Framework/Graphics/Video/VideoDecoder.cs | 2 +- 5 files changed, 37 insertions(+), 22 deletions(-) diff --git a/osu.Framework.NativeLibs/scripts/ffmpeg/build-linux.sh b/osu.Framework.NativeLibs/scripts/ffmpeg/build-linux.sh index 763058f01e..66891d58b8 100755 --- a/osu.Framework.NativeLibs/scripts/ffmpeg/build-linux.sh +++ b/osu.Framework.NativeLibs/scripts/ffmpeg/build-linux.sh @@ -7,6 +7,13 @@ popd > /dev/null source "$SCRIPT_PATH/common.sh" FFMPEG_FLAGS+=( + --enable-vaapi + --enable-vdpau + --enable-hwaccel='h264_vaapi,h264_vdpau' + --enable-hwaccel='hevc_vaapi,hevc_vdpau' + --enable-hwaccel='vp8_vaapi,vp8_vdpau' + --enable-hwaccel='vp9_vaapi,vp9_vdpau' + --target-os=linux ) diff --git a/osu.Framework.NativeLibs/scripts/ffmpeg/build-macOS.sh b/osu.Framework.NativeLibs/scripts/ffmpeg/build-macOS.sh index 2eb871c2d9..36bcffcbbe 100755 --- a/osu.Framework.NativeLibs/scripts/ffmpeg/build-macOS.sh +++ b/osu.Framework.NativeLibs/scripts/ffmpeg/build-macOS.sh @@ -18,6 +18,11 @@ if [ -z "${arch-}" ]; then fi FFMPEG_FLAGS+=( + --enable-videotoolbox + --enable-hwaccel=h264_videotoolbox + --enable-hwaccel=hevc_videotoolbox + --enable-hwaccel=vp9_videotoolbox + --enable-cross-compile --target-os=darwin --arch=$arch @@ -42,7 +47,7 @@ popd > /dev/null echo "-> Fixing dylibs paths..." BUILDPATH="macOS-$arch" -LIBS="libavcodec.58.dylib libavdevice.58.dylib libavfilter.7.dylib libavformat.58.dylib libavutil.56.dylib libswresample.3.dylib libswscale.5.dylib" +LIBS="libavcodec.58.dylib libavformat.58.dylib libavutil.56.dylib libswscale.5.dylib" for f in $LIBS; do install_name_tool "$BUILDPATH/$f" -id "@loader_path/$f" \ -change $BUILDPATH/libavcodec.58.dylib @loader_path/libavcodec.58.dylib \ diff --git a/osu.Framework.NativeLibs/scripts/ffmpeg/build-win.sh b/osu.Framework.NativeLibs/scripts/ffmpeg/build-win.sh index bb9d403a7d..ded8520dab 100755 --- a/osu.Framework.NativeLibs/scripts/ffmpeg/build-win.sh +++ b/osu.Framework.NativeLibs/scripts/ffmpeg/build-win.sh @@ -38,6 +38,14 @@ case $arch in esac FFMPEG_FLAGS+=( + --enable-w32threads + + --enable-dxva2 + --enable-d3d11va + --enable-hwaccel='h264_dxva2,h264_d3d11va,h264_d3d11va2' + --enable-hwaccel='hevc_dxva2,hevc_d3d11va,hevc_d3d11va2' + --enable-hwaccel='vp9_dxva2,vp9_d3d11va,vp9_d3d11va2' + --enable-cross-compile --target-os=mingw32 --arch=$cross_arch diff --git a/osu.Framework.NativeLibs/scripts/ffmpeg/common.sh b/osu.Framework.NativeLibs/scripts/ffmpeg/common.sh index 443f5e1cce..ee0f574669 100755 --- a/osu.Framework.NativeLibs/scripts/ffmpeg/common.sh +++ b/osu.Framework.NativeLibs/scripts/ffmpeg/common.sh @@ -4,28 +4,23 @@ set -eu FFMPEG_VERSION=4.3.3 FFMPEG_FILE="ffmpeg-$FFMPEG_VERSION.tar.gz" FFMPEG_FLAGS=( - --disable-programs - --disable-doc + # General options --disable-static - --disable-debug - --disable-ffplay - --disable-ffprobe - --disable-avdevice - --disable-swresample - --disable-librtmp - --disable-alsa - --disable-iconv - --disable-libxcb - --disable-libxcb-shm - --disable-libxcb-xfixes - --disable-libxcb-shape - --disable-sdl2 - --disable-zlib - --disable-bzlib - --disable-lzma - --disable-xlib - --disable-schannel --enable-shared + --disable-all + --disable-autodetect + --enable-lto + + # Libraries + --enable-avcodec + --enable-avformat + --enable-swscale + + # File and video formats + --enable-demuxer='mov,matroska,flv,avi' # mov = mp4, matroska = mkv & webm + --enable-parser='h264,hevc,vp8,vp9' + --enable-decoder='h264,hevc,vp8,vp9' + --enable-protocol=pipe ) function prep_ffmpeg() { diff --git a/osu.Framework/Graphics/Video/VideoDecoder.cs b/osu.Framework/Graphics/Video/VideoDecoder.cs index 42d745eeb9..ac197349cb 100644 --- a/osu.Framework/Graphics/Video/VideoDecoder.cs +++ b/osu.Framework/Graphics/Video/VideoDecoder.cs @@ -345,7 +345,7 @@ private void prepareDecoding() formatContext->pb = ioContext; formatContext->flags |= FFmpegFuncs.AVFMT_FLAG_GENPTS; // required for most HW decoders as they only read `pts` - int openInputResult = ffmpeg.avformat_open_input(&fcPtr, "dummy", null, null); + int openInputResult = ffmpeg.avformat_open_input(&fcPtr, "pipe:", null, null); inputOpened = openInputResult >= 0; if (!inputOpened) throw new InvalidOperationException($"Error opening file or stream: {getErrorMessage(openInputResult)}"); From 804d4df08c008e56231fd2e548d76c1208e9fee8 Mon Sep 17 00:00:00 2001 From: FreezyLemon Date: Wed, 23 Aug 2023 15:47:00 +0200 Subject: [PATCH 5/6] Use built-in way to handle install_names This should be functionally equivalent, but should be tested --- .../scripts/ffmpeg/build-macOS.sh | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/osu.Framework.NativeLibs/scripts/ffmpeg/build-macOS.sh b/osu.Framework.NativeLibs/scripts/ffmpeg/build-macOS.sh index 36bcffcbbe..c6978bf011 100755 --- a/osu.Framework.NativeLibs/scripts/ffmpeg/build-macOS.sh +++ b/osu.Framework.NativeLibs/scripts/ffmpeg/build-macOS.sh @@ -28,6 +28,8 @@ FFMPEG_FLAGS+=( --arch=$arch --extra-cflags="-arch $arch" --extra-ldflags="-arch $arch" + + --install-name-dir='@loader_path' ) pushd . > /dev/null @@ -44,14 +46,3 @@ for f in *.*.*.*.dylib; do mv -v "$f" "${f%.*.*.*}.dylib" done popd > /dev/null - -echo "-> Fixing dylibs paths..." -BUILDPATH="macOS-$arch" -LIBS="libavcodec.58.dylib libavformat.58.dylib libavutil.56.dylib libswscale.5.dylib" -for f in $LIBS; do - install_name_tool "$BUILDPATH/$f" -id "@loader_path/$f" \ - -change $BUILDPATH/libavcodec.58.dylib @loader_path/libavcodec.58.dylib \ - -change $BUILDPATH/libavformat.58.dylib @loader_path/libavformat.58.dylib \ - -change $BUILDPATH/libavutil.56.dylib @loader_path/libavutil.56.dylib \ - -change $BUILDPATH/libswscale.5.dylib @loader_path/libswscale.5.dylib -done From eadd42f22e1cac1bf44fa1a71eee228855e339ad Mon Sep 17 00:00:00 2001 From: FreezyLemon Date: Thu, 24 Aug 2023 11:45:21 +0200 Subject: [PATCH 6/6] Build Linux libraries on Ubuntu 20.04 --- .github/workflows/build-ffmpeg.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-ffmpeg.yml b/.github/workflows/build-ffmpeg.yml index 34850915f0..09f00b7224 100644 --- a/.github/workflows/build-ffmpeg.yml +++ b/.github/workflows/build-ffmpeg.yml @@ -106,7 +106,8 @@ jobs: build-linux: name: Build Linux (x64) - runs-on: ubuntu-22.04 + # Use 20.04 to target glibc 2.31 like the other native libs + runs-on: ubuntu-20.04 steps: - name: Install dependencies run: |