您的位置:首页 > 运维架构 > Linux

windows下编译ffmpeg2.5——使用VS2013,ARMLINUX,ANDORID编译ffmpeg

2016-01-15 11:23 791 查看
一、准备:

1.本机环境:win764bit;

2.安装MinGW到C:\MinGW,下载地址http://www.mingw.org/;

3.安装yasm,下载地址http://yasm.tortall.net/;

(2,3步请参考/article/1328987.html)

4.下载ffmpeg源码:我是从https://github.com/FFmpeg/FFmpeg上拉的release/2.5分支;

二、使用VS2013编译ffmpeg2.5:

VS2013已基本完整支持C99,使用VS2013,可以省去C89到C99的转换过程,并且FFMPEG2.5版本已经完整支持msvc工具链(实际FFMPEG2.3即已经支持),这使得使用VS2013编译ffmpeg变得异常简单,详细步骤可参考/article/1328987.html。

1.安装VS2013,假设装在D盘;

2.编辑C:\MinGW\msys\1.0\msys.bat文件,在此文件的最前面(@echooff之后)添加一行如下内容:

[plain]view
plaincopy





call"D:\ProgramFiles(x86)\MicrosoftVisualStudio12.0\VC\bin\vcvars32.bat"

3.重命名C:/MinGW/msys/1.0/bin/link.exe为link_renamed.exe;

4.在FFMPEG代码目录下新建文件build_msvc.sh,内容如下:

[plain]view
plaincopy





#!/bin/sh

#formsvc

MSVC_PREFIX=$(pwd)/out/msvc

functionbuild_msvc

{

./configure\

--prefix=$MSVC_PREFIX\

--enable-static\

--enable-shared\

--enable-debug\

--toolchain=msvc

makeclean

make

makeinstall

}

build_msvc

5.双击C:\MinGW\msys\1.0\msys.bat文件,在打开的命令行窗口下切换到ffmpeg源码目录,为build_msvc.sh添加执行权限,并执行;

6.等待脚本执行完成。

二、使用ANDROIDNDK编译ffmpeg2.5:

1.安装androidndk,下载地址:developer.android.com/tools/sdk/ndk/index.html,我使用的是ndk-r9d,安装目录为E:\android;

2.在FFMPEG代码目录下新建文件build_android.sh,内容如下:

[plain]view
plaincopy





NDK=E:/android/android-ndk-r9d

SYSROOT=$NDK/platforms/android-19/arch-arm/

TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64

PREFIX=$(pwd)/out/android

functionbuild_android

{

./configure\

--prefix=$PREFIX\

--enable-shared\

--disable-static\

--disable-doc\

--disable-ffmpeg\

--disable-ffplay\

--disable-ffprobe\

--disable-ffserver\

--disable-avdevice\

--disable-doc\

--disable-symver\

--enable-cross-compile\

--sysroot=$SYSROOT\

--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi-\

--target-os=linux\

--arch=arm

makeclean

make

makeinstall

}

build_android

3.双击C:\MinGW\msys\1.0\msys.bat文件,在打开的命令行窗口下切换到ffmpeg源码目录,为build_android.sh添加执行权限,并执行;

4.等待脚本执行完成。

三、使用ARMLINUX工具链编译ffmpeg2.5:

1.安装arm-none-linux-gnueabi-gcc,下载地址:http://www.veryarm.com/arm-none-linux-gnueabi-gcc,我使用的是windows安装版arm-2014.05-29-arm-none-linux-gnueabi.exe,安装路径:F:\arm-201405;

2.在FFMPEG代码目录下新建文件build_armlinux.sh,内容如下:

[plain]view
plaincopy





TOOLROOT=F:/arm-201405

PREFIX=$(pwd)/out/armlinux

functionbuild_armlinux

{

./configure\

--prefix=$PREFIX\

--enable-shared\

--disable-static\

--disable-doc\

--disable-ffmpeg\

--disable-ffplay\

--disable-ffprobe\

--disable-ffserver\

--disable-avdevice\

--disable-doc\

--disable-symver\

--enable-cross-compile\

--sysroot=$TOOLROOT/arm-none-linux-gnueabi/libc\

--cross-prefix=$TOOLROOT/bin/arm-none-linux-gnueabi-\

--target-os=linux\

--arch=arm

makeclean

make

makeinstall

}

build_armlinux

3.双击C:\MinGW\msys\1.0\msys.bat文件,在打开的命令行窗口下切换到ffmpeg源码目录,为build_armlinux.sh添加执行权限,并执行;

4.等待脚本执行完成。


win7下编译android版ffmpeg



参考:http://www.roman10.net/how-to-build-ffmpeg-with-ndk-r9/

ffmpeg用的是2.3.2版本。

困扰了很久,终于使用参考链接里的脚本成功编译了ffmpeg232版本,具体步骤为:

1.下载ffmpeg源码并解压,我解压后的源码目录为:E:\android;(参考链接说需要放到ndk目录下的source目录下,实测表明不是必须的如此)

2.安装MinGW;(1,2步参考/article/1328987.html,实际上我使用的也是当时编译VS版FFMPEG的环境);

3.下载androidNDK,下载地址:http://developer.android.com/tools/sdk/ndk/index.html,要注意win7是32位版还是64位版,我下载的是android-ndk-r10d-windows-x86_64.exe

,双击解压,我最后把解压后的android-ndk-r10d文件夹放在E:\android下面;

4.修改配置文件(参考链接里说需要修改配置文件,但我不修改也能成功编译);

将以下内容:

[plain]view
plaincopy





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)'

修改为:

[plain]view
plaincopy





SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'

LIB_INSTALL_EXTRA_CMD='$$(RANLIB)"$(LIBDIR)/$(LIBNAME)"'

SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'

SLIB_INSTALL_LINKS='$(SLIBNAME)'

5.在ffmpeg源码目录下新建一个build_android.sh脚本,并输入如下内容:

[plain]view
plaincopy





NDK=E:/android/android-ndk-r9d

SYSROOT=$NDK/platforms/android-19/arch-arm/

TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64

CPU=arm

PREFIX=$(pwd)/android/$CPU

ADDI_CFLAGS="-marm"

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"

makeclean

make

makeinstall

}

build_one

(注意不要直接从网页上复制这个脚本,如果直接从网页复制,有些行结尾会有2个空格,这会导致配置失败,可以用代码段上方的复制功能复制脚本)

6.双击msys.bat,进入类linuxshell界面(mysy在C:\MinGW\msys\1.0下),然后跳转到ffmpeg源码目录下(cdE:/android/ffmpeg232/);先用chmod+xbuild_android.sh给build_android.sh增加执行权限,在输入build_android.sh,然后就静等ffmpeg编译完成.

以下是链接地址原文:

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.

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: