我已经编译ffmpeg-1.2
成libffmpeg.so
,然后像这样在 Jni 中加载它:
handle = dlopen("/data/data/com.example.hellojni/lib/libffmpeg.so", RTLD_LAZY);
LOGE("%s() handle=%p", __func__, handle);
if (handle) {
func_t dlfunc = (func_t)dlsym(handle, "main");
LOGE("%s() dlfunc=%p", __func__, dlfunc);
if (dlfunc) {
err = dlfunc(argc, argv); // Crashed!!
日志猫:
17:11:10.499: E/Videokit(6642): __run_ffmpeg_main() handle=0x400c8370 // got handle!!
17:11:10.499: E/Videokit(6642): __run_ffmpeg_main() dlfunc=0x511326f8 // got symbol!!
17:11:10.689: D/BluetoothAdapter(773): 1094265936: getState() : mService = null. Returning STATE_OFF
17:11:10.709: W/Settings(773): Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
17:11:10.949: I/ActivityManager(492): Process com.example.hellojni (pid 6642) has died.
17:11:10.969: D/dalvikvm(6655): Late-enabling CheckJNI
17:11:10.969: I/ActivityManager(492): Start proc com.example.hellojni for activity com.example.hellojni/.HelloJni: pid=6655 uid=10065 gids={50065, 1006, 1015, 1028}
17:11:11.009: I/dalvikvm(6655): Turning on JNI app bug workarounds for target SDK version 8…
17:11:11.049: D/dalvikvm(6655): Trying to load lib /data/app-lib/com.example.hellojni-1/libhello-jni.so 0x40f0a808
17:11:11.049: D/dalvikvm(6655): Added shared lib /data/app-lib/com.example.hellojni-1/libhello-jni.so 0x40f0a808
17:11:11.049: D/dalvikvm(6655): No JNI_OnLoad found in /data/app-lib/com.example.hellojni-1/libhello-jni.so 0x40f0a808, skipping init
安卓.mak:
LOCAL_PATH := $(call my-dir)
FFMPEG_DIR := $(LOCAL_PATH)/ffmpeg-1.2.1
FFMPEG_LIBS := $(addprefix $(FFMPEG_DIR)/, \
....)
# libffmpeg
include $(CLEAR_VARS)
LOCAL_MODULE := ffmpeg
LOCAL_CFLAGS += -g -I$(FFMPEG_DIR) -Wno-deprecated-declarations
LOCAL_LDLIBS += -llog -lz $(FFMPEG_LIBS) # x264/libx264.a
LOCAL_C_INCLUDES := ...
LOCAL_SRC_FILES := ...
include $(BUILD_SHARED_LIBRARY)
# libhello-jni
include $(CLEAR_VARS)
LOCAL_ALLOW_UNDEFIND_SYMBOLS=false
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.c
LOCAL_LDLIBS := -ldl -llog -ljnigraphics -lz -lm
include $(BUILD_SHARED_LIBRARY)