最近一直在忙公司的项目,抽空研究了一下FFmpeg, 期间遇到了一些问题,难受了一个星期,总算弄出来了。在此记录一下,以便后面用时参考。
第一步:要在As中集成NDK插件,并且配置环境变量, 并编写Hellojni项目尝试写一个hello-jni
可以参考
http://blog.csdn.net/tongseng/article/details/53005123
http://blog.csdn.net/u011368551/article/details/50897874
http://www.jianshu.com/p/f3229ed57da9
这些文章
mac下编译 ffmpeg 参考http://www.jianshu.com/p/a1fe55d5683b
第二步:下载FFmpeg
https://ffmpeg.org/download.html#build-windows
第三步:编写build_android.sh脚本
注意:
Paste_Image.png
后来 我写成了我的ndk的全路径了
export TMPDIR="D:/ffmpeg-3.3/jni/temp"
NDK=F:\Local\Android\sdk\ndk-bundle
SYSROOT=F:/Local/Android/sdk/ndk-bundle/platforms/android-21/arch-arm
TOOLCHAIN=F:/Local/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-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
第四步:下载mingw和msys批处理软件
http://download.csdn.net/detail/gedongli/9847433
http://download.csdn.net/download/gedongli/9847507
第五步:在msys命令框中执行build_android.sh脚本进行批处理文件
注意:要在下载的ffmepeg文件路径下执行build_andorid.sh
到此为止,幸运的话就会看到下载的ffmpeg文件夹下多出android文件夹
image.png image.png image.png image.png第六步:从ffmpeg生成的android的lib文件和include文件夹copy到android工程jni目录下
image.png第七步:编写demo.c文件、Android.mk文件、Application.mk文件
1.编写Android.mk文件
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := avcodec
LOCAL_SRC_FILES := libavcodec-57.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := avfilter
LOCAL_SRC_FILES := libavfilter-6.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := avformat
LOCAL_SRC_FILES := libavformat-57.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := avutil
LOCAL_SRC_FILES := libavutil-55.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := swresample
LOCAL_SRC_FILES := libswresample-2.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := swscale
LOCAL_SRC_FILES := libswscale-4.so
include $(PREBUILT_SHARED_LIBRARY)
#######Program
include $(CLEAR_VARS)
LOCAL_MODULE := demo
LOCAL_SRC_FILES := demo.c
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
LOCAL_LDLIBS := -llog -lz
LOCAL_SHARED_LIBRARIES := avcodec avfilter avformat avutil swresample swscale
include $(BUILD_SHARED_LIBRARY)
注意# Program下的编写, 在集成的时候,因为不注意# Program 造成编译时总是找不到文件
2.编写Application.mk
Application.mk文件下就2行
APP_ABI := armeabi-v7a
APP_PLATFORM := android-14
3.编写demo.c文件
#######include <string.h>
#######include <jni.h>
#######include "libavcodec/avcodec.h"
JNIEXPORT jstring JNICALL Java_news_com_android_ffmpegdemo_MainActivity_getStrFromJNI(JNIEnv *env, jclass type){
char info[10000] = { 0 };
sprintf(info, "%s\n", avcodec_configuration());
return (*env)->NewStringUTF(env, info);
}
第八步:
image.png编译后会发现libs包下有相关的ffmepg的.so文件生成
image.png第九步:编写MainActivity并运行
image.png image.png
网友评论