ffmpeg-android-maker icon indicating copy to clipboard operation
ffmpeg-android-maker copied to clipboard

I try to enable srt in ffmpeg but i cannot compile ffmpeg

Open ciccio14 opened this issue 1 year ago • 7 comments

I tried to enable libsrt for ffmpeg using the istructions:

i added this line:

  --enable-libsrt | -srt)
    EXTERNAL_LIBRARIES+=("libsrt")
    ;;

to parse-arguments.sh

i created libsrt directory under scripts i create download.sh like this:

#!/usr/bin/env bash

# Script to download SRT's source code
# Relies on SRT_SOURCE_TYPE and SRT_SOURCE_VALUE variables
# to choose the valid origin and version

# Exports SOURCES_DIR_srt - path where actual sources are stored

# Getting sources of a particular SRT release.
# Same argument (SRT version) produces the same source set.
function ensureSourcesTar() {
  source ${SCRIPTS_DIR}/common-functions.sh

  downloadTarArchive \
    "srt" \
    "https://github.com/Haivision/srt/archive/refs/tags/${SRT_SOURCE_VALUE}.tar.gz"
}

# Getting sources of a particular branch or a tag of SRT's git repository.
# Same branch name may produce different source sets,
# as the branch in the origin repository may be updated in the future.
# Git tags lead to stable states of the source code.
function ensureSourcesGit() {
  NAME_TO_CHECKOUT=${SRT_SOURCE_VALUE}
  GIT_DIRECTORY=srt-git
  SRT_SOURCES=$(pwd)/${GIT_DIRECTORY}

  if [[ ! -d "$SRT_SOURCES" ]]; then
    git clone https://github.com/Haivision/srt.git ${GIT_DIRECTORY}
  fi

  cd ${GIT_DIRECTORY}
  git reset --hard

  git checkout $NAME_TO_CHECKOUT
  if [ ${SRT_SOURCE_TYPE} = "GIT_BRANCH" ]; then
    # Forcing the update of a branch
    git pull origin $NAME_TO_CHECKOUT
  fi

  # Additional logging to keep track of the exact commit to build
  echo "Commit to build:"
  git rev-parse HEAD

  export SOURCES_DIR_srt=${SRT_SOURCES}
}

# Actual code
case ${SRT_SOURCE_TYPE} in
  GIT_TAG)
    echo "Using SRT git tag: ${SRT_SOURCE_VALUE}"
    ensureSourcesGit
    ;;
  GIT_BRANCH)
    echo "Using SRT git repository and its branch: ${SRT_SOURCE_VALUE}"
    ensureSourcesGit
    ;;
  TAR)
    echo "Using SRT source archive: ${SRT_SOURCE_VALUE}"
    ensureSourcesTar
    ;;
esac

then i created the build.sh script:

#!/usr/bin/env bash

cmake -DENABLE_SHARED=1 -DCMAKE_INSTALL_PREFIX=/home/tommaso/lavoro/mine/progetti/ffmpeg-android/ffmpeg-android-maker/scripts/libsrt

${MAKE_EXECUTABLE} clean
${MAKE_EXECUTABLE} -j${HOST_NPROC}
${MAKE_EXECUTABLE} install

but when i try to compile the compiler seems to ignore my configuration. i also already installed libsrt in my ubuntu machine but if i try to add --enable-libsrt \ to build.sh of ffmpeg, the compile fails

Building the component: ffmpeg
ERROR: srt >= 1.3.0 not found using pkg-config

even if pkgconf finds the library installed:

pkgconf --modversion srt
1.5.4

ciccio14 avatar Apr 01 '25 16:04 ciccio14

I see you missed quite a lot of stuff that happens in other scripts of this project:

  • you don't use android toolchain for cmake. Here you can see an example of how this is done. Basically you build srt for you host environment and not for android. Please, adjust your script.
  • Please use the env variables like the script above. Yeah, I know their discoverability is not ideal, but they ensure you work in a proper directory for individual ABI. This matters, as cmake creates separate build directories for each ABI.
  • your local pkgconf has nothing to do with ffmpeg building process. And the message "ERROR: srt >= 1.3.0 not found using pkg-config" is actually misleading. It can mean many things like 'the headers are not in available' or 'there was a linking error', or anything else while checking the particular library.

Javernaut avatar Apr 02 '25 06:04 Javernaut

Hi Javernaut,

Thank you for taking the time to respond to my question. I apologize for the mistakes in my previous script and for not following the necessary steps correctly to build SRT for Android.

I have updated my script based on your suggestions and am now testing the new configuration.

