From ddbc65901d357d0f7ddeaab29a371bfef691b7e7 Mon Sep 17 00:00:00 2001 From: Javernaut Date: Fri, 2 Aug 2019 21:21:38 +0300 Subject: [PATCH 1/2] Adding possibility to set the FFmpeg version to use --- ffmpeg-android-maker.sh | 63 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 5 deletions(-) diff --git a/ffmpeg-android-maker.sh b/ffmpeg-android-maker.sh index f466aab..33994a2 100755 --- a/ffmpeg-android-maker.sh +++ b/ffmpeg-android-maker.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -FFMPEG_VERSION=4.1.4 +FFMPEG_FALLBACK_VERSION=4.1.4 # Assuming the script is used on macOS or Linux machine case "$OSTYPE" in @@ -11,7 +11,6 @@ esac # Directories used by the script BASE_DIR="$( cd "$( dirname "$0" )" && pwd )" SOURCES_DIR=${BASE_DIR}/sources -FFMPEG_SOURCES=${SOURCES_DIR}/ffmpeg-${FFMPEG_VERSION} OUTPUT_DIR=${BASE_DIR}/output BUILD_DIR=${BASE_DIR}/build STATS_DIR=${BASE_DIR}/stats @@ -23,8 +22,13 @@ rm -rf ${OUTPUT_DIR} mkdir -p ${STATS_DIR} mkdir -p ${OUTPUT_DIR} -# Test if sources of the FFmpeg exist. If not - download them -function ensureSources() { +# Getting sources of a particular ffmpeg release. +# Same argument (ffmpeg version) produces the same source set. +function ensureSourcesTag() { + FFMPEG_VERSION=$1 + + FFMPEG_SOURCES=${SOURCES_DIR}/ffmpeg-${FFMPEG_VERSION} + if [[ ! -d "$FFMPEG_SOURCES" ]]; then TARGET_FILE_NAME=ffmpeg-${FFMPEG_VERSION}.tar.bz2 TARGET_FILE_PATH=${SOURCES_DIR}/${TARGET_FILE_NAME} @@ -36,6 +40,55 @@ function ensureSources() { fi } +# Getting sources of a particular branch of ffmpeg's git repository. +# Same argument (branch name) may produce different source set, +# as the branch in origin repository may be updated in future. +function ensureSourcesBranch() { + BRANCH=$1 + + GIT_DIRECTORY=ffmpeg-git + + FFMPEG_SOURCES=${SOURCES_DIR}/${GIT_DIRECTORY} + + cd ${SOURCES_DIR} + + if [[ ! -d "$FFMPEG_SOURCES" ]]; then + git clone https://git.ffmpeg.org/ffmpeg.git ${GIT_DIRECTORY} + fi + + cd ${GIT_DIRECTORY} + git checkout $BRANCH + # Forcing the update of a branch + git pull origin $BRANCH + + # Additional logging to keep track of an exact commit to build + echo "Commit to build:" + git rev-parse HEAD + + cd ${BASE_DIR} +} + +# Test if sources of the FFmpeg exist. If not - download them +function ensureSources() { + TYPE=$1 + SECOND_ARGUMENT=$2 + + case $TYPE in + tag) + echo "Using FFmpeg ${SECOND_ARGUMENT}" + ensureSourcesTag ${SECOND_ARGUMENT} + ;; + branch) + echo "Using FFmpeg git repository and its branch ${SECOND_ARGUMENT}" + ensureSourcesBranch ${SECOND_ARGUMENT} + ;; + *) + echo "Using FFmpeg 4.1.4" + ensureSourcesTag ${FFMPEG_FALLBACK_VERSION} + ;; + esac +} + # Actual magic of configuring and compiling of FFmpeg for a certain architecture. # Supported architectures are: armeabi-v7a, arm64-v8a, x86 and x86_64 function assemble() { @@ -153,7 +206,7 @@ function installHeaders() { # Actual work -ensureSources +ensureSources $1 $2 build armeabi-v7a 16 build arm64-v8a 21 From fe6ab94ff36b4b68c6d735ee6fe024e0fabe6b47 Mon Sep 17 00:00:00 2001 From: Javernaut Date: Fri, 2 Aug 2019 21:41:05 +0300 Subject: [PATCH 2/2] Updating README.md to mention the possibility to set the version of FFmpeg --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 191bcb2..d28d337 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Here is a script that downloads the source code of [FFmpeg](https://www.ffmpeg.org) library and assembles it for Android. The script produces shared libraries as well as header files. The output structure looks like this: The actual content of all this directories depends on how the FFmpeg was configured before assembling. For my purpose I enabled only *libavcodec*, *libavformat*, *libavutil* and *libswscale*, but you can set your own configuration to make the FFmpeg you need. -The version of FFmpeg here is **4.1.4**. And the script expects to use **at least** Android NDK **r19** (*r20* also works ok). Starting with FFmpeg 4.1 and NDK r19 the whole process became much simpler. +The version of FFmpeg here by default is **4.1.4** (but can be overridden). And the script expects to use **at least** Android NDK **r19** (*r20* also works ok). Starting with FFmpeg 4.1 and NDK r19 the whole process became much simpler. ## Supported architectures @@ -24,4 +24,6 @@ And the actual Android app can be found [here](https://github.com/Javernaut/What ## Features +**Setting your own FFmpeg version**. You can actually override the version of FFmpeg used by the script. See details [here](https://github.com/Javernaut/ffmpeg-android-maker/wiki/Invocation-parameters). + **Text relocations monitoring**. After a build you can look into stats/text-relocations.txt file. That file lists all *.so files that were built and reports if they have text relocations. If you don't see any mentioning of 'TEXTREL' in the file, you are good. Otherwise, you will see exact binaries that have this problem.