How to Build ffmpeg with NDK r9

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.

For real examples to how to use the ffmpeg libraries in Android app, please
refer to my github repo ofandroid-ffmpeg-tutorial.

转自:http://www.roman10.net/how-to-build-ffmpeg-with-ndk-r9/

How to Build ffmpeg with NDK r9,码迷,mamicode.com

时间: 2024-10-02 03:33:03

How to Build ffmpeg with NDK r9的相关文章

Android NDK R9环境配置,开发教程

最近,在学习android ndk开发,配置环境的时候遇到了些问题,总算不负有心人--在这里记录哈过程,与筒子们分享哈--想学NDK的筒子们有福啦-- 教程本人亲测,非copy的-- 如有什么不明白的地方,可以留言 大神也可以进来瞧瞧有什么不对的地方,请指教两招 ----------------------------------------------------------------------------------------------------------------------

win下编译ffmpeg库,Compile and build ffmpeg library and dll on Windows x64( 正版)

转载请注明:来自EricKing,thanks 从没想到编一个library这么坑爹,再次提醒各位百度的东西只能参考,想节约时间还是要到官网上去查看docum.不废话了,开始详细过程: ——>1.搭建Win下的GCC编译环境(因为win下vs不支持ffmpeg的compile 和build,官网上也有说这一点) ——>2.下载latest ffmpeg source(后面附官网地址),想办法将编译后的文件做成dll,这是win下编程调试的核心 (这里就用到vs下的一个vc的bash文件叫vcv

Android NDK R9 安装配置 无需Cygwin

转自:http://www.cr173.com/soft/66623.html NDK是一个工具集,可让您实现您的应用程序使用本机代码的语言,如C和C + +.Android NDK 是在SDK前面又加上了“原生”二字,即Native Development Kit,因此又被Google称为“NDK”. 在此之前,Android平台的第三方应用程序均是依靠基于Java的Dalvik特制虚拟机进行开发的.原生SDK的公布可以让开发者更加直接的接触Android系统资源,并使用传统的C或C++语言编

ubuntu12.10+NDK r9 编译 ffmpeg 的一些参考资料

首先入门级的 编译宝典: https://trac.ffmpeg.org/wiki/CompilationGuide/Android http://www.roman10.net/how-to-build-ffmpeg-with-ndk-r9/ 二进制文件+so库: https://github.com/cine-io/android-ffmpeg-with-rtmp 一个利用二进制可执行文件的例子: https://github.com/vanevery/Android-MJPEG-Video

cocos2d-x在NDK r9下的编译问题

Compile++ thumb  : cocos2dx_static <= CCCommon.cpp E:/cocos2d-x-2.x/cocos2d-x-2.1.4/projects/T3/proj.android/../../../cocos2dx/platform/android/CCCommon.cpp: In function 'void cocos2d::CCLog(char const*, ...)': E:/cocos2d-x-2.x/cocos2d-x-2.1.4/projec

NDK Build 用法(NDK Build)(转)

1.ndk-build的用法 Android NDKr4引入了一个新的.小巧的shell脚本ndk-build,来简化源码编译. 该文件位于NDK根目录,进入你的工程根目录或子目录之后,在命令行下调用即可.例如: cd $PROJECT $NDK/ndk-build NDK指向你的NDK的安装目录,PROJECT指向你的Android工程目录.建议将ndk-build所在目录加入PATH环境变量或设置alias. 2.ndk-build的选项 所有给ndk-build的选项都会直接传给GNU M

Android/NDK环境下FFmpeg及AAC,MP3,X264的编译

本篇介绍在Android/Ndk环境下FFmpeg的编译及使用, FFmpeg自带了H264.AAC.MP3的解码器,但却没有(或没有好的)相应的编码器.相应的编码器需要使用第三方库.推荐使用的第三方库为x264(H264编码) .FDK_AAC(AAC编码),lame(MP3编码). 在顺序上,应该先编译好第三方库,最后再编译FFmpeg库. [本书说明:本文作者:邵发,本文选自<FFmpeg视音频编程指南>.有关本书的详细信息请访问官网:http://www.afanihao.cn ] [

Windows环境下使用cygwin ndk_r9c编译FFmpeg

 一.废话 最近学习,第一步就是编译.我们需要编译FFmpag,x264,fdk_aac,一步步来.先来讲一下FFmpeg,网上说的很多都是几百年前的,我亲测完美可用 联系我可以直接评论,也可以加我QQ:11635423  二.干货  我能力有限,但是我希望我写的东西能够让更多的人能够接受.我也是刚刚接触.做一个记录,也希望能够对其他人有好处. 几个概念理解一下:不理解也没关系.用了之后再说慢慢就理解了.主要是因为我们是windows 先是cygwin下的一些概念:        unix st

iOS平台基于ffmpeg的视频直播技术揭秘

现在非常流行直播,相信很多人都跟我一样十分好奇这个技术是如何实现的,正好最近在做一个ffmpeg的项目,发现这个工具很容易就可以做直播,下面来给大家分享下技术要点: 首先你得编译出ffmpeg运行所需的静态库,这个百度一下有很多内容,这里我就不多说了,建议可以用Github上的一个开源脚本来编译,简单粗暴有效率. 地址:GitHub - kewlbear/FFmpeg-iOS-build-script: Shell scripts to build FFmpeg for iOS and tvOS