How to Build ffmpeg with NDK r9
2015-10-13 10:18
691 查看
根据实际的NDK路径修改配置文件
Thisisaupdatedpostforapreviouspost,wherewebuilt
ffmpeg0.8withAndroidNDKr5andr6.Thispostwillgiveinstructionsofhowtobuildffmpeg2.0.1withAndroidNDKr9.
0.
DownloadAndroidNDK
ThelatestversionofAndroidNDKcanbedownloadedatAndroid
NDKwebsite.Atthetimeofwriting,thenewestversionisNDKr9.Notethatthewebsiteprovidesbothcurrentandlegacytoolchains.Weonlyneedthecurrenttoolchaintocompileffmpeg.
AfterdownloadNDK,simplydecompressthearchive.Notethatwe’lluse$NDKtorepresenttherootpathofthedecompressedNDK.
1.
Downloadffmpegsourcecode
FFMPEGsourcecodecanbedownloadedfromtheffmpeg
website.Thelateststablereleaseis2.0.1.Downloadthesourcecodeanddecompressitto$NDK/sourcesfolder.We’lldiscussaboutthereasonfordoingthislater.
2.
Updateconfigurefile
Openffmpeg-2.0.1/configurefilewithatexteditor,andlocatethefollowinglines.
Thiscauseffmpegsharedlibrariestobecompiledtolibavcodec.so.<version>(e.g.libavcodec.so.55),whichisnotcompatiblewithAndroidbuildsystem.Thereforewe’llneedtoreplacetheabovelineswiththefollowinglines.
3.
Buildffmpeg
Copythefollowingtexttoatexteditorandsaveitasbuild_android.sh.
Wedisabledstaticlibraryandenabledsharedlibrary.NotethatthebuildscriptisnotoptimizedforaparticularCPU.Oneshouldrefertoffmpegdocumentationfordetailedinformationaboutavailableconfigureoptions.
Oncethefileissaved,makesurethescriptisexecutablebythecommandbelow,
sudochmod+xbuild_android.sh
Thenexecutethescriptbythecommand,
./build_android.sh
4.
BuildOutput
Thebuildcantakeawhiletofinishdependingonyourcomputerspeed.Onceit’sdone,youshouldbeabletofindafolder$NDK/sources/ffmpeg-2.0.1/android,whichcontainsarm/libandarm/includefolders.
Thearm/libfoldercontainsthesharedlibraries,whilearm/includefoldercontainstheheaderfilesforlibavcodec,libavformat,libavfilter,libavutil,libswscaleetc.
Notethatthearm/libfoldercontainsboththelibraryfiles(e.g.:libavcodec-55.so)andsymboliclinks(e.g.:libavcodec.so)tothem.Wecanremovethesymboliclinkstoavoidconfusion.
5.
MakeffmpegLibrariesavailableforYourProjects
Nowwe’vecompiledtheffmpeglibrariesandreadytousethem.AndroidNDKallowsustoreuseacompiledmodulethroughtheimport-modulebuildcommand.
Thereasonwebuiltourffmpegsourcecodeunder$NDK/sourcesfolderisthatNDKbuildsystemwillsearchfordirectoriesunderthispathforexternalmodulesautomatically.Todeclaretheffmpeglibrariesasreusablemodules,we’llneedtoadd
afilenamed$NDK/sources/ffmpeg-2.0.1/android/arm/Android.mkwiththefollowingcontent,
BelowisanexampleofhowwecanusethelibrariesinaAndroidproject’sjni/Android.mkfile,
Notethatwecalledimport-modulewiththerelativepathto$NDK/sourcesforthebuildsystemtolocatethereusableffmpeglibraries.
ForrealexamplestohowtousetheffmpeglibrariesinAndroidapp,pleaserefertomygithubrepoofandroid-ffmpeg-tutorial.
Thisisaupdatedpostforapreviouspost,wherewebuilt
ffmpeg0.8withAndroidNDKr5andr6.Thispostwillgiveinstructionsofhowtobuildffmpeg2.0.1withAndroidNDKr9.
0.
DownloadAndroidNDK
ThelatestversionofAndroidNDKcanbedownloadedatAndroid
NDKwebsite.Atthetimeofwriting,thenewestversionisNDKr9.Notethatthewebsiteprovidesbothcurrentandlegacytoolchains.Weonlyneedthecurrenttoolchaintocompileffmpeg.
AfterdownloadNDK,simplydecompressthearchive.Notethatwe’lluse$NDKtorepresenttherootpathofthedecompressedNDK.
1.
Downloadffmpegsourcecode
FFMPEGsourcecodecanbedownloadedfromtheffmpeg
website.Thelateststablereleaseis2.0.1.Downloadthesourcecodeanddecompressitto$NDK/sourcesfolder.We’lldiscussaboutthereasonfordoingthislater.
2.
Updateconfigurefile
Openffmpeg-2.0.1/configurefilewithatexteditor,andlocatethefollowinglines.
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)'
Thiscauseffmpegsharedlibrariestobecompiledtolibavcodec.so.<version>(e.g.libavcodec.so.55),whichisnotcompatiblewithAndroidbuildsystem.Thereforewe’llneedtoreplacetheabovelineswiththefollowinglines.
SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
LIB_INSTALL_EXTRA_CMD='$$(RANLIB)"$(LIBDIR)/$(LIBNAME)"'
SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
SLIB_INSTALL_LINKS='$(SLIBNAME)'
3.
Buildffmpeg
Copythefollowingtexttoatexteditorandsaveitasbuild_android.sh.
#!/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
functionbuild_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
makeclean
make
makeinstall
}
CPU=arm
PREFIX=$(pwd)/android/$CPU
ADDI_CFLAGS="-marm"
build_one
Wedisabledstaticlibraryandenabledsharedlibrary.NotethatthebuildscriptisnotoptimizedforaparticularCPU.Oneshouldrefertoffmpegdocumentationfordetailedinformationaboutavailableconfigureoptions.
Oncethefileissaved,makesurethescriptisexecutablebythecommandbelow,
sudochmod+xbuild_android.sh
Thenexecutethescriptbythecommand,
./build_android.sh
4.
BuildOutput
Thebuildcantakeawhiletofinishdependingonyourcomputerspeed.Onceit’sdone,youshouldbeabletofindafolder$NDK/sources/ffmpeg-2.0.1/android,whichcontainsarm/libandarm/includefolders.
Thearm/libfoldercontainsthesharedlibraries,whilearm/includefoldercontainstheheaderfilesforlibavcodec,libavformat,libavfilter,libavutil,libswscaleetc.
Notethatthearm/libfoldercontainsboththelibraryfiles(e.g.:libavcodec-55.so)andsymboliclinks(e.g.:libavcodec.so)tothem.Wecanremovethesymboliclinkstoavoidconfusion.
5.
MakeffmpegLibrariesavailableforYourProjects
Nowwe’vecompiledtheffmpeglibrariesandreadytousethem.AndroidNDKallowsustoreuseacompiledmodulethroughtheimport-modulebuildcommand.
Thereasonwebuiltourffmpegsourcecodeunder$NDK/sourcesfolderisthatNDKbuildsystemwillsearchfordirectoriesunderthispathforexternalmodulesautomatically.Todeclaretheffmpeglibrariesasreusablemodules,we’llneedtoadd
afilenamed$NDK/sources/ffmpeg-2.0.1/android/arm/Android.mkwiththefollowingcontent,
LOCAL_PATH:=$(callmy-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)
BelowisanexampleofhowwecanusethelibrariesinaAndroidproject’sjni/Android.mkfile,
LOCAL_PATH:=$(callmy-dir)
include$(CLEAR_VARS)
LOCAL_MODULE:=tutorial03
LOCAL_SRC_FILES:=tutorial03.c
LOCAL_LDLIBS:=-llog-ljnigraphics-lz-landroid
LOCAL_SHARED_LIBRARIES:=libavformatlibavcodeclibswscalelibavutil
include$(BUILD_SHARED_LIBRARY)
$(callimport-module,ffmpeg-2.0.1/android/arm)
Notethatwecalledimport-modulewiththerelativepathto$NDK/sourcesforthebuildsystemtolocatethereusableffmpeglibraries.
ForrealexamplestohowtousetheffmpeglibrariesinAndroidapp,pleaserefertomygithubrepoof
相关文章推荐
- UISearchController
- 分子模拟软件Schrodinger Suites 2015安装
- 聊聊并发(六)ConcurrentLinkedQueue的实现原理分析
- [ajax] quick double or multiple click ajax submit cause chrome explorer's error snatshot
- (iOS)使用auto layout进行复杂布局时,UILabel的相关trick
- request和response概念用法
- easyui datagrid 单击事件和双击事件
- chain.doFilter(request,response)含义
- iOS UITableView 移除单元格选中时的高亮状态
- CSS3 Media Queries (转载自W3CPLUS)
- UvaLive 5026 Building Roads
- RequireJS模块化加载
- UITextField的使用
- Storing the SecurityContext between requests
- vector、list、deque和map的区别
- UIView和CALayer的区别
- iOS适配UITableViewCell上分割线致顶
- 系统提供的几种UITableViewCell的样式
- KVC中setValuesForKeysWithDictionary:
- 关于UINavigationController与UITableView聚合的发现