Mobile-ffmpeg: How to use gradle just for “libx264”(x264) and “libmp3lame”(lame)?

Created on 24 Apr 2020  ·  5Comments  ·  Source: tanersener/mobile-ffmpeg

I have integrated this library in my POC app and I have seen a drastic improvement in terms of processing speed compared to https://github.com/WritingMinds/ffmpeg-android-java. So before integrating this in a production environment, I do have few questions. Hope you will share your valuable insights, thank you.

1) Is FFMpeg 4.3-dev-2955 stable? Why are you not using 4.2.2 from the master branch of FFmpeg(https://github.com/FFmpeg/FFmpeg/releases)?

2) mobile-ffmpeg 4.3.2 Main Release supports 4 ABIs and 4.3.1.LTS supports 5 ABIs. So if I integrate 4.3.2 Main release, will Arm-v7a-neon fallback to arm-v7a for the device which does not support Neon, and work properly?

“Not all ARMv7-based Android devices support Neon, but devices that do may benefit significantly from its support for scalar/vector instructions.” (https://developer.android.com/ndk/guides/cpu-arm-neon)

3) Here is my main question. I just need to use “libx264”(x264) and “libmp3lame”(lame) in my commands and not other libraries as it increases app size significantly. For this, I can think of three ways to integrate,

3-A) By generating AAR with all 4 ABIs and with only two “x264” and “lame” libraries. But it seems a good bit of work to deal with.

3-B) Is there any way to exclude other libraries from full-gpl package? Or include just required libraries based on modules such as in JavaCV (https://github.com/bytedeco/sample-projects/blob/master/JavaCV-android-example/app/build.gradle).

    compile group: 'org.bytedeco', name: 'javacv', version: '1.3.1'
    compile group: 'org.bytedeco.javacpp-presets', name: 'opencv-platform', version: '3.1.0-1.3'
    compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg-platform', version: '3.2.1-1.3'

3-C) Two different gradle approach. One is implementation 'com.arthenica:mobile-ffmpeg-min-gpl:4.3.2' for “libx264” and second is implementation 'com.arthenica:mobile-ffmpeg-audio:4.3.2' for “libmp3lame”. In this way, there still will be a few extra libraries but not that many.

    implementation 'com.arthenica:mobile-ffmpeg-min-gpl:4.3.2'
    implementation('com.arthenica:mobile-ffmpeg-audio:4.3.2') {
        transitive=true
    }
//  or
    implementation('com.arthenica:mobile-ffmpeg-audio:4.3.2') {
        exclude group: 'com.arthenica', module: 'mobile-ffmpeg-audio'
    }

I tried the above code in build.gradle. However, I am facing the below error in this approach.

