apt-get update apt-get install yasm apt-get install pkg-config
安装 NDK 本文采用ndk r15c 或 ndk r19
经测试,NDK版本影响不大,只要不是太低就好
ndk r15下载
ndk 最新版下载FFmpeg 版本 本文采用 ffmpeg3.4.5
曾采用4.1.3版本,但是脚本文件有些问题,网上查阅的并不好用,文章末尾提供4.1.3版本sh(不一定好用,需要修改)
修改 configure
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)'
x264脚本 如果不需要,你需要将下方 ffmepg 脚本用的x264的地方加 # 下载 x264
#!/bin/bashNDK=/home/oblvion/Desktop/ffmpeg/androID-ndk-r15cconfigure(){ cpu= PREFIX=$(pwd)/androID/$cpu HOST="" CROSS_PREFIX="" SYSROOT="" if [ "$cpu" == "armv7-a" ] then HOST=arm-linux SYSROOT=$NDK/platforms/androID-21/arch-arm/ CROSS_PREFIX=$NDK/toolchains/arm-linux-androIDeabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androIDeabi- else HOST=aarch64-linux SYSROOT=$NDK/platforms/androID-21/arch-arm64/ CROSS_PREFIX=$NDK/toolchains/aarch64-linux-androID-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-androID- fi ./configure \ --prefix=$PREFIX \ --host=$HOST \ --enable-pic \ --enable-static \ --enalbe-neon \ --extra-cflags="-fPIE -pIE" \ --extra-ldflags="-fPIE -pIE" \ --cross-prefix=$CROSS_PREFIX \ --sysroot=$SYSROOT}build(){ make clean cpu= echo "build $cpu" configure $cpu #-j<cpu核心数> make -j4 make install}#build arm64build armv7-a
ffmpeg 脚本
#!/bin/bashNDK=/home/oblvion/Desktop/ffmpeg/androID-ndk-r15cADDI_CFLAGS="-fPIE -pIE"ADDI_LDFLAGS="-fPIE -pIE"configure(){ cpu= PREFIX=$(pwd)/androID/$cpu x264=$(pwd)/x264/androID/$cpu HOST="" CROSS_PREFIX="" SYSROOT="" ARCH="" if [ "$cpu" == "armv7-a" ] then ARCH="arm" HOST=arm-linux SYSROOT=$NDK/platforms/androID-21/arch-arm/ CROSS_PREFIX=$NDK/toolchains/arm-linux-androIDeabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androIDeabi- else ARCH="aarch64" HOST=aarch64-linux SYSROOT=$NDK/platforms/androID-21/arch-arm64/ CROSS_PREFIX=$NDK/toolchains/aarch64-linux-androID-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-androID- fi ./configure \ --prefix=$PREFIX \ --disable-encoders \ --disable-decoders \ --disable-avdevice \ --disable-static \ --disable-doc \ --disable-ffplay \ --disable-network \ --disable-doc \ --disable-symver \ --enable-neon \ --enable-shared \ --enable-libx264 \ --enable-gpl \ --enable-pic \ --enable-jni \ --enable-pthreads \ --enable-mediacodec \ --enable-encoder=aac \ --enable-encoder=gif \ --enable-encoder=libopenjpeg \ --enable-encoder=libmp3lame \ --enable-encoder=libwavpack \ --enable-encoder=libx264 \ --enable-encoder=mpeg4 \ --enable-encoder=pcm_s16le \ --enable-encoder=png \ --enable-encoder=srt \ --enable-encoder=subrip \ --enable-encoder=yuv4 \ --enable-encoder=text \ --enable-decoder=aac \ --enable-decoder=aac_latm \ --enable-decoder=libopenjpeg \ --enable-decoder=mp3 \ --enable-decoder=mpeg4_mediacodec \ --enable-decoder=pcm_s16le \ --enable-decoder=flac \ --enable-decoder=flv \ --enable-decoder=gif \ --enable-decoder=png \ --enable-decoder=srt \ --enable-decoder=xsub \ --enable-decoder=yuv4 \ --enable-decoder=vp8_mediacodec \ --enable-decoder=h264_mediacodec \ --enable-decoder=hevc_mediacodec \ --enable-hwaccel=h264_mediacodec \ --enable-hwaccel=mpeg4_mediacodec \ --enable-ffmpeg \ --enable-bsf=aac_adtstoasc \ --enable-bsf=h264_mp4toannexb \ --enable-bsf=hevc_mp4toannexb \ --enable-bsf=mpeg4_unpack_bframes \ --enable-cross-compile \ --cross-prefix=$CROSS_PREFIX \ --target-os=androID \ --arch=$ARCH \ --sysroot=$SYSROOT \ --extra-cflags="-I$x264/include $ADDI_CFLAGS" \ --extra-ldflags="-L$x264/lib"}build(){ make clean cpu= echo "build $cpu" configure $cpu make -j4 make install}#build arm64build armv7-a
注意 脚本需要 chmod +x build.sh ,然后 sudo ./脚本执行这个时候 你执行完脚本,如果幸运 ,能拿到 so文件了准备集成到 ndk androID 源码中创建 NDK 项目源码libs 目录下导入 so导入include文件
修改 build.gradle 文件
编辑CMake文件
cmake_minimum_required(VERSION 3.4.1)set(lib_src_DIR ${CMAKE_SOURCE_DIR}/../../../libs/${ANDROID_ABI})add_library( native-lib SHARED native-lib.cpp)add_library( avcodec SHARED importED)set_target_propertIEs( avcodec PROPERTIES importED_LOCATION ${lib_src_DIR}/libavcodec.so)add_library( avfilter SHARED importED)set_target_propertIEs( avfilter PROPERTIES importED_LOCATION ${lib_src_DIR}/libavfilter.so)add_library( avformat SHARED importED)set_target_propertIEs( avformat PROPERTIES importED_LOCATION ${lib_src_DIR}/libavformat.so)add_library( avutil SHARED importED)set_target_propertIEs( avutil PROPERTIES importED_LOCATION ${lib_src_DIR}/libavutil.so)add_library( postproc SHARED importED)set_target_propertIEs( postproc PROPERTIES importED_LOCATION ${lib_src_DIR}/libpostproc.so)add_library( swresample SHARED importED)set_target_propertIEs( swresample PROPERTIES importED_LOCATION ${lib_src_DIR}/libswresample.so)add_library( swscale SHARED importED)set_target_propertIEs( swscale PROPERTIES importED_LOCATION ${lib_src_DIR}/libswscale.so)find_library( log-lib log)include_directorIEs(${CMAKE_SOURCE_DIR}/src/main/cpp/include)target_link_librarIEs( native-lib avcodec avfilter avformat avutil postproc swresample swscale ${log-lib})
修改原来的 natice-lib.cpp 文件#include <jni.h>#include <string>#include <androID/log.h>extern "C" {#include "include/libavcodec/avcodec.h"#include "include/libavfilter/avfilter.h"#include "include/libavformat/avformat.h"#include "include/libavutil/imgutils.h"#include "include/libswresample/swresample.h"#include "include/libswscale/swscale.h"#include "include/libx264/x264.h"}extern "C"JNIEXPORT Jstring JNICALLJava_com_wmtc_ndktest_MainActivity_stringFromFFmpeg( jnienv *env, jobject /* this */) { char info[10000] = {0}; sprintf(info, "%s\n", avcodec_configuration()); return env->NewStringUTF(info);}
OK。调用,执行,不出意外看到如下:
ninja: error: xxxxxx missing and no kNown rule to make it
因为你的 CMake文件错误,检查一下
undefined reference to 'avcodec_configuration()'
看看是否
extern "C"
是这样导入的 源码文件extern "C" { #include "include/libavcodec/avcodec.h" #include "include/libavfilter/avfilter.h" #include "include/libavformat/avformat.h" #include "include/libavutil/imgutils.h" #include "include/libswresample/swresample.h" #include "include/libswscale/swscale.h" #include "include/libx264/x264.h" }
感谢一下文章提供的帮助 :编译相关文章 总结 以上是内存溢出为你收集整理的FFmepg编译及CMake 集成到 Android全部内容,希望文章能够帮你解决FFmepg编译及CMake 集成到 Android所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)