使用 NDK r9 编译ffmpeg
2014-04-02 11:16
363 查看
转自:http://wang-peng1.iteye.com/blog/2004897
1. 环境 ubuntu 我的是13.10 ndk r9d x86_64
2. 下载ffmpeg http://www.ffmpeg.org/download.html 找到
2.1.3 was released on 2014-01-15. It is the latest stable FFmpeg release from the 2.1 release branch, which was cut from master on 2013-10-28. Amongst lots of other changes, it includes all changes from ffmpeg-mt, libav master of 2013-10-27, libav 9 as of 2013-10-27.
It includes the following library versions:
Download bzip2 tarball 下载
下载之后 解压到 $NDK/sources 文件夹下面,这是因为编译快捷以及方便使用
3. 找到 ffmpeg-xxx/configure
找到如下几行:
Java代码
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)'
上面几行会导致libavcodec.so.<version>
(e.g. libavcodec.so.55),不会被android承认 ,修改为;
Java代码
SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
LIB_INSTALL_EXTRA_CMD='$$(RANLIB) "$(LIBDIR)/$(LIBNAME)"'
SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
SLIB_INSTALL_LINKS='$(SLIBNAME)'
4. 复制下面的代码到文本中 并命名为 build_android.sh,注意这个文件应该保存到 ffmpeg-xxx/configure
同一个文件夹下
Java代码
#!/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
注意修改 NDK=$HOME/Desktop/adt/android-ndk-r9
这行
5. 执行
Java代码
sudo chmod +x build_android.sh
./build_android.sh
6.输出 $NDK/sources/ffmpeg-xxx/android,
arm/lib 和arm/include
注意 arm/lib包含了两个 library files (e.g.: libavcodec-55.so) 和 symbolic links (e.g.: libavcodec.so) 我们需要删掉 symbolic links .
7. 让ffmpeg
Libraries用在我们的工程下
为了使ffmpeg libraries 可以作为 reusable modules, 在jni文件夹中创建lib文件夹,将.so文件拷入lib文件夹中,添加Android.mk 使用如下内容,
Java代码
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)
8.使用
使用 libraries在Android project’s jni/Android.mk file,
Java代码
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-subdir-java-files)
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)
这里你就会发现 我们用到了source中调用了 import-module 使用相对路径去调用。
参考:http://blog.csdn.net/cbzhaojay/article/details/8524915
问题2
:libavutil/parseutils.h:158:64: warning: ‘struct tm’ declared inside parameter listlibavutil/parseutils.h:171:8: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘av_timegm’libavutil/parseutils.c:441:64: warning: ‘struct tm’ declared inside parameter
listlibavutil/parseutils.c:441:7: error: conflictingtypes for ‘av_small_strptime’libavutil/parseutils.h:158:7: note: previous declaration of ‘av_small_strptime’ was here
In file included from jni/libavutil/parseutils.c:32:0:
jni/libavutil/parseutils.h:172:64: warning: 'struct tm' declared inside parameter list [enabled by default]
jni/libavutil/parseutils.h:172:64: warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default]
jni/libavutil/parseutils.h:185:25: warning: 'struct tm' declared inside parameter list [enabled by default]
jni/libavutil/parseutils.c:463:64: warning: 'struct tm' declared inside parameter list [enabled by default]
jni/libavutil/parseutils.c:463:7: error: conflicting types for 'av_small_strptime'
jni/libavutil/parseutils.h:172:7: note: previous declaration of 'av_small_strptime' was here
jni/libavutil/parseutils.c: In function 'av_small_strptime':
jni/libavutil/parseutils.c:485:19: error: dereferencing pointer to incomplete type
jni/libavutil/parseutils.c:491:19: error: dereferencing pointer to incomplete type
jni/libavutil/parseutils.c:497:19: error: dereferencing pointer to incomplete type
jni/libavutil/parseutils.c:503:19: error: dereferencing pointer to incomplete type
jni/libavutil/parseutils.c:509:19: error: dereferencing pointer to incomplete type
jni/libavutil/parseutils.c:515:19: error: dereferencing pointer to incomplete type
解决方法看:
把 ffmpeg/libavutil/time.h更名为avtime.h,
同时修改下面文件中的引用libavutil/time.h为libavutil/avtime.h
ffmpeg/libavformat/avformat.h:211
ffmpeg/libavformat/avio.c:25
ffmpeg/libavformat/hls.c:33
ffmpeg/libavformat/mux.c:39:30
ffmpeg/libavformat/utils.c:40
ffmpeg/libavutil/time.c:36
原因是重复引用了time.h,在parseutils.c和parseutils.h文件中都引用了,而libavutil/time.h也会被编译的时候引用,而<time.h>却使用的是android
ndk工具中的,造成了冲突。
1. 环境 ubuntu 我的是13.10 ndk r9d x86_64
2. 下载ffmpeg http://www.ffmpeg.org/download.html 找到
FFmpeg 2.1.3 "Fourier"
2.1.3 was released on 2014-01-15. It is the latest stable FFmpeg release from the 2.1 release branch, which was cut from master on 2013-10-28. Amongst lots of other changes, it includes all changes from ffmpeg-mt, libav master of 2013-10-27, libav 9 as of 2013-10-27.It includes the following library versions:
libavutil 52. 48.101 libavcodec 55. 39.101 libavformat 55. 19.104 libavdevice 55. 5.100 libavfilter 3. 90.100 libswscale 2. 5.101 libswresample 0. 17.104 libpostproc 52. 3.100
Download bzip2 tarball 下载
下载之后 解压到 $NDK/sources 文件夹下面,这是因为编译快捷以及方便使用
3. 找到 ffmpeg-xxx/configure
找到如下几行:
Java代码
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)'
上面几行会导致libavcodec.so.<version>
(e.g. libavcodec.so.55),不会被android承认 ,修改为;
Java代码
SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
LIB_INSTALL_EXTRA_CMD='$$(RANLIB) "$(LIBDIR)/$(LIBNAME)"'
SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
SLIB_INSTALL_LINKS='$(SLIBNAME)'
4. 复制下面的代码到文本中 并命名为 build_android.sh,注意这个文件应该保存到 ffmpeg-xxx/configure
同一个文件夹下
Java代码
#!/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
注意修改 NDK=$HOME/Desktop/adt/android-ndk-r9
这行
5. 执行
Java代码
sudo chmod +x build_android.sh
./build_android.sh
6.输出 $NDK/sources/ffmpeg-xxx/android,
arm/lib 和arm/include
注意 arm/lib包含了两个 library files (e.g.: libavcodec-55.so) 和 symbolic links (e.g.: libavcodec.so) 我们需要删掉 symbolic links .
7. 让ffmpeg
Libraries用在我们的工程下
为了使ffmpeg libraries 可以作为 reusable modules, 在jni文件夹中创建lib文件夹,将.so文件拷入lib文件夹中,添加Android.mk 使用如下内容,
Java代码
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)
8.使用
使用 libraries在Android project’s jni/Android.mk file,
Java代码
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-subdir-java-files)
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)
这里你就会发现 我们用到了source中调用了 import-module 使用相对路径去调用。
参考:http://blog.csdn.net/cbzhaojay/article/details/8524915
问题2
:libavutil/parseutils.h:158:64: warning: ‘struct tm’ declared inside parameter listlibavutil/parseutils.h:171:8: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘av_timegm’libavutil/parseutils.c:441:64: warning: ‘struct tm’ declared inside parameter
listlibavutil/parseutils.c:441:7: error: conflictingtypes for ‘av_small_strptime’libavutil/parseutils.h:158:7: note: previous declaration of ‘av_small_strptime’ was here
In file included from jni/libavutil/parseutils.c:32:0:
jni/libavutil/parseutils.h:172:64: warning: 'struct tm' declared inside parameter list [enabled by default]
jni/libavutil/parseutils.h:172:64: warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default]
jni/libavutil/parseutils.h:185:25: warning: 'struct tm' declared inside parameter list [enabled by default]
jni/libavutil/parseutils.c:463:64: warning: 'struct tm' declared inside parameter list [enabled by default]
jni/libavutil/parseutils.c:463:7: error: conflicting types for 'av_small_strptime'
jni/libavutil/parseutils.h:172:7: note: previous declaration of 'av_small_strptime' was here
jni/libavutil/parseutils.c: In function 'av_small_strptime':
jni/libavutil/parseutils.c:485:19: error: dereferencing pointer to incomplete type
jni/libavutil/parseutils.c:491:19: error: dereferencing pointer to incomplete type
jni/libavutil/parseutils.c:497:19: error: dereferencing pointer to incomplete type
jni/libavutil/parseutils.c:503:19: error: dereferencing pointer to incomplete type
jni/libavutil/parseutils.c:509:19: error: dereferencing pointer to incomplete type
jni/libavutil/parseutils.c:515:19: error: dereferencing pointer to incomplete type
解决方法看:
把 ffmpeg/libavutil/time.h更名为avtime.h,
同时修改下面文件中的引用libavutil/time.h为libavutil/avtime.h
ffmpeg/libavformat/avformat.h:211
ffmpeg/libavformat/avio.c:25
ffmpeg/libavformat/hls.c:33
ffmpeg/libavformat/mux.c:39:30
ffmpeg/libavformat/utils.c:40
ffmpeg/libavutil/time.c:36
原因是重复引用了time.h,在parseutils.c和parseutils.h文件中都引用了,而libavutil/time.h也会被编译的时候引用,而<time.h>却使用的是android
ndk工具中的,造成了冲突。
相关文章推荐
- iOS7开发的新特性之AirDrop
- unity3d教程游戏目标 (GameObject) 和组件 (Component) 的联系
- git 获取历史版本
- JavaScript 获取Select标签选中的项
- CMAKE的使用
- windows phone应用程序版本升级
- ios开发中view.layer.shouldRasterize = YES 的使用说明
- 虚拟机VMware下安装CentOS6.4
- 重载、覆盖和隐藏
- 数据结构之简单表达式计算器(读入中缀转后缀,通过后缀计算结果)
- C#中的匿名函数和闭包
- 解决远程访问mysql时变慢
- 简单利用触发器监控表记录的更改
- ios开发中view.layer.shouldRasterize = YES 的使用说明
- 转载 调试器工作原理
- C++中null与0的区别
- Java监听器与观察者模式
- 关于phonegap+jQuery mobile 登录链接验证
- 求质数算法的N种境界 (N > 10)
- UltraEdit编辑器删除空格,删除空行和将多行合并为一段。