ubuntu编译FFmpeg其实是比较简单的
工具:
VM虚拟机
ubuntu.iso镜像 https://yunpan.cn/cRPbJJdWNuDJR 访问密码 a216
Android NDK https://yunpan.cn/cRPbZvyptWGLN 访问密码 90e8
FFmpeg 2.2 https://yunpan.cn/cRPbjNyDBVcHT 访问密码 eb77
FFmpeg 3.0.2 最新 https://yunpan.cn/cRPbQqA8fB4cZ 访问密码 c6c4
步骤:
安装VM,ubuntu镜像就掠过了。。。请参考 http://jingyan.baidu.com/article/c14654134960d80bfcfc4cf3.html
想复制粘贴的话安装tools 请参考 http://jingyan.baidu.com/article/3065b3b6e8dedabecff8a435.html
解压所有用到的文件
准备工作做好了
先编译FFmpeg 2.2把
在ffmpeg2.2下创建build_android.sh文件
内容如下
#!/bin/bash
NDK=/home/zhang/Desktop/wode/r10+3.02/android-ndk-r10b
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-ffserver \
--enable-cross-compile \
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
--target-os=linux \
--arch=arm \
--sysroot=$SYSROOT \
--extra-cflags="-Os -fpic $ADDI_CFLAGS" \
--extra-ldflags="$ADDI_LDFLAGS" \
$ADDITIONAL_CONFIGURE_FLAG
}
CPU=arm
PREFIX=$(pwd)/android/$CPU
ADDI_CFLAGS="-marm"
build_one
NDK SYSROOT TOOLCHAIN这三个一定是你自己系统下的路径
更改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)'
替换为:
SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
LIB_INSTALL_EXTRA_CMD='$$(RANLIB)"$(LIBDIR)/$(LIBNAME)"'
SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
SLIB_INSTALL_LINKS='$(SLIBNAME)'
右击空白处打开终端
./build_android.sh 运行
成功
make命令
开始编译了,(大概编译10来分钟)编译完后执行 make install 就生成了一个android目录
android目录
创建一个Android 工程
我这里是Android Studio“
com_example_administrator_myapplication_CameraAc.h里的内容需要手动生成
javah -d jni -classpath C:\Users\Administrator\AppData\Local\Android\Sdk\platforms\android-21\android.jar;.\app\build\intermediates\classes\debug com.exam
javah -d (jni新建文件名) -classpath (sdk路径);(class 路径) (class文件名,包括包名)
CameraAc.java里的内容
public class CameraAc extends Activity {
private Button bt_up;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bt_up = (Button)findViewById(R.id.bt_up);
int codecID = 28;
int res = avcodeDecoder(codecID);
if (res == 1) {
bt_up.setText("Success!");
} else {
bt_up.setText("Failed!");
}
}
static {
System.loadLibrary("avutil-52");
System.loadLibrary("avcodec-55");
System.loadLibrary("swresample-0");
System.loadLibrary("avformat-55");
System.loadLibrary("swscale-2");
System.loadLibrary("avfilter-4");
System.loadLibrary("avdevice-55");
System.loadLibrary("ffmpeg_codec");
}
public native int avcodeDecoder(int codecID);
}
Android.mk里的内容
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := avcodec-55-prebuilt
LOCAL_SRC_FILES := prebuilt/libavcodec-55.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := avdevice-55-prebuilt
LOCAL_SRC_FILES := prebuilt/libavdevice-55.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := avfilter-4-prebuilt
LOCAL_SRC_FILES := prebuilt/libavfilter-4.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := avformat-55-prebuilt
LOCAL_SRC_FILES := prebuilt/libavformat-55.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := avutil-52-prebuilt
LOCAL_SRC_FILES := prebuilt/libavutil-52.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := avswresample-0-prebuilt
LOCAL_SRC_FILES := prebuilt/libswresample-0.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := swscale-2-prebuilt
LOCAL_SRC_FILES := prebuilt/libswscale-2.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := ffmpeg_codec
LOCAL_SRC_FILES := com_example_administrator_myapplication_CameraAc.c
LOCAL_LDLIBS := -llog -ljnigraphics -lz -landroid
LOCAL_SHARED_LIBRARIES := avcodec-55-prebuilt avdevice-55-prebuilt avfilter-4-prebuilt avformat-55-prebuilt avutil-52-prebuilt
include $(BUILD_SHARED_LIBRARY)
Application.mk里的内容
#APP_ABI := armeabi
#APP_ABI := armeabi-v7a
APP_ABI := all
APP_PLATFORM := android-10
com_example_administrator_myapplication_CameraAc.c里的内容
#include <stddef.h>
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "com_example_administrator_myapplication_CameraAc.h"
JNIEXPORT jint JNICALL Java_com_example_administrator_myapplication_CameraAc_avcodeDecoder
(JNIEnv *env, jobject obj, jint codecID)
{
AVCodec *codec = NULL;
av_register_all();
codec= avcodec_find_decoder(codecID);
if(codec != NULL)
{
return 1;
}
else
{
return-1;
}
}
妹的一直报错,记得把FUCKjni改成jni
果断用别的方法
新建一个jni文件夹,把东西都放进去
编译
生成lib文件了
编译好之后jni外面的文件夹下就会有lib目录
把jni文件夹弄出去,然后运行
3.02和2.2编译步骤都一样,编译出来的.so文件不一样而已
**
** http://download.csdn.net/detail/t1_one/9550614
特此感谢
http://blog.csdn.net/gobitan/article/details/22750719文章带来的灵感