一、準備:
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
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIn5Gcu82Yp9VRE90Qvw1c0V2czF2LcRXZu5ibkN3YuUGZvN2Lc9CX6MHc0RHaiojIsJye.png)
- 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
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIn5Gcu82Yp9VRE90Qvw1c0V2czF2LcRXZu5ibkN3YuUGZvN2Lc9CX6MHc0RHaiojIsJye.png)
- #!/bin/sh
- # for msvc
- MSVC_PREFIX=$(pwd)/out/msvc
- function build_msvc
- {
- ./configure \
- --prefix=$MSVC_PREFIX \
- --enable-static \
- --enable-shared \
- --enable-debug \
- --toolchain=msvc
- make clean
- make
- make install
- }
- 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
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIn5Gcu82Yp9VRE90Qvw1c0V2czF2LcRXZu5ibkN3YuUGZvN2Lc9CX6MHc0RHaiojIsJye.png)
- 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
- function build_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
- make clean
- make
- make install
- }
- 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
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIn5Gcu82Yp9VRE90Qvw1c0V2czF2LcRXZu5ibkN3YuUGZvN2Lc9CX6MHc0RHaiojIsJye.png)
- TOOLROOT=F:/arm-201405
- PREFIX=$(pwd)/out/armlinux
- function build_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
- make clean
- make
- make install
- }
- 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
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIn5Gcu82Yp9VRE90Qvw1c0V2czF2LcRXZu5ibkN3YuUGZvN2Lc9CX6MHc0RHaiojIsJye.png)
- 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 plain copy
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIn5Gcu82Yp9VRE90Qvw1c0V2czF2LcRXZu5ibkN3YuUGZvN2Lc9CX6MHc0RHaiojIsJye.png)
- 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 plain copy
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIn5Gcu82Yp9VRE90Qvw1c0V2czF2LcRXZu5ibkN3YuUGZvN2Lc9CX6MHc0RHaiojIsJye.png)
- 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"
- 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"
- make clean
- make
- make install
- }
- 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.