50

I want to configure FFMPEG in android studio but i cant get any document or link for that. Github on many FFMPEG lib available for android but that all are with old version. And how to run command in android? and i want to know after configure FFMPEG then how can we run FFMPEG commands. Help me for that. thanks advance.

I have used below links but not success in for latest version.

http://writingminds.github.io/ffmpeg-android-java

https://github.com/WritingMinds/ffmpeg-android-java

https://github.com/havlenapetr/FFMpeg

https://github.com/appunite/AndroidFFmpeg

https://github.com/WritingMinds/ffmpeg-android

Community
  • 1
  • 1
Ravi Vaghela
  • 3,420
  • 2
  • 23
  • 51

4 Answers4

37

The latest version of FFMPEG is 3.1.1, Just released before 12 days. So i think there is no readily available demo like this old one.

We need to build the FFMPEG library on our own. Some questions i found just pasting here that might help you. (Not tested)

How to Build FFmpeg for Android

  1. Compiling FFmpeg 2.3 with Android NDK r10
  2. How to compile ffmpeg-2.5.3 on windows with android-ndk-r10d
  3. How to compile ffmpeg-2.2.2 on windows with cygwin and android ndk r9c
  4. How to buid ffmpeg with android-ndk-r10d in windows

You need to compile it on your own the by downloading Android NDK & Latest Version of FFMPEG.

One tutorial is also there : How to Build FFmpeg for Android. This is quite old so you just need to change the versions mentioned here. For FFMPEG it will be 3.1.1 & NDK it will be r12b.


Building FFMPEG with NDK r12b:

  1. Download Android NDK : The latest version of Android NDK can be downloaded at Android NDK website. At the time of writing this answer, the newest version is NDK r12. simply decompress the archive

  2. Download ffmpeg source code : FFMPEG source code can be downloaded from the ffmpeg website. The latest stable release is 3.1.1 (at the time of writing). Download the source code and decompress it to $NDK/sources folder.

  3. Update configure file : Open ffmpeg-3.1.1/configure file with a text editor, and locate the following lines.

    SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBMAJOR)'
    LIB_INSTALL_EXTRA_CMD='$$(RANLIB) "$(LIBDIR)/$(LIBNAME)"'
    SLIB_INSTALL_NAME='$(SLIBNAME_WITH_VERSION)'
    SLIB_INSTALL_LINKS='$(SLIBNAME_WITH_MAJOR) $(SLIBNAME)'
    

    This cause ffmpeg shared libraries to be compiled to libavcodec.so. (e.g. libavcodec.so.55), which is not compatible with Android build system. Therefore we’ll need to replace the above lines with the following lines.

    SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
    LIB_INSTALL_EXTRA_CMD='$$(RANLIB) "$(LIBDIR)/$(LIBNAME)"'
    SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
    SLIB_INSTALL_LINKS='$(SLIBNAME)
    
  4. Build ffmpeg : Copy the following text to a text editor and save it as build_android.sh in ffmpeg_3.1.1 folder.

        #!/bin/bash
        NDK=$HOME/Desktop/adt/android-ndk-r9
        SYSROOT=$NDK/platforms/android-9/arch-arm/
        TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64
        function build_one
        {
            ./configure
                --prefix=$PREFIX
                --enable-shared
                --disable-static
            --disable-doc
                    --disable-ffmpeg
                --disable-ffplay
                --disable-ffprobe
                --disable-ffserver
                --disable-avdevice
                --disable-doc
                --disable-symver
                --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi-
                --target-os=linux
                --arch=arm
                --enable-cross-compile
                --sysroot=$SYSROOT
                --extra-cflags="-Os -fpic $ADDI_CFLAGS"
                --extra-ldflags="$ADDI_LDFLAGS"
            $ADDITIONAL_CONFIGURE_FLAG
            make clean
            make
            make install
        }
        CPU=arm
        PREFIX=$(pwd)/android/$CPU
        ADDI_CFLAGS="-marm"
        build_one
    

    Once the file is saved, go to the directory where this file lies & execute the command below,

    sudo chmod +x build_android.sh
    

    Then execute the script by the command,

    ./build_android.sh
    
  5. Build Output : The build can take a while to finish depending on your computer speed. Once it’s done, you should be able to find a folder $NDK/sources/ffmpeg-3.1.1/android, which contains arm/lib and arm/include folders.

  6. Make ffmpeg Libraries available for Your Projects

Steps above are fully tested and i performed them on my machine and the build was successful. For writing this answer i have took the reference from this article How to Build ffmpeg with NDK r9 but as it was for older version i have made some corrections on my own.

Open for asking any doubts.

Community
  • 1
  • 1
Janki Gadhiya
  • 4,492
  • 2
  • 29
  • 59
  • @JaydeepPatel see this : http://superuser.com/questions/163049/what-is-the-equivalent-of-chmod-777 – Janki Gadhiya Jul 15 '16 at 11:06
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/117406/discussion-between-jaydeep-patel-and-janki-gadhiya). – Jaydeep Devda Jul 15 '16 at 11:25
  • 2
    Hi am using ubundu and after executing this line ./build_android.sh it is showinng /configure: 3244: ./configure: Syntax error: redirection unexpected ./build_android.sh: line 8: --prefix=/home/techniche/Android/ndk/android-ndk-r12b/sources/ffmpeg-3.1.3/android/arm: No such file or directory – pranavjayadev Sep 19 '16 at 11:56
  • 1
    I was able to use you script successful for **ffmpeg 3.1.4**, but after finish there are no **android** folder (step 5) with output, instead there are folders with `.o`, `.d`, make files, etc. How to get `.so`? – Volodymyr Kulyk Oct 20 '16 at 10:21
  • 2
    hi @jankigadhiya .. i found problem in executing build_android.sh error:./build_android.sh: line 8: --prefix=/home/controller/Android/Sdk/ndk-bundle/ffmpeg-3.2.2/android/arm: No such file or directory – Angad Tiwari Dec 20 '16 at 12:50
  • thanks for your answer. I did what you said, but I get this error : ./build_android.sh: 34: ./build_android.sh: build_one: not found !!! – Davood Falahati Oct 27 '17 at 10:28
  • Can I use the direct library of GitHub instead of this lengthy process or this is the must? – Anand Savjani Jun 11 '18 at 17:02
  • I have tried to run cacls +x build_ffmpeg_android.sh for Window and then build_ffmpeg_android.sh because ./ was giving the error but Android folder not creating why? TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64 – Ashish Jain Dec 05 '18 at 13:21
  • @JankiGadhiya Please help me to configure ffmpeg lib for windows – Anand Savjani Aug 15 '20 at 08:35
13

I suggest you these following URLs that was helpful for me :

http://androidwarzone.blogspot.in/2011/12/ffmpeg4android.html

http://writingminds.github.io/ffmpeg-android-java/

https://androiddeveloperhelp.wordpress.com/2015/12/19/video-editing-android-example/

For knowledge:

http://www.lai18.com/content/5175900.html

Android studio Source Code:

https://drive.google.com/file/d/0B9qAjo6wKhk9MEpNNjMxaG5oWXM/view?usp=sharing

It may be help you.

parik dhakan
  • 787
  • 4
  • 19
5

Have you seen this link Writingminds's FFmpeg library provided all explanation about it in this link

Latest Version of that library writingmind is here https://github.com/WritingMinds/ffmpeg-android-java/releasesenter image description here

If you want to use latest version of any library you can do it right from in build.gradle because if any library is not updated it can be seen and can be updated from build.gradle, I always do this for many library for latest available version.

For gradle in FFMpeg use this

compile 'com.writingminds:FFmpegAndroid:0.3.2'

More libraries similar to it is given on this link https://android-arsenal.com/details/1/925

Also i suggest you to read this que, and this que

If you want to use Latest version of Original Library go here : FFmpeg [ latest version will be here ]

to add with native code then these blogs may help you

http://ffmpeg-android.blogspot.in/ and

http://www.roman10.net/2011/07/17/how-to-build-android-applications-based-on-ffmpeg-by-an-example/

Community
  • 1
  • 1
TapanHP
  • 5,969
  • 6
  • 37
  • 66
  • i want to use latest version of FFMPEG – Ravi Vaghela Jul 11 '16 at 05:49
  • I have already mentioned twise in my answer for latest version @RaviVGHL this link i have given you in my answer is giving it http://writingminds.github.io/ffmpeg-android-java/ and you can update latest library version directly from build.gradle – TapanHP Jul 11 '16 at 05:54
  • but here no any latest version build with this library – Ravi Vaghela Jul 11 '16 at 06:08
  • I have already provided that also in my answer from official site you can always get latest version. https://ffmpeg.org/download.html – TapanHP Jul 12 '16 at 07:37
  • This is out of dated dependency. Please update your answer – Anand Savjani Aug 15 '20 at 08:36
  • can you please edit this as I am no longer working on Java and android and not sure what version you are asking for? @AnandSavjani – TapanHP Aug 15 '20 at 11:04
1

I've experienced with ffmpeg for android for few weeks.

The library called FFmpeg4Android and can be found here at WarZone.

I know the title says it from December 6, 2011 but i've tested and worked with it and it all runs smoothly. You haven't mentioned what's your exact need with this library but you could read about the ffmpeg abilities at the official site.

The FFmpeg4Android has an example project that can be a great reference, and also their support is immediate and clear.

The commands are running according to your string input, e.g:

ffmpeg -y -i /sdcard/videokit/in.mp4 -strict experimental -s 160x120 -r 25 -vcodec mpeg4 -b 150k -ab 48000 -ac 2 -ar 22050 /sdcard/videokit/out.mp4

let me know if you need further help, i'll be glad to help.

Juvi
  • 1,078
  • 1
  • 19
  • 38