`#!/usr/bin/env bash CMAKE_BUILD_DIR=libsrt_build_${ANDROID_ABI} cd srt rm -rf ${CMAKE_BUILD_DIR} mkdir ${CMAKE_BUILD_DIR} cd ${CMAKE_BUILD_DIR} ${CMAKE_EXECUTABLE} ..
-DCMAKE_SYSTEM_NAME=Android
-DANDROID_PLATFORM=${ANDROID_PLATFORM}
-DANDROID_ABI=${ANDROID_ABI}
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake
-DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
-DENABLE_SHARED=1
-DSRT_STATIC=0
-DENABLE_TESTING=0

${MAKE_EXECUTABLE} clean ${MAKE_EXECUTABLE} -j${HOST_NPROC} ${MAKE_EXECUTABLE} install export EXTRA_BUILD_CONFIGURATION_FLAGS="$EXTRA_BUILD_CONFIGURATION_FLAGS --enable-libsrt"`

However, during compilation, I encounter the following error: [ 68%] Building C object CMakeFiles/srt_virtual.dir/haicrypt/cryspr-openssl-evp.c.o In file included from /home/tommaso/lavoro/mine/progetti/ffmpeg-android/ffmpeg-android-maker/scripts/libsrt/srt/haicrypt/cryspr.c:24: In file included from /home/tommaso/lavoro/mine/progetti/ffmpeg-android/ffmpeg-android-maker/scripts/libsrt/srt/haicrypt/hcrypt.h:48: In file included from /home/tommaso/lavoro/mine/progetti/ffmpeg-android/ffmpeg-android-maker/scripts/libsrt/srt/haicrypt/cryspr.h:39: In file included from /home/tommaso/lavoro/mine/progetti/ffmpeg-android/ffmpeg-android-maker/scripts/libsrt/srt/haicrypt/cryspr-config.h:13: /home/tommaso/lavoro/mine/progetti/ffmpeg-android/ffmpeg-android-maker/scripts/libsrt/srt/haicrypt/cryspr-openssl-evp.h:22:10: fatal error: 'openssl/evp.h' file not found 22 | #include <openssl/evp.h> /* PKCS5_xxx() */

It seems that the build process cannot find the OpenSSL libraries. I have checked my build environment and tried specifying the library paths, but the error persists.

If you have any suggestions on how to resolve this issue, I would greatly appreciate it.

Thanks again for your help!

Best regards

ciccio14 avatar Apr 02 '25 17:04 ciccio14

going into more detail I found this internal script of srt https://github.com/Haivision/srt/blob/master/docs/build/build-android.md made specifically to build the application for android. is it possible to integrate it into the ffmpeg build process?

ciccio14 avatar Apr 03 '25 13:04 ciccio14

Hey there, I'm really out of capacity to dive super deep into the thing. Yet I can provide a couple of advices.

  1. Do you really need the openssl? I don't know for what exactly you are goint to use srt, but you could use flags that eliminate the dependency on openssl.
  2. Another thing, as I understand when building srt you can supply the mbedtls instead of opessl. You could try doing the thing this way. The mbedtls is already built by ffmpeg-andorid-maker, but you probably need to tweek these scripts to use mbedtls by srt, and not by ffmpeg itself. Sadly, I never came with a proper solution for dependencies and shared libraries building instead of static libs. I even consider rewriting the whole thing in Python once I really have time.

Javernaut avatar Apr 07 '25 17:04 Javernaut

I was able to successfully compile FFMPEG with SRT following this thread. I did most of the compiling and moving library files around by hand, but ultimately it worked.

Key Takeaways:

I used https://github.com/Haivision/srt/blob/master/docs/build/build-android.md to build srt for android, but as @Javernaut stated I had to use mbedtls. The mbedtls script in the Haivision/srt repo does not work correctly so it will fail, but you can compile mbedtls manually and move the .so files into the build-android prebuilt directory. Then you can compile srt with mbedtls.

Once you compile srt with mbedtls you can move the mbedtls and srt .so files into the build dir for this repo and pass the --enable-libsrt flag. You must also statically compile ffmpeg (see first note here https://srtlab.github.io/srt-cookbook/apps/ffmpeg.html).

Hopefully this helps. Thank you both for the insight.

tux1765 avatar Nov 13 '25 14:11 tux1765

Hi @tux1765, what do you mean by

The mbedtls script in this repo does not work correctly so it will fail

exactly?

Javernaut avatar Nov 16 '25 20:11 Javernaut

I was referring to the mkmbedtls script in the SRT build repo (https://github.com/Haivision/srt/blob/master/scripts/build-android/mkmbedtls). Apologies, poor wording on my part.

I had to build mbedtls manually then the rest of build-android worked once I moved over the lib files into the appropriate directories. Seems like there are submodules that the script does not account for after cloning, which in turn chokes the compilation. https://github.com/Mbed-TLS/mbedtls#git-usage

tux1765 avatar Nov 16 '25 20:11 tux1765