From 0fc62bfcd63fdccba759c1421ca7e4b5a2278cb9 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Mon, 27 Feb 2023 21:43:48 +0100 Subject: [PATCH] Use minimal prebuilt FFmpeg for Windows On the scrcpy-deps repo, I built FFmpeg 5.1.2 binaries for Windows with only the features used by scrcpy. For comparison, here are the sizes of the dll for FFmpeg 5.1.2: - before: 89M - after: 4.7M It also allows to upgrade the old FFmpeg version (4.3.1) used for win32. Refs Refs --- app/meson.build | 11 ++---- app/prebuilt-deps/prepare-ffmpeg-win32.sh | 45 ----------------------- app/prebuilt-deps/prepare-ffmpeg-win64.sh | 36 ------------------ app/prebuilt-deps/prepare-ffmpeg.sh | 30 +++++++++++++++ cross_win32.txt | 5 +-- cross_win64.txt | 5 +-- release.mk | 36 ++++++++---------- 7 files changed, 50 insertions(+), 118 deletions(-) delete mode 100755 app/prebuilt-deps/prepare-ffmpeg-win32.sh delete mode 100755 app/prebuilt-deps/prepare-ffmpeg-win64.sh create mode 100755 app/prebuilt-deps/prepare-ffmpeg.sh diff --git a/app/meson.build b/app/meson.build index a16a000b..f070db72 100644 --- a/app/meson.build +++ b/app/meson.build @@ -129,16 +129,11 @@ else ffmpeg_bin_dir = meson.current_source_dir() + '/prebuilt-deps/data/' + prebuilt_ffmpeg + '/bin' ffmpeg_include_dir = 'prebuilt-deps/data/' + prebuilt_ffmpeg + '/include' - # ffmpeg versions are different for win32 and win64 builds - ffmpeg_avcodec = meson.get_cross_property('ffmpeg_avcodec') - ffmpeg_avformat = meson.get_cross_property('ffmpeg_avformat') - ffmpeg_avutil = meson.get_cross_property('ffmpeg_avutil') - ffmpeg = declare_dependency( dependencies: [ - cc.find_library(ffmpeg_avcodec, dirs: ffmpeg_bin_dir), - cc.find_library(ffmpeg_avformat, dirs: ffmpeg_bin_dir), - cc.find_library(ffmpeg_avutil, dirs: ffmpeg_bin_dir), + cc.find_library('avcodec-59', dirs: ffmpeg_bin_dir), + cc.find_library('avformat-59', dirs: ffmpeg_bin_dir), + cc.find_library('avutil-57', dirs: ffmpeg_bin_dir), ], include_directories: include_directories(ffmpeg_include_dir) ) diff --git a/app/prebuilt-deps/prepare-ffmpeg-win32.sh b/app/prebuilt-deps/prepare-ffmpeg-win32.sh deleted file mode 100755 index 2a6a3841..00000000 --- a/app/prebuilt-deps/prepare-ffmpeg-win32.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env bash -set -e -DIR=$(dirname ${BASH_SOURCE[0]}) -cd "$DIR" -. common -mkdir -p "$PREBUILT_DATA_DIR" -cd "$PREBUILT_DATA_DIR" - -DEP_DIR=ffmpeg-win32-4.3.1 - -FILENAME_SHARED=ffmpeg-4.3.1-win32-shared.zip -SHA256SUM_SHARED=357af9901a456f4dcbacd107e83a934d344c9cb07ddad8aaf80612eeab7d26d2 - -FILENAME_DEV=ffmpeg-4.3.1-win32-dev.zip -SHA256SUM_DEV=230efb08e9bcf225bd474da29676c70e591fc94d8790a740ca801408fddcb78b - -if [[ -d "$DEP_DIR" ]] -then - echo "$DEP_DIR" found - exit 0 -fi - -get_file "https://github.com/Genymobile/scrcpy/releases/download/v1.16/$FILENAME_SHARED" \ - "$FILENAME_SHARED" "$SHA256SUM_SHARED" -get_file "https://github.com/Genymobile/scrcpy/releases/download/v1.16/$FILENAME_DEV" \ - "$FILENAME_DEV" "$SHA256SUM_DEV" - -mkdir "$DEP_DIR" -cd "$DEP_DIR" - -ZIP_PREFIX_SHARED=ffmpeg-4.3.1-win32-shared -unzip "../$FILENAME_SHARED" \ - "$ZIP_PREFIX_SHARED"/bin/avutil-56.dll \ - "$ZIP_PREFIX_SHARED"/bin/avcodec-58.dll \ - "$ZIP_PREFIX_SHARED"/bin/avformat-58.dll \ - "$ZIP_PREFIX_SHARED"/bin/swresample-3.dll \ - "$ZIP_PREFIX_SHARED"/bin/swscale-5.dll - -ZIP_PREFIX_DEV=ffmpeg-4.3.1-win32-dev -unzip "../$FILENAME_DEV" \ - "$ZIP_PREFIX_DEV/include/*" - -mv "$ZIP_PREFIX_SHARED"/* . -mv "$ZIP_PREFIX_DEV"/* . -rmdir "$ZIP_PREFIX_SHARED" "$ZIP_PREFIX_DEV" diff --git a/app/prebuilt-deps/prepare-ffmpeg-win64.sh b/app/prebuilt-deps/prepare-ffmpeg-win64.sh deleted file mode 100755 index f5d56e6f..00000000 --- a/app/prebuilt-deps/prepare-ffmpeg-win64.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -set -e -DIR=$(dirname ${BASH_SOURCE[0]}) -cd "$DIR" -. common -mkdir -p "$PREBUILT_DATA_DIR" -cd "$PREBUILT_DATA_DIR" - -VERSION=5.1.2 -DEP_DIR=ffmpeg-win64-$VERSION - -FILENAME=ffmpeg-$VERSION-full_build-shared.7z -SHA256SUM=d9eb97b72d7cfdae4d0f7eaea59ccffb8c364d67d88018ea715d5e2e193f00e9 - -if [[ -d "$DEP_DIR" ]] -then - echo "$DEP_DIR" found - exit 0 -fi - -get_file "https://github.com/GyanD/codexffmpeg/releases/download/$VERSION/$FILENAME" \ - "$FILENAME" "$SHA256SUM" - -mkdir "$DEP_DIR" -cd "$DEP_DIR" - -ZIP_PREFIX=ffmpeg-$VERSION-full_build-shared -7z x "../$FILENAME" \ - "$ZIP_PREFIX"/bin/avutil-57.dll \ - "$ZIP_PREFIX"/bin/avcodec-59.dll \ - "$ZIP_PREFIX"/bin/avformat-59.dll \ - "$ZIP_PREFIX"/bin/swresample-4.dll \ - "$ZIP_PREFIX"/bin/swscale-6.dll \ - "$ZIP_PREFIX"/include -mv "$ZIP_PREFIX"/* . -rmdir "$ZIP_PREFIX" diff --git a/app/prebuilt-deps/prepare-ffmpeg.sh b/app/prebuilt-deps/prepare-ffmpeg.sh new file mode 100755 index 00000000..dc8b1ca2 --- /dev/null +++ b/app/prebuilt-deps/prepare-ffmpeg.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +set -e +DIR=$(dirname ${BASH_SOURCE[0]}) +cd "$DIR" +. common +mkdir -p "$PREBUILT_DATA_DIR" +cd "$PREBUILT_DATA_DIR" + +VERSION=5.1.2-scrcpy +DEP_DIR="ffmpeg-$VERSION" + +FILENAME="$DEP_DIR".7z +SHA256SUM=93f32ffc29ddb3466d669f7078d3fd8030c3388bc8a18bcfeefb6428fc5ceef1 + +if [[ -d "$DEP_DIR" ]] +then + echo "$DEP_DIR" found + exit 0 +fi + +get_file "https://github.com/rom1v/scrcpy-deps/releases/download/$VERSION/$FILENAME" \ + "$FILENAME" "$SHA256SUM" + +mkdir "$DEP_DIR" +cd "$DEP_DIR" + +ZIP_PREFIX=ffmpeg +7z x "../$FILENAME" +mv "$ZIP_PREFIX"/* . +rmdir "$ZIP_PREFIX" diff --git a/cross_win32.txt b/cross_win32.txt index e50c0bc8..f89463d9 100644 --- a/cross_win32.txt +++ b/cross_win32.txt @@ -16,9 +16,6 @@ cpu = 'i686' endian = 'little' [properties] -ffmpeg_avcodec = 'avcodec-58' -ffmpeg_avformat = 'avformat-58' -ffmpeg_avutil = 'avutil-56' -prebuilt_ffmpeg = 'ffmpeg-win32-4.3.1' +prebuilt_ffmpeg = 'ffmpeg-5.1.2-scrcpy/win32' prebuilt_sdl2 = 'SDL2-2.26.1/i686-w64-mingw32' prebuilt_libusb = 'libusb-1.0.26/libusb-MinGW-Win32' diff --git a/cross_win64.txt b/cross_win64.txt index 2dc876a6..c30c46f2 100644 --- a/cross_win64.txt +++ b/cross_win64.txt @@ -16,9 +16,6 @@ cpu = 'x86_64' endian = 'little' [properties] -ffmpeg_avcodec = 'avcodec-59' -ffmpeg_avformat = 'avformat-59' -ffmpeg_avutil = 'avutil-57' -prebuilt_ffmpeg = 'ffmpeg-win64-5.1.2' +prebuilt_ffmpeg = 'ffmpeg-5.1.2-scrcpy/win64' prebuilt_sdl2 = 'SDL2-2.26.1/x86_64-w64-mingw32' prebuilt_libusb = 'libusb-1.0.26/libusb-MinGW-x64' diff --git a/release.mk b/release.mk index 67578022..9c2820c7 100644 --- a/release.mk +++ b/release.mk @@ -11,7 +11,7 @@ .PHONY: default clean \ test \ build-server \ - prepare-deps-win32 prepare-deps-win64 \ + prepare-deps \ build-win32 build-win64 \ dist-win32 dist-win64 \ zip-win32 zip-win64 \ @@ -62,19 +62,13 @@ build-server: meson setup "$(SERVER_BUILD_DIR)" --buildtype release -Dcompile_app=false ) ninja -C "$(SERVER_BUILD_DIR)" -prepare-deps-win32: +prepare-deps: @app/prebuilt-deps/prepare-adb.sh @app/prebuilt-deps/prepare-sdl.sh - @app/prebuilt-deps/prepare-ffmpeg-win32.sh + @app/prebuilt-deps/prepare-ffmpeg.sh @app/prebuilt-deps/prepare-libusb.sh -prepare-deps-win64: - @app/prebuilt-deps/prepare-adb.sh - @app/prebuilt-deps/prepare-sdl.sh - @app/prebuilt-deps/prepare-ffmpeg-win64.sh - @app/prebuilt-deps/prepare-libusb.sh - -build-win32: prepare-deps-win32 +build-win32: prepare-deps [ -d "$(WIN32_BUILD_DIR)" ] || ( mkdir "$(WIN32_BUILD_DIR)" && \ meson setup "$(WIN32_BUILD_DIR)" \ --cross-file cross_win32.txt \ @@ -83,7 +77,7 @@ build-win32: prepare-deps-win32 -Dportable=true ) ninja -C "$(WIN32_BUILD_DIR)" -build-win64: prepare-deps-win64 +build-win64: prepare-deps [ -d "$(WIN64_BUILD_DIR)" ] || ( mkdir "$(WIN64_BUILD_DIR)" && \ meson setup "$(WIN64_BUILD_DIR)" \ --cross-file cross_win64.txt \ @@ -100,11 +94,11 @@ dist-win32: build-server build-win32 cp app/data/scrcpy-noconsole.vbs "$(DIST)/$(WIN32_TARGET_DIR)" cp app/data/icon.png "$(DIST)/$(WIN32_TARGET_DIR)" cp app/data/open_a_terminal_here.bat "$(DIST)/$(WIN32_TARGET_DIR)" - cp app/prebuilt-deps/data/ffmpeg-win32-4.3.1/bin/avutil-56.dll "$(DIST)/$(WIN32_TARGET_DIR)/" - cp app/prebuilt-deps/data/ffmpeg-win32-4.3.1/bin/avcodec-58.dll "$(DIST)/$(WIN32_TARGET_DIR)/" - cp app/prebuilt-deps/data/ffmpeg-win32-4.3.1/bin/avformat-58.dll "$(DIST)/$(WIN32_TARGET_DIR)/" - cp app/prebuilt-deps/data/ffmpeg-win32-4.3.1/bin/swresample-3.dll "$(DIST)/$(WIN32_TARGET_DIR)/" - cp app/prebuilt-deps/data/ffmpeg-win32-4.3.1/bin/swscale-5.dll "$(DIST)/$(WIN32_TARGET_DIR)/" + cp app/prebuilt-deps/data/ffmpeg-5.1.2-scrcpy/win32/bin/avutil-57.dll "$(DIST)/$(WIN32_TARGET_DIR)/" + cp app/prebuilt-deps/data/ffmpeg-5.1.2-scrcpy/win32/bin/avcodec-59.dll "$(DIST)/$(WIN32_TARGET_DIR)/" + cp app/prebuilt-deps/data/ffmpeg-5.1.2-scrcpy/win32/bin/avformat-59.dll "$(DIST)/$(WIN32_TARGET_DIR)/" + cp app/prebuilt-deps/data/ffmpeg-5.1.2-scrcpy/win32/bin/swresample-4.dll "$(DIST)/$(WIN32_TARGET_DIR)/" + cp app/prebuilt-deps/data/ffmpeg-5.1.2-scrcpy/win32/bin/zlib1.dll "$(DIST)/$(WIN32_TARGET_DIR)/" cp app/prebuilt-deps/data/platform-tools-33.0.3/adb.exe "$(DIST)/$(WIN32_TARGET_DIR)/" cp app/prebuilt-deps/data/platform-tools-33.0.3/AdbWinApi.dll "$(DIST)/$(WIN32_TARGET_DIR)/" cp app/prebuilt-deps/data/platform-tools-33.0.3/AdbWinUsbApi.dll "$(DIST)/$(WIN32_TARGET_DIR)/" @@ -119,11 +113,11 @@ dist-win64: build-server build-win64 cp app/data/scrcpy-noconsole.vbs "$(DIST)/$(WIN64_TARGET_DIR)" cp app/data/icon.png "$(DIST)/$(WIN64_TARGET_DIR)" cp app/data/open_a_terminal_here.bat "$(DIST)/$(WIN64_TARGET_DIR)" - cp app/prebuilt-deps/data/ffmpeg-win64-5.1.2/bin/avutil-57.dll "$(DIST)/$(WIN64_TARGET_DIR)/" - cp app/prebuilt-deps/data/ffmpeg-win64-5.1.2/bin/avcodec-59.dll "$(DIST)/$(WIN64_TARGET_DIR)/" - cp app/prebuilt-deps/data/ffmpeg-win64-5.1.2/bin/avformat-59.dll "$(DIST)/$(WIN64_TARGET_DIR)/" - cp app/prebuilt-deps/data/ffmpeg-win64-5.1.2/bin/swresample-4.dll "$(DIST)/$(WIN64_TARGET_DIR)/" - cp app/prebuilt-deps/data/ffmpeg-win64-5.1.2/bin/swscale-6.dll "$(DIST)/$(WIN64_TARGET_DIR)/" + cp app/prebuilt-deps/data/ffmpeg-5.1.2-scrcpy/win64/bin/avutil-57.dll "$(DIST)/$(WIN64_TARGET_DIR)/" + cp app/prebuilt-deps/data/ffmpeg-5.1.2-scrcpy/win64/bin/avcodec-59.dll "$(DIST)/$(WIN64_TARGET_DIR)/" + cp app/prebuilt-deps/data/ffmpeg-5.1.2-scrcpy/win64/bin/avformat-59.dll "$(DIST)/$(WIN64_TARGET_DIR)/" + cp app/prebuilt-deps/data/ffmpeg-5.1.2-scrcpy/win64/bin/swresample-4.dll "$(DIST)/$(WIN64_TARGET_DIR)/" + cp app/prebuilt-deps/data/ffmpeg-5.1.2-scrcpy/win64/bin/zlib1.dll "$(DIST)/$(WIN64_TARGET_DIR)/" cp app/prebuilt-deps/data/platform-tools-33.0.3/adb.exe "$(DIST)/$(WIN64_TARGET_DIR)/" cp app/prebuilt-deps/data/platform-tools-33.0.3/AdbWinApi.dll "$(DIST)/$(WIN64_TARGET_DIR)/" cp app/prebuilt-deps/data/platform-tools-33.0.3/AdbWinUsbApi.dll "$(DIST)/$(WIN64_TARGET_DIR)/"