ffmpeg2.2 is compiled under Ubuntu using the NDK--and tested with Android engineering

Source: Internet
Author: User

Wainiwann Source: http://www.cnblogs.com/wainiwann/This article copyright belongs to the author, welcome reprint, but without the author's consent must retain this paragraph statement, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility.

absrtact: This paper mainly introduces the compiling and basic testing process of porting FFmpeg audio and video codec library to Android platform.

Environment Preparation:

Ubuntu12.04 TLS

android-ndk-r9d-linux-x86_64.tar.bz2

ffmpeg2.2

---------------------------------------------------------

First step: Download

1. Configure the ubuntu12.04 TLS system environment.

2. Download the NDK version for r9d.

3. Download the ffmpeg2.2 version.

Step two: Compiling the environment settings under Ubuntu

1. After installing the ubuntu12.04 TLS 64-bit Linux system, you can choose to install the content:

In the reference to some other Linux under the NDK environment building materials See 64-bit Ubuntu installation need to download Bison

64-bit Ubuntu also needs to download gcc-multilib and g++-multilib:

Terminal command: " sudo apt-get install biosn gcc-multilib g++-multilib "

2. Download NDK after unpacking directory:/home/admin/develop/android-ndk-r9d

To configure the NDK environment variable:

(2.) Configure the NDK environment variables:

In-Terminal execution: " gedit ~/.BASHRC "

At the end of the open file, add the following:

ndk=/home/admin/develop/android-ndk-r9d

Export NDK

(3.) Read and execute commands in ~/.BASHRC in the current bash environment:

Terminal execution: " source ~/.BASHRC "

(4.) to see if it takes effect:

Terminal execution: " echo $NDK "

Results:/home/test/develop/android-ndk-r9d

(5.) test the NDK compilation JNI project:

To the Hello-jni directory of ANDROID-NDK-R9D's sample directory.

Terminal execution: " $NDK/ndk-build "

If the environment is configured successfully, the so library is generated.

3. Decompression ffmpeg-2.2 Source code

The ffmpeg-2.2.tar.gz is extracted and copied to any directory, this example is copied to the./android-ndk-r9d/sample/ffmpeg2.2 directory.

After the copy, add the "build_android.sh" file:

#!/bin/Bashsysroot= $NDK/platforms/android-9/arch-arm/toolchain= $NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64functionbuild_one{./Configure--prefix=$PREFIX--enable-shared--disable-Static--disable-Doc--disable-Ffserver--enable-cross-Compile--cross-prefix= $TOOLCHAIN/bin/arm-linux-androideabi-     --target-os=Linux--arch=Arm--sysroot=$SYSROOT--extra-cflags="-os-fpic $ADDI _cflags"     --extra-ldflags="$ADDI _ldflags"$ADDITIONAL _configure_flag} CPU=Armprefix=$(pwd)/android/$CPUADDI _cflags="-marm"Build_one

Some of the data above build_android.sh the first few lines are written like this:

#!/bin/bashNDK=/home/admin/develop/android-ndk-r9dsysroot= $NDK/ platforms/android-9/arch-arm/toolchain= $NDK/toolchains/arm-linux-androideabi-4.8/ prebuilt/linux-x86_64 .....

Because the NDK's environment path has already been set under Linux, there is no need to specify the NDK path in build_android.sh.

It is recommended to set the NDK's environment path to the system environment when compiling ffmpeg, because if not set, use "ndk=/home/admin/... "Personal feeling is very disgusting, especially when using Cygwin compile under Windows, there is often an issue where the NDK path cannot be found, so it is best to also configure the NDK environment path under Windows compilation.

To modify the Configure file:

Many ffmpeg compiled data above said to modify the Configure file, said the reason is if not modified, on Android system.loadlibrary ("xxx"); An issue where individual so libraries could not load.

Open the FFmpeg source configure file to make the following modifications:

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)'to be replaced by: Slibname_with_major='$ (slibpref) $ (FULLNAME)-$ (libmajor) $ (Slibsuf)'Lib_install_extra_cmd='$$ (Ranlib) "$ (libdir)/$ (libname)"'Slib_install_name='$ (slibname_with_major)'slib_install_links='$ (slibname)'

Step three: Compile the ffmpeg source under Ubuntu 64 to get a few so libraries that can be used on Android platform arm

1. Add executable permissions to build_android.sh and configure:

Terminal execution:

" $chmod +x./build_android.sh "

" $chmod +x./configure "

