From 589477ff49e7478790e1f450f54c555479057f50 Mon Sep 17 00:00:00 2001 From: Javernaut Date: Fri, 3 Nov 2023 16:57:41 +0100 Subject: [PATCH 01/12] Raw support of libx265 --- .github/workflows/compilability_check.yml | 2 +- scripts/libx265/build.sh | 28 +++++++++++++++++++++++ scripts/libx265/download.sh | 9 ++++++++ scripts/parse-arguments.sh | 5 ++++ 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100755 scripts/libx265/build.sh create mode 100755 scripts/libx265/download.sh diff --git a/.github/workflows/compilability_check.yml b/.github/workflows/compilability_check.yml index 3ddffe5..a6f1a53 100644 --- a/.github/workflows/compilability_check.yml +++ b/.github/workflows/compilability_check.yml @@ -19,4 +19,4 @@ jobs: run: | export ANDROID_SDK_HOME=$ANDROID_HOME export ANDROID_NDK_HOME=$ANDROID_NDK - ./ffmpeg-android-maker.sh -all-free -all-gpl -android=21 -abis=${{ matrix.abi }} \ No newline at end of file + ./ffmpeg-android-maker.sh -x265 -android=24 -abis=${{ matrix.abi }} \ No newline at end of file diff --git a/scripts/libx265/build.sh b/scripts/libx265/build.sh new file mode 100755 index 0000000..0dadc7f --- /dev/null +++ b/scripts/libx265/build.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +# libaom doesn't support building while being in its root directory +CMAKE_BUILD_DIR=libx265_build_${ANDROID_ABI} +rm -rf ${CMAKE_BUILD_DIR} +mkdir ${CMAKE_BUILD_DIR} +cd ${CMAKE_BUILD_DIR} + +${CMAKE_EXECUTABLE} ../source \ + -DANDROID_PLATFORM=${ANDROID_PLATFORM} \ + -DANDROID_ABI=${ANDROID_ABI} \ + -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \ + -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} \ + -DANDROID_ARM_NEON=1 \ + -DCONFIG_PIC=1 \ + -DCONFIG_RUNTIME_CPU_DETECT=0 \ + -DENABLE_TESTS=0 \ + -DENABLE_DOCS=0 \ + -DENABLE_TESTDATA=0 \ + -DENABLE_EXAMPLES=0 \ + -DENABLE_TOOLS=0 + +sed -i '' 's/-lpthread/-pthread/' CMakeFiles/cli.dir/link.txt +sed -i '' 's/-lpthread/-pthread/' CMakeFiles/x265-shared.dir/link.txt +sed -i '' 's/-lpthread/-pthread/' CMakeFiles/x265-static.dir/link.txt + +${MAKE_EXECUTABLE} -j${HOST_NPROC} +${MAKE_EXECUTABLE} install diff --git a/scripts/libx265/download.sh b/scripts/libx265/download.sh new file mode 100755 index 0000000..2d2a680 --- /dev/null +++ b/scripts/libx265/download.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +source ${SCRIPTS_DIR}/common-functions.sh + +LIBX265_VERSION=3.5 + +downloadTarArchive \ + "libx265" \ + "https://bitbucket.org/multicoreware/x265_git/downloads/x265_${LIBX265_VERSION}.tar.gz" \ No newline at end of file diff --git a/scripts/parse-arguments.sh b/scripts/parse-arguments.sh index 6bc4e6b..b8b8198 100755 --- a/scripts/parse-arguments.sh +++ b/scripts/parse-arguments.sh @@ -32,6 +32,7 @@ SUPPORTED_LIBRARIES_FREE=( # All GPL libraries that are supported SUPPORTED_LIBRARIES_GPL=( "libx264" + "libx265" ) for argument in "$@"; do @@ -113,6 +114,10 @@ for argument in "$@"; do EXTERNAL_LIBRARIES+=("libx264") FFMPEG_GPL_ENABLED=true ;; + --enable-libx265 | -x265) + EXTERNAL_LIBRARIES+=("libx265") + FFMPEG_GPL_ENABLED=true + ;; --enable-mbedtls | -mbedtls) EXTERNAL_LIBRARIES+=("mbedtls") ;; From a5d52631919eb9df345a208247eed40735e9b73f Mon Sep 17 00:00:00 2001 From: Javernaut Date: Fri, 3 Nov 2023 17:11:19 +0100 Subject: [PATCH 02/12] Possible fix for sed difference between Linux and Mac --- scripts/libx265/build.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/scripts/libx265/build.sh b/scripts/libx265/build.sh index 0dadc7f..32cb0ae 100755 --- a/scripts/libx265/build.sh +++ b/scripts/libx265/build.sh @@ -20,9 +20,17 @@ ${CMAKE_EXECUTABLE} ../source \ -DENABLE_EXAMPLES=0 \ -DENABLE_TOOLS=0 -sed -i '' 's/-lpthread/-pthread/' CMakeFiles/cli.dir/link.txt -sed -i '' 's/-lpthread/-pthread/' CMakeFiles/x265-shared.dir/link.txt -sed -i '' 's/-lpthread/-pthread/' CMakeFiles/x265-static.dir/link.txt +# TODO Make it prettier +if [[ "$OSTYPE" == "darwin"* ]]; then + sed -i '' 's/-lpthread/-pthread/' CMakeFiles/cli.dir/link.txt + sed -i '' 's/-lpthread/-pthread/' CMakeFiles/x265-shared.dir/link.txt + sed -i '' 's/-lpthread/-pthread/' CMakeFiles/x265-static.dir/link.txt +else + sed -i 's/-lpthread/-pthread/' CMakeFiles/cli.dir/link.txt + sed -i 's/-lpthread/-pthread/' CMakeFiles/x265-shared.dir/link.txt + sed -i 's/-lpthread/-pthread/' CMakeFiles/x265-static.dir/link.txt +fi + ${MAKE_EXECUTABLE} -j${HOST_NPROC} ${MAKE_EXECUTABLE} install From 454d3153de416d0bd4905192e302cb3ccd3f7250 Mon Sep 17 00:00:00 2001 From: Javernaut Date: Fri, 10 Nov 2023 14:24:29 +0100 Subject: [PATCH 03/12] Fix for getting the libfreetype --- scripts/libfreetype/download.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/libfreetype/download.sh b/scripts/libfreetype/download.sh index 1bf2019..070989c 100755 --- a/scripts/libfreetype/download.sh +++ b/scripts/libfreetype/download.sh @@ -6,4 +6,4 @@ FREETYPE_VERSION=2.13.2 downloadTarArchive \ "libfreetype" \ - "https://nav.dl.sourceforge.net/project/freetype/freetype2/${FREETYPE_VERSION}/freetype-${FREETYPE_VERSION}.tar.gz" + "https://download.savannah.gnu.org/releases/freetype/freetype-${FREETYPE_VERSION}.tar.gz" From 11b5b8f351dbb31528f60f3485f3b81b71672a5c Mon Sep 17 00:00:00 2001 From: Javernaut Date: Fri, 10 Nov 2023 14:43:00 +0100 Subject: [PATCH 04/12] Update mbedtls to 3.5.1 --- scripts/mbedtls/download.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/mbedtls/download.sh b/scripts/mbedtls/download.sh index e5dc228..b73d749 100755 --- a/scripts/mbedtls/download.sh +++ b/scripts/mbedtls/download.sh @@ -2,7 +2,7 @@ source ${SCRIPTS_DIR}/common-functions.sh -export MBEDTLS_VERSION=3.4.1 +export MBEDTLS_VERSION=3.5.1 downloadTarArchive \ "mbedtls" \ "https://github.com/Mbed-TLS/mbedtls/archive/refs/tags/v${MBEDTLS_VERSION}.tar.gz" \ From f070451fa24d0ffadd4b4a982e8a402cdcbcc96d Mon Sep 17 00:00:00 2001 From: Javernaut Date: Sat, 11 Nov 2023 08:29:07 +0100 Subject: [PATCH 05/12] Update FFmpeg default version to 6.1 --- README.md | 2 +- scripts/parse-arguments.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bb91d0a..67a9531 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ The script also produces `ffmpeg` and `ffprobe` executables that can be used in The main focus of ffmpeg-android-maker is to prepare shared libraries for seamless integration into an Android project. The script prepares the `output` directory that is meant to be used. And it's not the only thing this project does. -By default this script downloads and builds the FFmpeg **6.0**, but the version can be overridden. +By default this script downloads and builds the FFmpeg **6.1**, but the version can be overridden. The details of how this script is implemented are described in this series of posts: * [Part 1](https://proandroiddev.com/a-story-about-ffmpeg-in-android-part-i-compilation-898e4a249422) diff --git a/scripts/parse-arguments.sh b/scripts/parse-arguments.sh index 6bc4e6b..4e4df8a 100755 --- a/scripts/parse-arguments.sh +++ b/scripts/parse-arguments.sh @@ -9,7 +9,7 @@ ABIS_TO_BUILD=() API_LEVEL=19 SOURCE_TYPE=TAR -SOURCE_VALUE=6.0 +SOURCE_VALUE=6.1 EXTERNAL_LIBRARIES=() FFMPEG_GPL_ENABLED=false From 70b0d5d08397e8f0040d3c947f980546beaba19a Mon Sep 17 00:00:00 2001 From: Javernaut Date: Sat, 11 Nov 2023 09:02:23 +0100 Subject: [PATCH 06/12] Using android level 24 on CI --- .github/workflows/compilability_check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/compilability_check.yml b/.github/workflows/compilability_check.yml index 3ddffe5..50435db 100644 --- a/.github/workflows/compilability_check.yml +++ b/.github/workflows/compilability_check.yml @@ -19,4 +19,4 @@ jobs: run: | export ANDROID_SDK_HOME=$ANDROID_HOME export ANDROID_NDK_HOME=$ANDROID_NDK - ./ffmpeg-android-maker.sh -all-free -all-gpl -android=21 -abis=${{ matrix.abi }} \ No newline at end of file + ./ffmpeg-android-maker.sh -all-free -all-gpl -android=24 -abis=${{ matrix.abi }} \ No newline at end of file From 5a961c3f12370e0d084edf7a50cab4742b074def Mon Sep 17 00:00:00 2001 From: Javernaut Date: Sat, 11 Nov 2023 11:15:35 +0100 Subject: [PATCH 07/12] Fixing the mbedtls 3.5.1 building --- .github/workflows/compilability_check.yml | 2 +- scripts/mbedtls/android.cmake | 5 +++++ scripts/mbedtls/build.sh | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 scripts/mbedtls/android.cmake diff --git a/.github/workflows/compilability_check.yml b/.github/workflows/compilability_check.yml index 50435db..3ddffe5 100644 --- a/.github/workflows/compilability_check.yml +++ b/.github/workflows/compilability_check.yml @@ -19,4 +19,4 @@ jobs: run: | export ANDROID_SDK_HOME=$ANDROID_HOME export ANDROID_NDK_HOME=$ANDROID_NDK - ./ffmpeg-android-maker.sh -all-free -all-gpl -android=24 -abis=${{ matrix.abi }} \ No newline at end of file + ./ffmpeg-android-maker.sh -all-free -all-gpl -android=21 -abis=${{ matrix.abi }} \ No newline at end of file diff --git a/scripts/mbedtls/android.cmake b/scripts/mbedtls/android.cmake new file mode 100644 index 0000000..b7b6e59 --- /dev/null +++ b/scripts/mbedtls/android.cmake @@ -0,0 +1,5 @@ +include("$ENV{ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake") + +if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686") + set(CMAKE_C_FLAGS "-mpclmul -msse2 -maes") +endif() diff --git a/scripts/mbedtls/build.sh b/scripts/mbedtls/build.sh index 91b0c19..8fa6f67 100755 --- a/scripts/mbedtls/build.sh +++ b/scripts/mbedtls/build.sh @@ -11,7 +11,7 @@ cd ${CMAKE_BUILD_DIR} ${CMAKE_EXECUTABLE} .. \ -DANDROID_PLATFORM=${ANDROID_PLATFORM} \ -DANDROID_ABI=${ANDROID_ABI} \ - -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \ + -DCMAKE_TOOLCHAIN_FILE=${SCRIPTS_DIR}/mbedtls/android.cmake \ -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} \ -DENABLE_TESTING=0 From ca1e99000834d7fa2de403ed073e26cd32e99f5f Mon Sep 17 00:00:00 2001 From: Javernaut Date: Sat, 11 Nov 2023 11:28:19 +0100 Subject: [PATCH 08/12] Update NDK support to r26b --- .github/workflows/compilability_check.yml | 4 ++-- scripts/parse-arguments.sh | 2 +- tools/docker/Dockerfile | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/compilability_check.yml b/.github/workflows/compilability_check.yml index 3ddffe5..c51e2e5 100644 --- a/.github/workflows/compilability_check.yml +++ b/.github/workflows/compilability_check.yml @@ -18,5 +18,5 @@ jobs: - name: Executing the script run: | export ANDROID_SDK_HOME=$ANDROID_HOME - export ANDROID_NDK_HOME=$ANDROID_NDK - ./ffmpeg-android-maker.sh -all-free -all-gpl -android=21 -abis=${{ matrix.abi }} \ No newline at end of file + export ANDROID_NDK_HOME=$ANDROID_NDK_LATEST_HOME + ./ffmpeg-android-maker.sh -all-free -all-gpl -android=24 -abis=${{ matrix.abi }} \ No newline at end of file diff --git a/scripts/parse-arguments.sh b/scripts/parse-arguments.sh index 4e4df8a..29f65c4 100755 --- a/scripts/parse-arguments.sh +++ b/scripts/parse-arguments.sh @@ -7,7 +7,7 @@ # Can be overridden with specific arguments. # See the end of this file for more description. ABIS_TO_BUILD=() -API_LEVEL=19 +API_LEVEL=21 SOURCE_TYPE=TAR SOURCE_VALUE=6.1 EXTERNAL_LIBRARIES=() diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index 58b35d8..6367c23 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -3,7 +3,7 @@ FROM --platform=linux/amd64 ubuntu:22.04 # Arguments that can be overridden in 'docker build' command: # Versions of Android SDK and NDK. The CMake is installed via NDK. ARG VERSION_SDK=10406996 -ARG VERSION_NDK=25.2.9519653 +ARG VERSION_NDK=26.1.10909125 ARG VERSION_CMAKE=3.22.1 # Package to install via pip3 From 9913f34dbd58306ed6266cc5adc423e53e458352 Mon Sep 17 00:00:00 2001 From: Javernaut Date: Sat, 11 Nov 2023 13:41:55 +0100 Subject: [PATCH 09/12] Using openjdk-17 in Dockerfile --- tools/docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index 6367c23..c584bed 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -25,7 +25,7 @@ RUN apt-get --allow-releaseinfo-change update && apt-get install -y --no-install python3-wheel \ ninja-build \ build-essential \ - openjdk-8-jdk-headless \ + openjdk-17-jdk-headless \ curl \ unzip \ bash \ From d3eb7e4b0413e0b5680c52a6dd1c960046fe903e Mon Sep 17 00:00:00 2001 From: Javernaut Date: Sat, 11 Nov 2023 18:35:17 +0100 Subject: [PATCH 10/12] Libx265 integration improvement --- scripts/libx265/build.sh | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/scripts/libx265/build.sh b/scripts/libx265/build.sh index 32cb0ae..3e2da64 100755 --- a/scripts/libx265/build.sh +++ b/scripts/libx265/build.sh @@ -6,31 +6,31 @@ rm -rf ${CMAKE_BUILD_DIR} mkdir ${CMAKE_BUILD_DIR} cd ${CMAKE_BUILD_DIR} +EXTRA_CMAKE_ARG="" +case $ANDROID_ABI in + arm64-v8a|x86) + # Disabling assembler optimizations for certain ABIs. Not a good solution, but it at least works + EXTRA_CMAKE_ARG="-DENABLE_ASSEMBLY=OFF" + ;; +esac + ${CMAKE_EXECUTABLE} ../source \ -DANDROID_PLATFORM=${ANDROID_PLATFORM} \ -DANDROID_ABI=${ANDROID_ABI} \ -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \ -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} \ - -DANDROID_ARM_NEON=1 \ - -DCONFIG_PIC=1 \ - -DCONFIG_RUNTIME_CPU_DETECT=0 \ - -DENABLE_TESTS=0 \ - -DENABLE_DOCS=0 \ - -DENABLE_TESTDATA=0 \ - -DENABLE_EXAMPLES=0 \ - -DENABLE_TOOLS=0 + -DENABLE_PIC=ON \ + $EXTRA_CMAKE_ARG -# TODO Make it prettier +EXTRA_SED_ARG="" if [[ "$OSTYPE" == "darwin"* ]]; then - sed -i '' 's/-lpthread/-pthread/' CMakeFiles/cli.dir/link.txt - sed -i '' 's/-lpthread/-pthread/' CMakeFiles/x265-shared.dir/link.txt - sed -i '' 's/-lpthread/-pthread/' CMakeFiles/x265-static.dir/link.txt -else - sed -i 's/-lpthread/-pthread/' CMakeFiles/cli.dir/link.txt - sed -i 's/-lpthread/-pthread/' CMakeFiles/x265-shared.dir/link.txt - sed -i 's/-lpthread/-pthread/' CMakeFiles/x265-static.dir/link.txt + EXTRA_SED_ARG="''" fi +sed -i $EXTRA_SED_ARG 's/-lpthread/-pthread/' CMakeFiles/cli.dir/link.txt +sed -i $EXTRA_SED_ARG 's/-lpthread/-pthread/' CMakeFiles/x265-shared.dir/link.txt +sed -i $EXTRA_SED_ARG 's/-lpthread/-pthread/' CMakeFiles/x265-static.dir/link.txt +export FFMPEG_EXTRA_LD_FLAGS="${FFMPEG_EXTRA_LD_FLAGS} -lm -lc++" ${MAKE_EXECUTABLE} -j${HOST_NPROC} ${MAKE_EXECUTABLE} install From 08c6d96da864c7e498ffc26847babe19349ed17f Mon Sep 17 00:00:00 2001 From: Javernaut Date: Sat, 11 Nov 2023 18:42:39 +0100 Subject: [PATCH 11/12] Building all libraries on CI --- .github/workflows/compilability_check.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/compilability_check.yml b/.github/workflows/compilability_check.yml index 9435993..85a4439 100644 --- a/.github/workflows/compilability_check.yml +++ b/.github/workflows/compilability_check.yml @@ -1,5 +1,5 @@ name: Compilability check -on: [push, pull_request] +on: [ push, pull_request ] jobs: build: runs-on: ubuntu-22.04 @@ -19,4 +19,4 @@ jobs: run: | export ANDROID_SDK_HOME=$ANDROID_HOME export ANDROID_NDK_HOME=$ANDROID_NDK_LATEST_HOME - ./ffmpeg-android-maker.sh -x265 -android=24 -abis=${{ matrix.abi }} \ No newline at end of file + ./ffmpeg-android-maker.sh -all-free -all-gpl -android=24 -abis=${{ matrix.abi }} \ No newline at end of file From ec661864fe44c91bc799dfd65dcbc85af66e2bcf Mon Sep 17 00:00:00 2001 From: Javernaut Date: Sat, 11 Nov 2023 19:37:03 +0100 Subject: [PATCH 12/12] libx265 build improvement --- scripts/libx265/build.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/libx265/build.sh b/scripts/libx265/build.sh index 3e2da64..63d08c4 100755 --- a/scripts/libx265/build.sh +++ b/scripts/libx265/build.sh @@ -20,6 +20,8 @@ ${CMAKE_EXECUTABLE} ../source \ -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \ -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} \ -DENABLE_PIC=ON \ + -DENABLE_SHARED=OFF \ + -DENABLE_CLI=OFF \ $EXTRA_CMAKE_ARG EXTRA_SED_ARG=""