Duplicate class com.arthenica.mobileffmpeg.Abi found in modules jetified-mobile-ffmpeg-audio-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-audio:4.3.2) and jetified-mobile-ffmpeg-min-gpl-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-min-gpl:4.3.2)
Duplicate class com.arthenica.mobileffmpeg.AbiDetect found in modules jetified-mobile-ffmpeg-audio-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-audio:4.3.2) and jetified-mobile-ffmpeg-min-gpl-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-min-gpl:4.3.2)
Duplicate class com.arthenica.mobileffmpeg.BuildConfig found in modules jetified-mobile-ffmpeg-audio-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-audio:4.3.2) and jetified-mobile-ffmpeg-min-gpl-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-min-gpl:4.3.2)
Duplicate class com.arthenica.mobileffmpeg.CameraSupport found in modules jetified-mobile-ffmpeg-audio-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-audio:4.3.2) and jetified-mobile-ffmpeg-min-gpl-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-min-gpl:4.3.2)
Duplicate class com.arthenica.mobileffmpeg.Config found in modules jetified-mobile-ffmpeg-audio-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-audio:4.3.2) and jetified-mobile-ffmpeg-min-gpl-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-min-gpl:4.3.2)
Duplicate class com.arthenica.mobileffmpeg.Config$1 found in modules jetified-mobile-ffmpeg-audio-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-audio:4.3.2) and jetified-mobile-ffmpeg-min-gpl-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-min-gpl:4.3.2)
Duplicate class com.arthenica.mobileffmpeg.FFmpeg found in modules jetified-mobile-ffmpeg-audio-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-audio:4.3.2) and jetified-mobile-ffmpeg-min-gpl-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-min-gpl:4.3.2)
Duplicate class com.arthenica.mobileffmpeg.FFprobe found in modules jetified-mobile-ffmpeg-audio-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-audio:4.3.2) and jetified-mobile-ffmpeg-min-gpl-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-min-gpl:4.3.2)
Duplicate class com.arthenica.mobileffmpeg.Level found in modules jetified-mobile-ffmpeg-audio-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-audio:4.3.2) and jetified-mobile-ffmpeg-min-gpl-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-min-gpl:4.3.2)
Duplicate class com.arthenica.mobileffmpeg.LogCallback found in modules jetified-mobile-ffmpeg-audio-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-audio:4.3.2) and jetified-mobile-ffmpeg-min-gpl-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-min-gpl:4.3.2)
Duplicate class com.arthenica.mobileffmpeg.LogMessage found in modules jetified-mobile-ffmpeg-audio-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-audio:4.3.2) and jetified-mobile-ffmpeg-min-gpl-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-min-gpl:4.3.2)
Duplicate class com.arthenica.mobileffmpeg.MediaInformation found in modules jetified-mobile-ffmpeg-audio-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-audio:4.3.2) and jetified-mobile-ffmpeg-min-gpl-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-min-gpl:4.3.2)
Duplicate class com.arthenica.mobileffmpeg.MediaInformationParser found in modules jetified-mobile-ffmpeg-audio-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-audio:4.3.2) and jetified-mobile-ffmpeg-min-gpl-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-min-gpl:4.3.2)
Duplicate class com.arthenica.mobileffmpeg.Packages found in modules jetified-mobile-ffmpeg-audio-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-audio:4.3.2) and jetified-mobile-ffmpeg-min-gpl-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-min-gpl:4.3.2)
Duplicate class com.arthenica.mobileffmpeg.Statistics found in modules jetified-mobile-ffmpeg-audio-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-audio:4.3.2) and jetified-mobile-ffmpeg-min-gpl-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-min-gpl:4.3.2)
Duplicate class com.arthenica.mobileffmpeg.StatisticsCallback found in modules jetified-mobile-ffmpeg-audio-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-audio:4.3.2) and jetified-mobile-ffmpeg-min-gpl-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-min-gpl:4.3.2)
Duplicate class com.arthenica.mobileffmpeg.StreamInformation found in modules jetified-mobile-ffmpeg-audio-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-audio:4.3.2) and jetified-mobile-ffmpeg-min-gpl-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-min-gpl:4.3.2)
Duplicate class com.arthenica.mobileffmpeg.util.AsyncSingleFFmpegExecuteTask found in modules jetified-mobile-ffmpeg-audio-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-audio:4.3.2) and jetified-mobile-ffmpeg-min-gpl-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-min-gpl:4.3.2)
Duplicate class com.arthenica.mobileffmpeg.util.AsyncSingleFFprobeExecuteTask found in modules jetified-mobile-ffmpeg-audio-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-audio:4.3.2) and jetified-mobile-ffmpeg-min-gpl-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-min-gpl:4.3.2)
Duplicate class com.arthenica.mobileffmpeg.util.AsyncSingleGetMediaInformationTask found in modules jetified-mobile-ffmpeg-audio-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-audio:4.3.2) and jetified-mobile-ffmpeg-min-gpl-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-min-gpl:4.3.2)
Duplicate class com.arthenica.mobileffmpeg.util.Pair found in modules jetified-mobile-ffmpeg-audio-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-audio:4.3.2) and jetified-mobile-ffmpeg-min-gpl-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-min-gpl:4.3.2)
Duplicate class com.arthenica.mobileffmpeg.util.SingleExecuteCallback found in modules jetified-mobile-ffmpeg-audio-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-audio:4.3.2) and jetified-mobile-ffmpeg-min-gpl-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-min-gpl:4.3.2)
Duplicate class com.arthenica.mobileffmpeg.util.SingleGetMediaInformationCallback found in modules jetified-mobile-ffmpeg-audio-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-audio:4.3.2) and jetified-mobile-ffmpeg-min-gpl-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-min-gpl:4.3.2)
Duplicate class com.arthenica.mobileffmpeg.util.Trio found in modules jetified-mobile-ffmpeg-audio-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-audio:4.3.2) and jetified-mobile-ffmpeg-min-gpl-4.3.2-runtime.jar (com.arthenica:mobile-ffmpeg-min-gpl:4.3.2)

