天天看点

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

一、准备:

1. 本机环境: win7 64bit;

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

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

(2,3步请参考http://blog.csdn.net/finewind/article/details/38854517)

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变得异常简单,详细步骤可参考http://blog.csdn.net/finewind/article/details/38854517。

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

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

[plain]  view plain copy

windows下编译ffmpeg2.5——使用VS2013,ARMLINUX,ANDORID编译ffmpeg win7下编译android版ffmpeg
windows下编译ffmpeg2.5——使用VS2013,ARMLINUX,ANDORID编译ffmpeg win7下编译android版ffmpeg
  1. call "D:\Program Files(x86)\Microsoft Visual Studio 12.0\VC\bin\vcvars32.bat"  

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

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

[plain]  view plain copy

windows下编译ffmpeg2.5——使用VS2013,ARMLINUX,ANDORID编译ffmpeg win7下编译android版ffmpeg
windows下编译ffmpeg2.5——使用VS2013,ARMLINUX,ANDORID编译ffmpeg win7下编译android版ffmpeg
  1. #!/bin/sh  
  2. # for msvc  
  3. MSVC_PREFIX=$(pwd)/out/msvc       
  4. function build_msvc  
  5. {  
  6. ./configure     \  
  7.     --prefix=$MSVC_PREFIX \  
  8.     --enable-static     \  
  9.     --enable-shared     \  
  10.     --enable-debug      \  
  11.     --toolchain=msvc  
  12. make clean  
  13. make          
  14. make install      
  15. }  
  16. build_msvc  

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

6. 等待脚本执行完成。

二、使用ANDROID NDK编译ffmpeg2.5:

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

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

[plain]  view plain copy

windows下编译ffmpeg2.5——使用VS2013,ARMLINUX,ANDORID编译ffmpeg win7下编译android版ffmpeg
windows下编译ffmpeg2.5——使用VS2013,ARMLINUX,ANDORID编译ffmpeg win7下编译android版ffmpeg
  1. NDK=E:/android/android-ndk-r9d  
  2. SYSROOT=$NDK/platforms/android-19/arch-arm/  
  3. TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64  
  4. PREFIX=$(pwd)/out/android  
  5. function build_android  
  6. {  
  7. ./configure \  
  8.     --prefix=$PREFIX \  
  9.     --enable-shared \  
  10.     --disable-static \  
  11.     --disable-doc \  
  12.     --disable-ffmpeg \  
  13.     --disable-ffplay \  
  14.     --disable-ffprobe \  
  15.     --disable-ffserver \  
  16.     --disable-avdevice \  
  17.     --disable-doc \  
  18.     --disable-symver \  
  19.     --enable-cross-compile \  
  20.     --sysroot=$SYSROOT  \  
  21.     --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \  
  22.     --target-os=linux \  
  23.     --arch=arm  
  24. make clean  
  25. make  
  26. make install  
  27. }  
  28. build_android  

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

4. 等待脚本执行完成。

三、使用ARM LINUX工具链编译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 plain copy

windows下编译ffmpeg2.5——使用VS2013,ARMLINUX,ANDORID编译ffmpeg win7下编译android版ffmpeg
windows下编译ffmpeg2.5——使用VS2013,ARMLINUX,ANDORID编译ffmpeg win7下编译android版ffmpeg
  1. TOOLROOT=F:/arm-201405  
  2. PREFIX=$(pwd)/out/armlinux  
  3. function build_armlinux  
  4. {  
  5. ./configure \  
  6.     --prefix=$PREFIX \  
  7.     --enable-shared \  
  8.     --disable-static \  
  9.     --disable-doc \  
  10.     --disable-ffmpeg \  
  11.     --disable-ffplay \  
  12.     --disable-ffprobe \  
  13.     --disable-ffserver \  
  14.     --disable-avdevice \  
  15.     --disable-doc \  
  16.     --disable-symver \  
  17.     --enable-cross-compile \  
  18.     --sysroot=$TOOLROOT/arm-none-linux-gnueabi/libc  \  
  19.     --cross-prefix=$TOOLROOT/bin/arm-none-linux-gnueabi- \  
  20.     --target-os=linux \  
  21.     --arch=arm  
  22. make clean  
  23. make  
  24. make install  
  25. }  
  26. 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步参考http://blog.csdn.net/finewind/article/details/38854517,实际上我使用的也是当时编译VS版FFMPEG的环境);

3. 下载android NDK,下载地址: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 plain copy

windows下编译ffmpeg2.5——使用VS2013,ARMLINUX,ANDORID编译ffmpeg win7下编译android版ffmpeg
windows下编译ffmpeg2.5——使用VS2013,ARMLINUX,ANDORID编译ffmpeg win7下编译android版ffmpeg
  1. SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBMAJOR)'  
  2. LIB_INSTALL_EXTRA_CMD='$$(RANLIB) "$(LIBDIR)/$(LIBNAME)"'  
  3. SLIB_INSTALL_NAME='$(SLIBNAME_WITH_VERSION)'  
  4. SLIB_INSTALL_LINKS='$(SLIBNAME_WITH_MAJOR) $(SLIBNAME)'  

修改为:

[plain]  view plain copy

