关闭

使用ndk 编译 编译ffmpeg 并使用

37人阅读 评论(0) 收藏 举报
分类:

有句话说得好,工欲善其事,必先利其器
1、 环境 ubuntu 我的是14.04 android-ndk64-r9b
2、下载ffmpeg http://www.ffmpeg.org/download.html 我现在的是最新版本ffmpeg-3.1.3
3、下载ndk 解压,配置好环境
4、创建jni文件夹,把下载好的ffmpeg解压到穿件号的文件夹中,因为ndk默认先编译jni文件中的文件
5

找到 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.57),不会被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)'  

5、创建解压好的ffmpeg文件中先建一个config.sh执行脚本

#!/bin/bash

#配置NDK路径
export NDK=/home/lilaishun/ndk/android-ndk-r9b
#配置工具链
export PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt
#配置平台
export PLATFORM=$NDK/platforms/android-8/arch-arm

#配置编译好了之后的文件输出目录,$(pwd)当前目录下
export PREFIX=$(pwd)/androids/
build_one(){
  ./configure --target-os=linux --prefix=$PREFIX \
--enable-cross-compile \
--enable-runtime-cpudetect \
--disable-asm \
--arch=arm \
--cc=$PREBUILT/linux-x86_64/bin/arm-linux-androideabi-gcc \
--cross-prefix=$PREBUILT/linux-x86_64/bin/arm-linux-androideabi- \
--disable-stripping \
--nm=$PREBUILT/linux-x86_64/bin/arm-linux-androideabi-nm \
--sysroot=$PLATFORM \
--enable-gpl --enable-shared --disable-static --enable-nonfree --enable-version3 --enable-small \
--enable-zlib --disable-ffprobe --disable-ffplay --disable-ffmpeg --disable-ffserver --disable-debug \
--extra-cflags="-fPIC -DANDROID -D__thumb__ -mthumb -Wfatal-errors -Wno-deprecated -mfloat-abi=softfp -marm -march=armv7-a" 
}
build_one
make -j4
make install

6、打开终端,cd到脚本的位置 chmod +x config.sh//给脚本添加执行权限
./config.sh
这是终端会开始执行脚本,并编译大约20多分钟编译停止后
在androids文件会生成也就是我们想要的库文件
.so文件不带数字的是软连接,可以删掉头文件

7.创建android项目并创建一个jni文件夹
把编译好的文件拷贝到jni中,新建Android.mk文件

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := avcodec-57-prebuilt
LOCAL_SRC_FILES :=libavcodec-57.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := avdevice-57-prebuilt
LOCAL_SRC_FILES :=libavdevice-57.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := avfilter-6-prebuilt
LOCAL_SRC_FILES :=libavfilter-6.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := avformat-57-prebuilt
LOCAL_SRC_FILES :=libavformat-57.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE :=  avutil-55-prebuilt
LOCAL_SRC_FILES :=libavutil-55.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE :=  swresample-2-prebuilt
LOCAL_SRC_FILES :=libswresample-2.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE :=  swscale-4-prebuilt
LOCAL_SRC_FILES :=libswscale-4.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE :=  postproc-54-prebuilt
LOCAL_SRC_FILES :=libpostproc-54.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE    := test_jni
LOCAL_SRC_FILES := test_jni.cpp
LOCAL_LDLIBS := -llog -ljnigraphics -lz -landroid
LOCAL_SHARED_LIBRARIES :=avcodec-57-prebuilt avfilter-6-prebuilt avfilter-6-prebuilt avformat-57-prebuilt avutil-55-prebuilt swscale-4-prebuilt postproc-54-prebuilt swresample-2-prebuilt


include $(BUILD_SHARED_LIBRARY)

下面是我编译好的库文件测试可以使用需要的可以去下载
http://download.csdn.net/detail/qq_18144521/9616304

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:39次
    • 积分:13
    • 等级:
    • 排名:千里之外
    • 原创:1篇
    • 转载:0篇
    • 译文:0篇
    • 评论:1条
    文章分类
    文章存档
    最新评论