4) If I generate multiple apks for four different ABIs mainly to reduce apk size and then upload on Play Store, is there any change required or just below code is fine? https://developer.android.com/studio/build/configure-apk-splits

    splits {
        abi {
            enable true
            reset()
            include 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
            universalApk false
        }
    }

5) Need Main Release with support below Android API Level 24. It seems you are checking Build.VERSION_CODES.N only in two classes, Config.java and CameraSupport.java. So if you can set minSdkVersion 21 and throw an exception it would be great. For now I am using in AndroidManifest.xml. As I am not using any stuff related to Camera but I need to support API level 21 and above.

Thanks in advance.

question

All 5 comments

1 . There are several reasons behind that decision.

  • Dev releases are tested less compared to point releases. So in terms of stability and bugs, you can expect them to have more bugs compared to point releases. But I don't think that the difference between these two is big enough to call one of them unstable. MobileFFmpeg tests the core functionality and the all major external libraries before publishing a release. If a bug is detected somewhere, those commits/files are not included in MobileFFmpeg releases.
  • I don't want MobileFFmpeg to depend on ffmpeg releases. Depending means, waiting for a release, waiting for a functionality to be fixed/implemented.
  • ffmpeg developers only support master. They do not support those point releases. So I don't want to support or build them too.
  • New functionalities are introduced in master first.
  • Sometimes, multiple point releases are published by ffmpeg developers. But I do not have time to publish each of them for mobile. So, I have my own release cycle.
    ...
  • It will try to use arm-v7a ABI. But I don't guarantee that it will work properly. If you try to use a binary code optimised for NEON , then it will crash most probably.
  • ffmpeg shared libraries are linked to other external libraries on link time. So, none of the gradle solutions will work. A is the only option.
  • I think it is fine. Please take a look at the build.gradle of test-application. It uses a similar configuration for splitting the apks.
  • I'm not throwing any exceptions in this library and I don't see any reasons to throw one. Main releases use API Level 24 because there are some native methods that depend on API Level 24. You are free to clone the project and apply your changes there.

Thanks tanersener, for a detailed response.

For number 2, I think non-Neon devices are very rare, so I am taking chances.
https://developer.android.com/ndk/guides/cpu-arm-neon

https://android.stackexchange.com/questions/208830/how-common-is-arm-neon-support-among-recent-android-phones-and-tablets

And for number 5, what will crash if I integrate 4.3.2 Main Release and just use “libx264”(x264) and “libmp3lame”(lame)?

And If I integrate 4.31.LTS Release, does it include neon and other cpufeature or hardware related features to run FFmpeg command faster for the above two libraries?

And for number 5, what will crash if I integrate 4.3.2 Main Release and just use “libx264”(x264) and “libmp3lame”(lame)?

Are you using a published release here? If an API Level 21 device tries to load v4.3.2, I expect that application to crash on startup.

And If I integrate 4.31.LTS Release, does it include neon and other cpufeature or hardware related features to run FFmpeg command faster for the above two libraries?

Yes, it does. All 5 architectures are enabled on Android LTS releases.

Yes, it is crashing on the devices with API 21-23 so I need to go with 4.3.1.LTS release.

1) implementation 'com.arthenica:mobile-ffmpeg-full:v4.3.1.LTS' Release supports 5 different ABIs(arm-v7a, arm-v7a-neon, arm64-v8a, x86, x86-64).

splits {
    abi {
        enable true
        reset()
        include 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
        universalApk false
    }
}

And If I split APKs for four different ABIs. Then which ABI is included in final release in between arm-v7a and arm-v7a-neon?

2) Just to clarify, If I need to build the AAR file just for “libx264”(x264) and “libmp3lame”(lame)  then I need to download "Source code(zip)" from here(https://github.com/tanersener/mobile-ffmpeg/releases/tag/v4.3.1.LTS). And then I need to follow these steps(https://github.com/tanersener/mobile-ffmpeg#5-building), right?

Please see Android NEON Support wiki page for 1. For 2, you are right. You need to follow instructions given in Building section.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chaocharleswang picture chaocharleswang  ·  4Comments

andyrenkehe picture andyrenkehe  ·  8Comments

rabelhmd picture rabelhmd  ·  7Comments

JayParikh20 picture JayParikh20  ·  4Comments

tim162 picture tim162  ·  5Comments