From b162063535c8bcf7fa410507a1a88c2c7a898ad5 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 2 Sep 2024 21:55:27 +1000 Subject: [PATCH] CI/AppImage: Build shrunk ffmpeg for media capture --- .github/workflows/rolling-release.yml | 14 +- CMakeModules/FindFFMPEG.cmake | 3 + README.md | 4 +- scripts/appimage/make-appimage.sh | 5 + scripts/deps/build-ffmpeg-linux.sh | 326 ++++++++++++++++++++++++++ 5 files changed, 345 insertions(+), 7 deletions(-) create mode 100755 scripts/deps/build-ffmpeg-linux.sh diff --git a/.github/workflows/rolling-release.yml b/.github/workflows/rolling-release.yml index 50fea617b..58ded3961 100644 --- a/.github/workflows/rolling-release.yml +++ b/.github/workflows/rolling-release.yml @@ -213,22 +213,26 @@ jobs: sudo scripts/retry.sh apt-get -y install \ build-essential clang-17 cmake curl extra-cmake-modules git libasound2-dev libcurl4-openssl-dev libdbus-1-dev libdecor-0-dev libegl-dev libevdev-dev \ libfontconfig-dev libfreetype-dev libfuse2 libgtk-3-dev libgudev-1.0-dev libharfbuzz-dev libinput-dev libopengl-dev libpipewire-0.3-dev libpulse-dev \ - libssl-dev libudev-dev libwayland-dev libx11-dev libx11-xcb-dev libxcb1-dev libxcb-composite0-dev libxcb-cursor-dev libxcb-damage0-dev libxcb-glx0-dev \ - libxcb-icccm4-dev libxcb-image0-dev libxcb-keysyms1-dev libxcb-present-dev libxcb-randr0-dev libxcb-render0-dev libxcb-render-util0-dev libxcb-shape0-dev \ - libxcb-shm0-dev libxcb-sync-dev libxcb-util-dev libxcb-xfixes0-dev libxcb-xinput-dev libxcb-xkb-dev libxext-dev libxkbcommon-x11-dev libxrandr-dev lld-17 \ - llvm-17 nasm ninja-build patchelf pkg-config zlib1g-dev + libssl-dev libudev-dev libva-dev libwayland-dev libx11-dev libx11-xcb-dev libxcb1-dev libxcb-composite0-dev libxcb-cursor-dev libxcb-damage0-dev \ + libxcb-glx0-dev libxcb-icccm4-dev libxcb-image0-dev libxcb-keysyms1-dev libxcb-present-dev libxcb-randr0-dev libxcb-render0-dev libxcb-render-util0-dev \ + libxcb-shape0-dev libxcb-shm0-dev libxcb-sync-dev libxcb-util-dev libxcb-xfixes0-dev libxcb-xinput-dev libxcb-xkb-dev libxext-dev libxkbcommon-x11-dev \ + libxrandr-dev lld-17 llvm-17 nasm ninja-build patchelf pkg-config zlib1g-dev - name: Cache Dependencies id: cache-deps uses: actions/cache@v4.0.2 with: path: ~/deps - key: deps ${{ hashFiles('scripts/deps/build-dependencies-linux.sh') }} + key: deps ${{ hashFiles('scripts/deps/build-dependencies-linux.sh', 'scripts/deps/build-ffmpeg-linux.sh') }} - name: Build Dependencies if: steps.cache-deps.outputs.cache-hit != 'true' run: scripts/deps/build-dependencies-linux.sh "$HOME/deps" + - name: Build FFmpeg + if: steps.cache-deps.outputs.cache-hit != 'true' + run: scripts/deps/build-ffmpeg-linux.sh "$HOME/deps" + - name: Initialize build tag run: | echo '#pragma once' > src/scmversion/tag.h diff --git a/CMakeModules/FindFFMPEG.cmake b/CMakeModules/FindFFMPEG.cmake index 1f8a31351..f88201736 100644 --- a/CMakeModules/FindFFMPEG.cmake +++ b/CMakeModules/FindFFMPEG.cmake @@ -35,6 +35,7 @@ function (_ffmpeg_find component headername) "lib${component}/${headername}" PATHS "${FFMPEG_ROOT}/include" + "${CMAKE_PREFIX_PATH}/include" ~/Library/Frameworks /Library/Frameworks /usr/local/include @@ -60,6 +61,8 @@ function (_ffmpeg_find component headername) "${component}" PATHS "${FFMPEG_ROOT}/lib" + "${CMAKE_PREFIX_PATH}/lib" + "${CMAKE_PREFIX_PATH}/lib64" ~/Library/Frameworks /Library/Frameworks /usr/local/lib diff --git a/README.md b/README.md index 13b844f77..3a82000b6 100644 --- a/README.md +++ b/README.md @@ -160,12 +160,12 @@ Requirements: Ubuntu/Debian package names: ``` -build-essential clang cmake curl extra-cmake-modules git libasound2-dev libcurl4-openssl-dev libdbus-1-dev libdecor-0-dev libegl-dev libevdev-dev libfontconfig-dev libfreetype-dev libgtk-3-dev libgudev-1.0-dev libharfbuzz-dev libinput-dev libopengl-dev libpipewire-0.3-dev libpulse-dev libssl-dev libudev-dev libwayland-dev libx11-dev libx11-xcb-dev libxcb1-dev libxcb-composite0-dev libxcb-cursor-dev libxcb-damage0-dev libxcb-glx0-dev libxcb-icccm4-dev libxcb-image0-dev libxcb-keysyms1-dev libxcb-present-dev libxcb-randr0-dev libxcb-render0-dev libxcb-render-util0-dev libxcb-shape0-dev libxcb-shm0-dev libxcb-sync-dev libxcb-util-dev libxcb-xfixes0-dev libxcb-xinput-dev libxcb-xkb-dev libxext-dev libxkbcommon-x11-dev libxrandr-dev lld llvm nasm ninja-build pkg-config zlib1g-dev +autoconf automake build-essential clang cmake curl extra-cmake-modules git libasound2-dev libcurl4-openssl-dev libdbus-1-dev libdecor-0-dev libegl-dev libevdev-dev libfontconfig-dev libfreetype-dev libgtk-3-dev libgudev-1.0-dev libharfbuzz-dev libinput-dev libopengl-dev libpipewire-0.3-dev libpulse-dev libssl-dev libudev-dev libwayland-dev libx11-dev libx11-xcb-dev libxcb1-dev libxcb-composite0-dev libxcb-cursor-dev libxcb-damage0-dev libxcb-glx0-dev libxcb-icccm4-dev libxcb-image0-dev libxcb-keysyms1-dev libxcb-present-dev libxcb-randr0-dev libxcb-render0-dev libxcb-render-util0-dev libxcb-shape0-dev libxcb-shm0-dev libxcb-sync-dev libxcb-util-dev libxcb-xfixes0-dev libxcb-xinput-dev libxcb-xkb-dev libxext-dev libxkbcommon-x11-dev libxrandr-dev libtool lld llvm nasm ninja-build pkg-config zlib1g-dev ``` Fedora package names: ``` -alsa-lib-devel brotli-devel clang cmake dbus-devel egl-wayland-devel extra-cmake-modules fontconfig-devel gcc-c++ gtk3-devel libavcodec-free-devel libavformat-free-devel libavutil-free-devel libcurl-devel libdecor-devel libevdev-devel libICE-devel libinput-devel libSM-devel libswresample-free-devel libswscale-free-devel libX11-devel libXau-devel libxcb-devel libXcomposite-devel libXcursor-devel libXext-devel libXfixes-devel libXft-devel libXi-devel libxkbcommon-devel libxkbcommon-x11-devel libXpresent-devel libXrandr-devel libXrender-devel lld llvm make mesa-libEGL-devel mesa-libGL-devel nasm ninja-build openssl-devel patch pcre2-devel perl-Digest-SHA pipewire-devel pulseaudio-libs-devel systemd-devel wayland-devel xcb-util-cursor-devel xcb-util-devel xcb-util-errors-devel xcb-util-image-devel xcb-util-keysyms-devel xcb-util-renderutil-devel xcb-util-wm-devel xcb-util-xrm-devel zlib-devel +alsa-lib-devel autoconf automake brotli-devel clang cmake dbus-devel egl-wayland-devel extra-cmake-modules fontconfig-devel gcc-c++ gtk3-devel libavcodec-free-devel libavformat-free-devel libavutil-free-devel libcurl-devel libdecor-devel libevdev-devel libICE-devel libinput-devel libSM-devel libswresample-free-devel libswscale-free-devel libX11-devel libXau-devel libxcb-devel libXcomposite-devel libXcursor-devel libXext-devel libXfixes-devel libXft-devel libXi-devel libxkbcommon-devel libxkbcommon-x11-devel libXpresent-devel libXrandr-devel libXrender-devel libtool lld llvm make mesa-libEGL-devel mesa-libGL-devel nasm ninja-build openssl-devel patch pcre2-devel perl-Digest-SHA pipewire-devel pulseaudio-libs-devel systemd-devel wayland-devel xcb-util-cursor-devel xcb-util-devel xcb-util-errors-devel xcb-util-image-devel xcb-util-keysyms-devel xcb-util-renderutil-devel xcb-util-wm-devel xcb-util-xrm-devel zlib-devel ``` #### Building diff --git a/scripts/appimage/make-appimage.sh b/scripts/appimage/make-appimage.sh index 51ea6c03f..99bbb5766 100755 --- a/scripts/appimage/make-appimage.sh +++ b/scripts/appimage/make-appimage.sh @@ -56,6 +56,11 @@ APPDIRNAME=DuckStation.AppDir STRIP=strip declare -a MANUAL_LIBS=( + "libavcodec.so.61" + "libavformat.so.61" + "libavutil.so.59" + "libswscale.so.8" + "libswresample.so.5" "libdiscord-rpc.so" "libfreetype.so.6" "libshaderc_shared.so" diff --git a/scripts/deps/build-ffmpeg-linux.sh b/scripts/deps/build-ffmpeg-linux.sh new file mode 100755 index 000000000..70d844118 --- /dev/null +++ b/scripts/deps/build-ffmpeg-linux.sh @@ -0,0 +1,326 @@ +#!/usr/bin/env bash + +set -e + +if [ "$#" -lt 1 ]; then + echo "Syntax: $0 " + exit 1 +fi + +for arg in "$@"; do + if [ "$arg" == "-skip-download" ]; then + echo "Not downloading sources." + SKIP_DOWNLOAD=true + shift + elif [ "$arg" == "-skip-cleanup" ]; then + echo "Not removing build directory." + SKIP_CLEANUP=true + shift + elif [ "$arg" == "" ]; then + # Eat empty args. + shift + fi +done + +SCRIPTDIR=$(realpath $(dirname "${BASH_SOURCE[0]}")) +NPROCS="$(getconf _NPROCESSORS_ONLN)" +INSTALLDIR="$1" +if [ "${INSTALLDIR:0:1}" != "/" ]; then + INSTALLDIR="$PWD/$INSTALLDIR" +fi + +mkdir -p deps-build +cd deps-build + +DEPSINSTALLDIR="$PWD/ffmpeg-deps" +echo "Installation directory is $INSTALLDIR" +echo "FFmpeg dependencies directory is $DEPSINSTALLDIR" + +FFMPEG=7.0.2 +LAME=3.100 +LIBVPX=1.14.1 +FDK_AAC=0fc0e0e0b89de3becd5f099eae725f13eeecc0d1 +LIBAOM=3ab84a7710ee34db3e43b3e61c7d69ab80276a33 +LIBOGG=1.3.5 +LIBVORBIS=1.3.7 +LIBTHEORA=1.1.1 +FLAC=1.4.3 +SPEEX=1.2.0 +AMF=1.4.34 +OPUS=1.5.2 +SVT_AV1=2.2.1 + +# Encoder list from freedesktop SDK, which apparently came from Fedora. +# Disabled list: av1_qsv h264_qsv hevc_qsv mjpeg_qsv mpeg2_qsv vc1_qsv vp8_qsv vp9_qsv +# av1_nvenc h264_nvenc hevc_nvenc libxvid libtwolame libopenh264 libgsm libgsm_ms +# ilbc libilbc libopencore_amrnb libopenjpeg libvo_amrwbenc libjxl libcodec2 hap librav1e +FFMPEG_ENCODER_LIST=""\ +"a64multi a64multi5 aac libfdk_aac ac3 adpcm_adx "\ +"adpcm_argo adpcm_g722 adpcm_g726 adpcm_g726le adpcm_ima_alp adpcm_ima_amv "\ +"adpcm_ima_apm adpcm_ima_qt adpcm_ima_ssi adpcm_ima_wav adpcm_ima_ws adpcm_ms "\ +"adpcm_swf adpcm_yamaha alac alias_pix amv anull "\ +"apng ass asv1 asv2 av1_amf "\ +"av1_vaapi ayuv bitpacked bmp cinepak "\ +"cljr dca dfpwm dnxhd dpx dvbsub "\ +"dvdsub dvvideo exr ffv1 ffvhuff flac "\ +"flashsv flashsv2 flv g723_1 gif h261 "\ +"h263 h263_v4l2m2m h263p h264_amf "\ +"h264_v4l2m2m h264_vaapi hdr hevc_amf "\ +"hevc_v4l2m2m hevc_vaapi huffyuv jpegls "\ +"jpeg2000 libaom libaom_av1 libmp3lame "\ +"libopus libschroedinger libspeex libsvtav1 libtheora "\ +"libvorbis libvpx_vp8 libvpx_vp9 libwebp "\ +"libwebp_anim mjpeg mjpeg_vaapi mlp "\ +"mp2 mp2fixed mpeg1video mpeg2video mpeg2_vaapi "\ +"mpeg4 mpeg4_v4l2m2m msmpeg4v2 msmpeg4v3 msvideo1 nellymoser "\ +"opus pam pbm pcm_alaw pcm_f32be pcm_f32le "\ +"pcm_f64be pcm_f64le pcm_mulaw pcm_s16be pcm_s16be_planar pcm_s16le "\ +"pcm_s16le_planar pcm_s24be pcm_s24le pcm_s24le_planar pcm_s32be pcm_s32le "\ +"pcm_s32le_planar pcm_s8 pcm_s8_planar pcm_u16be pcm_u16le pcm_u24be "\ +"pcm_u24le pcm_u32be pcm_u32le pcm_u8 pcx pgm "\ +"pgmyuv phm png ppm qoi qtrle "\ +"r10k r210 ra_144 rawvideo roq roq_dpcm "\ +"rpza rv10 rv20 s302m sbc sgi "\ +"smc snow sonic sonic_ls speedhq srt "\ +"ssa subrip sunrast svq1 targa text "\ +"tiff truehd tta ttml utvideo v210 "\ +"v308 v408 v410 vc1_v4l2m2m vc2 "\ +"vnull vorbis vp8_v4l2m2m vp8_vaapi "\ +"vp9_vaapi wavpack wbmp webvtt wmav1 wmav2 "\ +"wmv1 wmv2 wrapped_avframe xbm xface xsub "\ +"xwd y41p yuv4 zlib zmbv" +FFMPEG_ENCODERS="" +for encoder in $FFMPEG_ENCODER_LIST; do + if [ -z "$FFMPEG_ENCODERS" ]; then + FFMPEG_ENCODERS="--enable-encoder=$encoder" + else + FFMPEG_ENCODERS="$FFMPEG_ENCODERS,$encoder" + fi +done + +if [ "$SKIP_DOWNLOAD" != true ]; then + if [ ! -f "ffmpeg-$FFMPEG.tar.xz" ]; then + curl -C - -L -O "https://ffmpeg.org/releases/ffmpeg-$FFMPEG.tar.xz" + fi + if [ ! -f "lame-$LAME.tar.gz" ]; then + curl -C - -L -o "lame-$LAME.tar.gz" "https://sourceforge.net/projects/lame/files/lame/$LAME/lame-$LAME.tar.gz/download" + fi + if [ ! -f "libvpx-$LIBVPX.tar.gz" ]; then + curl -C - -L -o "libvpx-$LIBVPX.tar.gz" "https://github.com/webmproject/libvpx/archive/refs/tags/v$LIBVPX.tar.gz" + fi + if [ ! -f "fdk-aac-stripped-$FDK_AAC.tar.gz" ]; then + curl -C - -L -o "fdk-aac-stripped-$FDK_AAC.tar.gz" "https://gitlab.freedesktop.org/wtaymans/fdk-aac-stripped/-/archive/$FDK_AAC/fdk-aac-stripped-$FDK_AAC.tar.gz" + fi + if [ ! -d "aom" ]; then + git clone https://aomedia.googlesource.com/aom + cd aom + git checkout "$LIBAOM" + cd .. + fi + if [ ! -f "libogg-$LIBOGG.tar.gz" ]; then + curl -C - -L -O "https://downloads.xiph.org/releases/ogg/libogg-$LIBOGG.tar.gz" + fi + if [ ! -f "libvorbis-$LIBVORBIS.tar.gz" ]; then + curl -C - -L -O "https://github.com/xiph/vorbis/releases/download/v$LIBVORBIS/libvorbis-$LIBVORBIS.tar.gz" + fi + if [ ! -f "libtheora-$LIBTHEORA.tar.bz2" ]; then + curl -C - -L -O "https://downloads.xiph.org/releases/theora/libtheora-$LIBTHEORA.tar.bz2" + fi + if [ ! -f "flac-$FLAC.tar.xz" ]; then + curl -C - -L -O "https://downloads.xiph.org/releases/flac/flac-$FLAC.tar.xz" + fi + if [ ! -f "speex-$SPEEX.tar.gz" ]; then + curl -C - -L -O "https://downloads.xiph.org/releases/speex/speex-$SPEEX.tar.gz" + fi + if [ ! -f "AMF-headers.tar.gz" ]; then + curl -C - -L -O "https://github.com/GPUOpen-LibrariesAndSDKs/AMF/releases/download/v$AMF/AMF-headers.tar.gz" + fi + if [ ! -f "opus-$OPUS.tar.gz" ]; then + curl -C - -L -O "https://downloads.xiph.org/releases/opus/opus-$OPUS.tar.gz" + fi + if [ ! -f "SVT-AV1-$SVT_AV1.tar.gz" ]; then + curl -C - -L -O "https://gitlab.com/AOMediaCodec/SVT-AV1/-/archive/v$SVT_AV1/SVT-AV1-$SVT_AV1.tar.gz" + fi +fi + +cat > SHASUMS <