windows下编译ffmpeg2.5——使用VS2013,ARMLINUX,ANDORID编译ffmpeg win7下编译android版ffmpeg
windows下编译ffmpeg2.5——使用VS2013,ARMLINUX,ANDORID编译ffmpeg win7下编译android版ffmpeg
  1. SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'  
  2. LIB_INSTALL_EXTRA_CMD='$$(RANLIB) "$(LIBDIR)/$(LIBNAME)"'  
  3. SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'  
  4. SLIB_INSTALL_LINKS='$(SLIBNAME)'  

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

[plain]  view plain copy

windows下编译ffmpeg2.5——使用VS2013,ARMLINUX,ANDORID编译ffmpeg win7下编译android版ffmpeg
windows下编译ffmpeg2.5——使用VS2013,ARMLINUX,ANDORID编译ffmpeg win7下编译android版ffmpeg
  1. NDK=E:/android/android-ndk-r9d  
  2. SYSROOT=$NDK/platforms/android-19/arch-arm/  
  3. TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64  
  4. CPU=arm  
  5. PREFIX=$(pwd)/android/$CPU   
  6. ADDI_CFLAGS="-marm"  
  7. function build_one  
  8. {  
  9. ./configure \  
  10.     --prefix=$PREFIX \  
  11.     --enable-shared \  
  12.     --disable-static \  
  13.     --disable-doc \  
  14.     --disable-ffmpeg \  
  15.     --disable-ffplay \  
  16.     --disable-ffprobe \  
  17.     --disable-ffserver \  
  18.     --disable-avdevice \  
  19.     --disable-doc \  
  20.     --disable-symver \  
  21.     --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \  
  22.     --target-os=linux \  
  23.     --arch=arm \  
  24.     --enable-cross-compile \  
  25.     --sysroot=$SYSROOT \  
  26.     --extra-cflags="-Os -fpic $ADDI_CFLAGS" \  
  27.     --extra-ldflags="$ADDI_LDFLAGS"   
  28. make clean  
  29. make  
  30. make install  
  31. }  
  32. build_one  

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

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

以下是链接地址原文:

This is a updated post for a previous post, where we built ffmpeg 0.8 with Android NDK r5 and r6. This post will give instructions of how to build ffmpeg 2.0.1 with Android NDK r9.

0. Download Android NDK

The latest version of Android NDK can be downloaded at Android NDK website. At the time of writing, the newest version is NDK r9. Note that the website provides both current and legacy toolchains. We only need the current toolchain to compile ffmpeg.

After download NDK, simply decompress the archive. Note that we’ll use $NDK to represent the root path of the decompressed NDK.

1. Download ffmpeg source code

FFMPEG source code can be downloaded from the ffmpeg website. The latest stable release is 2.0.1. Download the source code and decompress it to $NDK/sources folder. We’ll discuss about the reason for doing this later.

2. Update configure file

Open ffmpeg-2.0.1/configure file with a text editor, and locate the following lines.

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

This cause ffmpeg shared libraries to be compiled to libavcodec.so.<version> (e.g. libavcodec.so.55), which is not compatible with Android build system. Therefore we’ll need to replace the above lines with the following lines.

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. Build ffmpeg

Copy the following text to a text editor and save it as build_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      
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      

We disabled static library and enabled shared library. Note that the build script is not optimized for a particular CPU. One should refer to ffmpeg documentation for detailed information about available configure options.

Once the file is saved, make sure the script is executable by the command below,

sudo chmod +x build_android.sh

Then execute the script by the command,

./build_android.sh

4. Build Output

The build can take a while to finish depending on your computer speed. Once it’s done, you should be able to find a folder $NDK/sources/ffmpeg-2.0.1/android, which contains arm/lib and arm/include folders.

The arm/lib folder contains the shared libraries, while arm/include folder contains the header files for libavcodec, libavformat, libavfilter, libavutil, libswscale etc.

Note that the arm/lib folder contains both the library files (e.g.: libavcodec-55.so) and symbolic links (e.g.: libavcodec.so) to them. We can remove the symbolic links to avoid confusion.

5. Make ffmpeg Libraries available for Your Projects

Now we’ve compiled the ffmpeg libraries and ready to use them. Android NDK allows us to reuse a compiled module through the import-module build command.

The reason we built our ffmpeg source code under $NDK/sources folder is that NDK build system will search for directories under this path for external modules automatically. To declare the ffmpeg libraries as reusable modules, we’ll need to add a file named $NDK/sources/ffmpeg-2.0.1/android/arm/Android.mk with the following content,

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)      

Below is an example of how we can use the libraries in a Android project’s jni/Android.mk file,

LOCAL_PATH := $(call my-dir)      
include $(CLEAR_VARS)      
LOCAL_MODULE    := tutorial03      
LOCAL_SRC_FILES := tutorial03.c      
LOCAL_LDLIBS := -llog -ljnigraphics -lz -landroid      
LOCAL_SHARED_LIBRARIES := libavformat libavcodec libswscale libavutil      
include $(BUILD_SHARED_LIBRARY)      
$(call import-module,ffmpeg-2.0.1/android/arm)      

Note that we called import-module with the relative path to $NDK/sources for the build system to locate the reusable ffmpeg libraries.

继续阅读