2. Convert format to build_android.sh and configure:

Terminal execution: (need to install Dos2unix first)

" $dos 2unix./build_android.sh "

" $dos 2unix./configure "

3. Final compilation:

Terminal execution:

" $./build_android.sh "

" $ make"

"$ make install "

----------------------

Successful compilation will generate an "Android" directory in the FFmpeg source directory with the compiled so library and the required header files, and so on.

Where so library should be a few:

libavutil-solibavcodec-solibswresample-0. Solibavformat -solibswscale-2. Solibpostproc-Solibavfilter -4. Solibavdevice-

Fourth Step: Use these libraries under Android:

----------------------------------------------------

1. Use these libraries using the HELLO-JNI project in the NDK sample directory:

(A.) Create a new Ffmpeglib directory under the JNI directory of the Hello-jni source and copy all of those libraries to the/hello-jni/jni/ffmpeglib/directory.

(b.) Then copy all the compiled FFmpeg header files to the/hello-jni/jni/directory.

(c.) Use ffmpeg within the Hello-jni.c file:

#include <string.h><jni.h><libavcodec/avcodec.h>Jstringjava_ Com_example_hellojni_hellojni_stringfromjni (jnienv* env,                                                  jobject thiz) {    char str[  - ];     " %d " , Avcodec_version ());     return (*env), NEWSTRINGUTF (env, str);}

(d.) Load the so library in the Hellojni.java file to invoke the test function within JNI:

Static      {                system.loadlibrary ("avutil-52");        System.loadlibrary ("avcodec-55");        System.loadlibrary ("swresample-0");        System.loadlibrary ("avformat-55");        System.loadlibrary ("swscale-2");        System.loadlibrary ("postproc-52");        System.loadlibrary ("avfilter-4");        System.loadlibrary ("avdevice-55");        System.loadlibrary ("Hello-jni");                }          Public native String  Stringfromjni ();

(E.) Modify the Android.mk file under the JNI directory in the Hello-jni source code:

Local_path: = $ (Call my-dir) include $ (clear_vars) Local_module:= avcodec- --ffmpeglibLocal_src_files:= ffmpeglib/libavcodec- -. Soinclude $ (prebuilt_shared_library) include $ (clear_vars) Local_module:= avdevice- --ffmpeglibLocal_src_files:= ffmpeglib/libavdevice- -. Soinclude $ (prebuilt_shared_library) include $ (clear_vars) Local_module:= avfilter-4-ffmpeglibLocal_src_files:= ffmpeglib/libavfilter-4. Soinclude $ (prebuilt_shared_library) include $ (clear_vars) Local_module:= avformat- --ffmpeglibLocal_src_files:= ffmpeglib/libavformat- -. Soinclude $ (prebuilt_shared_library) include $ (clear_vars) Local_module:= avutil- the-ffmpeglibLocal_src_files:= ffmpeglib/libavutil- the. Soinclude $ (prebuilt_shared_library) include $ (clear_vars) Local_module:= avswresample-0-ffmpeglibLocal_src_files:= ffmpeglib/libswresample-0. Soinclude $ (prebuilt_shared_library) include $ (clear_vars) Local_module:= swscale-2-ffmpeglibLocal_src_files:= ffmpeglib/libswscale-2. Soinclude $ (prebuilt_shared_library) include $ (clear_vars) Local_module:= postproc- the-ffmpeglibLocal_src_files:= ffmpeglib/libpostproc- the. Soinclude $ (prebuilt_shared_library) include $ (clear_vars) Local_module:= hello-JNI local_src_files:= hello-Jni.clocal_ldlibs:=-llog-ljnigraphics-lz-landroidlocal_shared_libraries:= avcodec- --prebuilt avdevice- --prebuilt avfilter-4-prebuilt avformat- --prebuilt avutil- the-prebuilt swscale-2-prebuilt postproc- the-prebuilt avswresample-0-Prebuiltinclude $ (build_shared_library)

(f.) Using Cygwin to compile the Hello-jni project under Windows:

"$NDK/ndk-build"

Build libhello-jni.so complete.

----------------------------------------

Attach all the so libraries and header files compiled under Ubuntu:

http://download.csdn.net/detail/wain163/7494547

--------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------

Resources:

http://blog.csdn.net/gobitan/article/details/22750719

Wainiwann Source: http://www.cnblogs.com/wainiwann/This article copyright belongs to the author, welcome reprint, but without the author's consent must retain this paragraph statement, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.