Skip to content

Instantly share code, notes, and snippets.

@halfninja
Created February 15, 2011 20:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halfninja/828227 to your computer and use it in GitHub Desktop.
Save halfninja/828227 to your computer and use it in GitHub Desktop.
Building FFMPEG+libx264 for Android NDK
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := videokit
FFMPEG_LIBS := $(shell find ffmpeg -name '*.a')
LOCAL_CFLAGS += -Iffmpeg
LOCAL_LDLIBS += -llog $(FFMPEG_LIBS)
LOCAL_SRC_FILES := jni_interface.c
include $(BUILD_SHARED_LIBRARY)
# There are a few ways to build this using the NDK. Using version r5b here as it introduces
# better support for standalone building, so we can use FFMPEG's configure and make and a
# minimal Android.mk to pull it all together
# should point to where your NDK is
NDK=~/android-ndk-r5b
# get ffmpeg
git clone git://git.ffmpeg.org/ffmpeg.git
cd ffmpeg
# build a standalone toolchain - you could install this to somewhere more permanent
$NDK/build/tools/make-standalone-toolchain.sh --install-dir=/tmp/android/toolchain
export PATH=$PATH:$NDK:/tmp/android/toolchain/bin
./configure --enable-cross-compile \
--arch=arm5te \
--enable-armv5te \
--target-os=linux \
--disable-stripping \
--disable-neon \
--enable-version3 \
--disable-shared \
--enable-static \
--enable-gpl \
--enable-memalign-hack \
--cc=arm-linux-androideabi-gcc \
--ld=arm-linux-androideabi-ld \
--extra-cflags="-fPIC -DANDROID -D__thumb__ -mthumb" \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-network \
--disable-mpegaudio-hp \
--disable-avdevice \
--enable-zlib
# make, and wait
make

Instructions

  1. place Android.mk and jni_interface.c in the jni directory
  2. follow instructions to get and build FFMPEG

This has been built on a 64-bit Ubuntu. It might work on Windows, but I’m on Windows and found it’s much easier to use a copy of Ubuntu inside VirtualBox for compiling.

#include "libavformat/avformat.h"
#include "libavdevice/avdevice.h"
#include "libswscale/swscale.h"
#include <android/log.h>
#include <jni.h>
int init()
{
av_register_all();
__android_log_write(ANDROID_LOG_ERROR, "VideoKit", "Better implement some JNI methods!")
}
/* Compile your Java class with native methods then run javah on it to generate a header file */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment