Mobile-ffmpeg: Build FFmpeg and FFprobe alongside with shared native libraries

Created on 16 Jun 2020  路  19Comments  路  Source: tanersener/mobile-ffmpeg

Description

Before converting a media user would want to see the details for their file (container, codec, and other information) => I need FFprobe executable, FFmpeg would do that too but not enough details.

Convert a video require a lot of RAM so typically you would want to offload it to another process => I need FFmpeg executable to execute via Runtime.getRuntime().exec(). Also, the app has to support parallel execution, viewing process and cancellation, that why Runtime.getRuntime().exec() is a must.

For now, each executable take about 12mb, I believe that because they are built as a standalone executable file. Does having both executable files that share common .so file possible? If yes how can I do that because for now, I have no clue where to start. If not would you recommend any other solution?

Thanks!

Expected behavior
What you expected to happen.
12Mb for all FFmpeg FFprobe and shared libraries

Current behavior
12Mb for each FFmpeg FFprobe executable

Environment

  • Platform: Android
  • Architecture: All
question

All 19 comments

Did you try to use MobileFFmpeg in your application? You don't need to have executables to do the things you've said.

@tanersener In my case, I need to use Runtime.getRuntime().exec() with executable file unfortunately

MobileFFmpeg does not create executables for FFmpeg and FFprobe by default. It is possible to edit the scripts and generate them. Building ffmpeg executable on Android wiki page explains which files should be updated. However, steps explained there don't work on all devices. So, I can't guarantee that it will work for you.

I tried to edit the script today, It creates several .so files and 2 executable ffmpeg and ffprobe as expected. Then I rename ffmpeg to libffmpeg.so to trick the android gradle plugin so that it will include the executable libffmpeg.so into the apk the extract it when the apk got installed. As the result, I can locate and execute libffmpeg.so, but it got error
CANNOT LINK EXECUTABLE "libffmpeg.so" : library "libavdevice.so" not found
Any ideas on how to solve this?

No.

Having 2 executable is kind of okay, the trade-off is your APK size will increase for about ~12mb, I will stick with that until we find out a better solution for this :(

When you build an executable that needs libavdevice.so and others, there is very little duplication, so the increase of size is inevitable. On the other hand, you can split by the ABI, and have smaller APKs for arm64, x86, etc.

@alexcohn but
When I build the executables with *.so, the executables show CANNOT LINK EXECUTABLE "libffmpeg.so" : library "libavdevice.so" not found when execute.
Build 2 executable alone (with no .so files) then the size is double.
I use Android App Bundle so it split by the ABI by default

Current working (double the size)

Output:
ffmpeg 12mb
ffprobe 12mb

Best base scenario (which current yell CANNOT LINK EXECUTABLE)

Output:
ffmpeg 100Kb
ffprobe 200kb
libav.so 6mb
libxx.so 1mb
...

(I did rename ffmpeg to libffmpeg.so so that the file got copied to APK)

You miss the environment parameter when you exec ffmpeg, e.g. like this:

Runtime.getRuntime().exec(
  new String[]{"./libffmpeg.so", "--version"}, 
  new String[]{"LD_LIBRARY_PATH=."}, 
  new File(getApplicationInfo().nativeLibraryDir));

@alexcohn thank you very much, I will try that tomorrow

@alexcohn l
thank man. it works like a charm

@tanersener it may be nice to document this use case in the Wiki

@alexcohn I think the case documented in the wiki is different than the case discussed here. Wiki page describes how to generate ffmpeg executable. In this thread, we have a case where both ffmpeg executable and other shared libraries are generated.

Right, the Wiki page speaks about statically-linked executables. It may be worth adding the case of shared-lib-linked executables, too. And the story of obligatory renaming and avoiding android:extractNativeLibs=false

I don't know what that story is. Can I skip that part?
I created this project to save people from those tricks and workarounds.
Ironically, I'm asked to write down a wiki about them.

Sorry, I didn't mean to offend you.

@alexcohn No worries. I know you didn't. I'm just trying to say that I don't want to document a workaround which is beyond the scope of the project. I also don't know the details of it.

Updated the wiki. When google decides to document those workarounds we may put a link for them in the wiki.

@tanersener thank you for being awesome!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

khacchungory picture khacchungory  路  7Comments

fayte0618 picture fayte0618  路  3Comments

JayParikh20 picture JayParikh20  路  4Comments

krislyy picture krislyy  路  5Comments

ZedZeal picture ZedZeal  路  6Comments