Cross compile FFmpeg with openssl and libsrt by android ndk

I am trying to cross-compile FFmpeg using the Android NDK and enable support for OpenSSL and libsrt. After separately compiling OpenSSL and libsrt, when configuring FFmpeg, pkg-config cannot correctly locate the installed OpenSSL and libsrt libraries.

Here are my compilation scripts.
OpenSSL 3.1.4

#!/bin/bash

if [[ ! -d "./openssl" ]]; then
    git clone --depth 1 --branch openssl-3.1.4 https://github.com/openssl/openssl.git
fi

cd openssl

export ANDROID_NDK_ROOT=/home/albert/workspace/DevKit/android/SDK/ndk/25.1.8937393/
PATH=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH

rm -rf ./android
make clean

./Configure android-arm64 \
 -D__ANDROID_API__=28 \
--prefix=$PWD/android/arm64-v8a

make -j $(grep "cpu cores" /proc/cpuinfo | wc -l)
make install

cd ..

libsrt 1.5.3

#!/bin/bash

if [[ ! -d "./srt" ]]; then
    git clone --depth 1 --branch v1.5.3 https://github.com/Haivision/srt.git
fi

export OpenSSL_INSTALL_DIR=$PWD/openssl/android/arm64-v8a

cd srt

rm -rf ./android
make clean

./configure --use-enclib=openssl \
--use-openssl-pc=OFF \
--OPENSSL_INCLUDE_DIR=$OpenSSL_INSTALL_DIR/include \
--OPENSSL_CRYPTO_LIBRARY=$OpenSSL_INSTALL_DIR/lib/libcrypto.a \
--OPENSSL_SSL_LIBRARY=$OpenSSL_INSTALL_DIR/lib/libssl.a \
--CMAKE_PREFIX_PATH=$PWD/install/android/arm64-v8a \
--CMAKE_INSTALL_PREFIX=$PWD/install/android/arm64-v8a \
--CMAKE_ANDROID_NDK=/home/albert/workspace/DevKit/android/SDK/ndk/25.1.8937393 \
--CMAKE_SYSTEM_NAME=Android \
--CMAKE_SYSTEM_VERSION=28 \
--CMAKE_ANDROID_ARCH_ABI=arm64-v8a \
--CMAKE_C_FLAGS="-fPIC" \
--enable-c++11 \
--enable-stdcxx-sync \
--enable-debug=2 \
--enable-logging=0 \
--enable-heavy-logging=0 \
--enable-apps=0

make -j $(grep "cpu cores" /proc/cpuinfo | wc -l)
make install

cd ..

Then I put those install dir to PKG_CONFIG_PATH

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$PWD/openssl/android/arm64-v8a/lib/pkgconfig:$PWD/srt/install/android/arm64-v8a/lib/pkgconfig

Upon testing, both OpenSSL and SRT can successfully retrieve the version and corresponding linking symbols.

But, When I’m going to configure FFmpeg, Error Occurred

My FFmpeg configurtion script

TOOLCHAIN=/home/albert/workspace/DevKit/android/SDK/ndk/25.1.8937393/toolchains/llvm/prebuilt/linux-x86_64
API=28

./configure \
 --prefix=$PWD/android/arm64-v8a \
 --disable-neon \
 --disable-hwaccels \
 --disable-gpl \
 --disable-postproc \
 --enable-static \
 --enable-jni \
 --disable-mediacodec \
 --disable-decoder=h264_mediacodec \
 --disable-doc \
 --disable-programs \
 --disable-ffmpeg \
 --disable-ffplay \
 --disable-ffprobe \
 --disable-avdevice \
 --disable-symver \
 --cross-prefix=$TOOLCHAIN/bin/llvm- \
 --target-os=android \
 --arch=arm64 \
 --cpu=armv8-a \
 --cc=$TOOLCHAIN/bin/aarch64-linux-android$API-clang \
 --cxx=$TOOLCHAIN/bin/aarch64-linux-android$API-clang++ \
 --enable-cross-compile \
 --sysroot=$TOOLCHAIN/sysroot \
 --enable-version3 \
 --enable-openssl \
 --enable-libsrt \
 --extra-cflags="-DVK_ENABLE_BETA_EXTENSIONS=0 -mno-stackrealign -Os -fpic -march=armv8-a " \
 --extra-ldflags="" \
 $ADDITIONAL_CONFIGURE_FLAG
ERROR: srt >= 1.3.0 not found using pkg-config

config.log

require_pkg_config libsrt srt >= 1.3.0 srt/srt.h srt_socket
check_pkg_config libsrt srt >= 1.3.0 srt/srt.h srt_socket
test_pkg_config libsrt srt >= 1.3.0 srt/srt.h srt_socket
false --exists --print-errors srt >= 1.3.0
ERROR: srt >= 1.3.0 not found using pkg-config

If only enable OpenSSL, then get Error

ERROR: OpenSSL <3.0.0 is incompatible with the gpl

config.log

check_pkg_config openssl openssl >= 3.0.0 openssl/ssl.h OPENSSL_init_ssl
test_pkg_config openssl openssl >= 3.0.0 openssl/ssl.h OPENSSL_init_ssl
false --exists --print-errors openssl >= 3.0.0
ERROR: OpenSSL <3.0.0 is incompatible with the gpl

Leave a Comment