您的位置:首页 > 其它

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.

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,pleaserefertomygithubrepoofandroid-ffmpeg-tutorial.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: