ffmpeg使用NDK r9编译
2014-02-14 13:32
405 查看
国内网站找了许多都没有成功。以下在mac和ubuntu上译编成功
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’llneedtoaddafilenamed
$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’llneedtoaddafilenamed
$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
相关文章推荐
- 使用 NDK r9 编译ffmpeg
- 使用 NDK r9 编译ffmpeg
- 使用 NDK r9 编译ffmpeg
- 使用 NDK r9 编译ffmpeg
- ffmpeg2.2在ubuntu下使用NDK编译——并在android工程下测试使用
- buntu12.10 64位 + android-ndk-r9 编译ffmpeg遇到的问题
- ubuntu_16.04_LTS使用NDK编译FFMPEG_3.1.1
- Ubuntu下为AndroidStudio编译并使用FFmpeg(一)ndk部分
- MAC下使用ndk编译ffmpeg
- linux下使用ndk编译ffmpeg
- Ubuntu 14.04 NDK R9 编译ffmpeg2.4
- ffmpeg2.2在ubuntu下使用NDK编译——并在android工程下测试使用
- 【Android】NDK编译ffmpeg(基于使用Ubuntu15.10)
- ubuntu_14.04_LTS使用NDK编译FFMPEG_2.7.2
- 在32位的Ubuntu 11.04中为Android NDK r6编译FFmpeg0.8.1版-Android中使用FFmpeg媒体库(一)
- 使用NDK交叉编译ffmpeg, android后台可执行。
- Android-NDK-r9编译ffmpeg-0.11.3
- ffmpeg2.2在ubuntu下使用NDK编译——并在android工程下测试使用
- 【android NDK及JNI】ubuntu12.10 64位 + android-ndk-r9 编译ffmpeg遇到的问题 .