FFMPEG is a fantastic & great library for video application development. It has many functions for modification, capturing, streaming, etc. For the first step, We have to compile FFMPEG library for Android. Google supply NDK(Native Development Kit) for using native C/C++ code.
Reference by How to Build ffmpeg with NDK r9 – Roman
Cygwin or MinGW Installation
As you know, Cygwin is a virtual Linux machine on Windows OS and MinGW is gcc compiler set . Download from Cygwin Installation website or MinGW
In my case, I use Windows 8 and Cygwin has some permission control problem (test compile error when ./configure). I installed MinGW (Installed package : mingw-developer-toolkit, mingw32-base, mingw32-gcc-g++, msys-base )
NDK Install & FFMPEG Compile
1) Download NDK latest version from Android NDK website. At the timing of blogging, the latest version is NDK-r10 (Decompress at c:\android-ndk-r10)
2) Download FFMPEG from ffmpeg website. The latest stable release is 2.3. Download the source code and decompress it to c:\android-ndk-r10\sources folder. (c:\android-ndk-r10\sources\ffmpeg-2.3)
3) Open ffmpeg-2.3/configure file with a text editor and change: (CAUTION: When you make files by Windows Editor, You have to save UNIX file format because carriage return code is different : \n vs \n\r)
SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)' LIB_INSTALL_EXTRA_CMD='$$(RANLIB) "$(LIBDIR)/$(LIBNAME)"'TEMP SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)' SLIB_INSTALL_LINKS='$(SLIBNAME)'
make directory in ffmpeg-2.3/ffmpegtemp folder and change mode +x. change temporary file directory as below. This directory is temporary directory for compiler testing
# set temporary file name
TEMPDIR="c:/ffmpegtmp"
TMP="c:/ffmpegtmp"
: ${TMPDIR:=$TEMPDIR}
: ${TMPDIR:=$TMP}
: ${TMPDIR:="c:/ffmpegtmp"}
4) Make script file for compile : a.sh
#!/bin/bash
NDK=c:/android-ndk-r10
SYSROOT=$NDK/platforms/android-9/arch-arm/
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/windows
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
5) Change the a.sh file permission ‘-x’. I always use chmod 777 ^^;; and then execute script
./a.sh
Compile time is so long….. Go to cafe and drink something with your friend. If you don’t have friends, Visit FFMPEG ORG 🙂
If you finished. You can see the folder c:\android-ndk-r10\sources\ffmpeg-2.3\android\arm\include & c:\android-ndk-r10\sources\ffmpeg-2.3\android\arm\lib
Import MPEG library in Android Project
1) We compiled ffmpeg libraries and we can use them. We stored ffmepg files under /samples/ffmpeg-2.3 directory because external modules have to be use NDK build. For external use of ffmepg library, we have to make a ‘Android.mk’ file in c:\android-ndk-r10\sources\ffmpeg-2.3\android\arm\ directory as below
LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE:= libavcodec LOCAL_SRC_FILES:= lib/libavcodec-55.so LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include include $(PREBUILT_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE:= libavformat LOCAL_SRC_FILES:= lib/libavformat-55.so LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include include $(PREBUILT_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE:= libswscale LOCAL_SRC_FILES:= lib/libswscale-2.so LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include include $(PREBUILT_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE:= libavutil LOCAL_SRC_FILES:= lib/libavutil-52.so LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include include $(PREBUILT_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE:= libavfilter LOCAL_SRC_FILES:= lib/libavfilter-3.so LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include include $(PREBUILT_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE:= libwsresample LOCAL_SRC_FILES:= lib/libswresample-0.so LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include include $(PREBUILT_SHARED_LIBRARY)
2) Make Android Application
Project name: FFTest Build Target: Android 4.0 Application name: FFTest Package name: com.example.FFTest Create Activity: FFTest Min SDK Version: API 8
It works so perfectly, Thanks a lot!
LikeLike
can you please help me for this.. i am new for NDK … its very urgent for me..
LikeLiked by 1 person
Yo have done great job
but i am having one error when generating Command ./android_build.sh
The Eroor is :
WARNING: d:/android-ndk-windows/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-pkg-config not found, library detection may fail.
CC libavfilter/aeval.o
In file included from ./libavutil/common.h:83,
from ./libavutil/avutil.h:289,
from ./libavutil/avassert.h:31,
from libavfilter/aeval.c:26:
./config.h:9:18: warning: missing terminating ” character
./config.h:10:7: warning: missing terminating ” character
In file included from ./libavutil/common.h:83,
from ./libavutil/avutil.h:289,
from ./libavutil/avassert.h:31,
from libavfilter/aeval.c:26:
./config.h:10: error: missing terminating ” character
In file included from ./libavutil/intmath.h:30,
from ./libavutil/common.h:84,
from ./libavutil/avutil.h:289,
from ./libavutil/avassert.h:31,
from libavfilter/aeval.c:26:
./libavutil/arm/intmath.h:94: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘static’
In file included from ./libavutil/avutil.h:289,
from ./libavutil/avassert.h:31,
from libavfilter/aeval.c:26:
./libavutil/common.h: In function ‘av_sat_add32_c’:
./libavutil/common.h:208: error: implicit declaration of function ‘av_clipl_int32_arm’
In file included from libavfilter/audio.h:26,
from libavfilter/aeval.c:33:
libavfilter/internal.h: In function ‘ff_insert_inpad’:
libavfilter/internal.h:275: warning: ‘input_count’ is deprecated (declared at libavfilter/avfilter.h:643)
libavfilter/internal.h: In function ‘ff_insert_outpad’:
libavfilter/internal.h:289: warning: ‘output_count’ is deprecated (declared at libavfilter/avfilter.h:650)
arm-linux-androideabi-gcc.exe: unrecognized option ‘-pthreads’
make: *** [libavfilter/aeval.o] Error 1
CC libavfilter/aeval.o
In file included from ./libavutil/common.h:83,
from ./libavutil/avutil.h:289,
from ./libavutil/avassert.h:31,
from libavfilter/aeval.c:26:
./config.h:9:18: warning: missing terminating ” character
./config.h:10:7: warning: missing terminating ” character
In file included from ./libavutil/common.h:83,
from ./libavutil/avutil.h:289,
from ./libavutil/avassert.h:31,
from libavfilter/aeval.c:26:
./config.h:10: error: missing terminating ” character
In file included from ./libavutil/intmath.h:30,
from ./libavutil/common.h:84,
from ./libavutil/avutil.h:289,
from ./libavutil/avassert.h:31,
from libavfilter/aeval.c:26:
./libavutil/arm/intmath.h:94: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘static’
In file included from ./libavutil/avutil.h:289,
from ./libavutil/avassert.h:31,
from libavfilter/aeval.c:26:
./libavutil/common.h: In function ‘av_sat_add32_c’:
./libavutil/common.h:208: error: implicit declaration of function ‘av_clipl_int32_arm’
In file included from libavfilter/audio.h:26,
from libavfilter/aeval.c:33:
libavfilter/internal.h: In function ‘ff_insert_inpad’:
libavfilter/internal.h:275: warning: ‘input_count’ is deprecated (declared at libavfilter/avfilter.h:643)
libavfilter/internal.h: In function ‘ff_insert_outpad’:
libavfilter/internal.h:289: warning: ‘output_count’ is deprecated (declared at libavfilter/avfilter.h:650)
arm-linux-androideabi-gcc.exe: unrecognized option ‘-pthreads’
make: *** [libavfilter/aeval.o] Error 1
I need your help…
Thanks.
LikeLike
If you are using a windows editor, Please save as configure file to UNIX format
LikeLike
I am able to run that .sh script successfully .. but its not generating android folder inside sources/ffmpeg.. I am using ndk r10, ffmpeg 2.1.7. Please help me.
LikeLike
Please check the ndk path in .sh
LikeLike
When I execute ./a.sh , I get an error: Permission denied. Any advice would be greatly appreciated! I’m using Cygwin to run in on Windows 8.1 pro.
LikeLike
I tried #!./a.sh and got it working….it doesn’t build anything anlthough it doesn’t complain either. Also, you didn’t talk about how we’re supposed to setup eclipse project. Do we just take the libraries from the compiled ffmpeg and dump them into our project’s libs folder?
LikeLiked by 1 person
please check the permission of a.sh –> Use chmod command in the Cygwin
LikeLike
please suggest me how to compile ffmeg with ndk on windows 7
LikeLike
Simply install CygWin and the other is same process
LikeLike