1

我已经编译了最新的 Bambuser FFmpeg 项目,其中包含 sh 文件。我已将该目录复制到我的 Android 项目中的“jni”目录中。现在,我尝试使用 r8e ndk 编译 ffmpeg 库。

但是,我不知道 c 文件应该是怎样的。一方面,c 文件可能类似于 ffmepg.c 库的主要功能。Java 类使用字符串数组调用此函数,如ffmpeg4android所做的那样。

另一方面,它可能是一个包含大量 ffmpeg 函数的函数,如 av_register_all()、av_register_all()、...

这样做的最佳形式是什么?对构建c文件有什么帮助吗?

安卓.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
MY_LIB_PATH := armeabi-v7a/lib
LOCAL_MODULE := libavcore
LOCAL_SRC_FILES := $(MY_LIB_PATH)/libavcore.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libavformat
LOCAL_SRC_FILES := $(MY_LIB_PATH)/libavformat.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libavcodec
LOCAL_SRC_FILES := $(MY_LIB_PATH)/libavcodec.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libavdevice
LOCAL_SRC_FILES := $(MY_LIB_PATH)/libavdevice.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libavfilter
LOCAL_SRC_FILES := $(MY_LIB_PATH)/libavfilter.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libavutil
LOCAL_SRC_FILES := $(MY_LIB_PATH)/libavutil.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libswscale
LOCAL_SRC_FILES := $(MY_LIB_PATH)/libswscale.so
include $(PREBUILT_SHARED_LIBRARY)


#local_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := libtest_jni
LOCAL_SRC_FILES := libtest/ffmpeg.c

LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/armeabi-v7a/include \
    $(LOCAL_PATH)/ffmpeg-android/ffmpeg 
    LOCAL_LDLIBS := -L$(NDK_PLATFORMS_ROOT)/$(TARGET_PLATFORM)/arch-arm/usr/lib -   L$(LOCAL_PATH) -L$(LOCAL_PATH)/armeabi-v7a/lib/ -lavformat -lavcodec -lavdevice -lavfilter -   lavutil -lswscale -llog -lz -lm
    #dl -lgcc

    include $(BUILD_SHARED_LIBRARY)

Java 文件:

public class MainActivity extends Activity {

public native String loadInfo (String name);

static {
    System.loadLibrary("avutil");
    System.loadLibrary("swscale");
    System.loadLibrary("avcore");
    System.loadLibrary("avfilter");
    System.loadLibrary("avdevice");
    System.loadLibrary("avcodec");
    System.loadLibrary("avformat");

    System.loadLibrary("test_jni");
    }


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    File rootsd = Environment.getExternalStorageDirectory();
    File dcim = new File(rootsd, "DCIM");
    File file = new File(dcim, "mm.mp4");

    Log.i("INFO: ", file.toString());

    loadInfo(file.toString());

}

}

ffmepg.c的主要功能c文件复制

 #include <jni.h>  
 #include <android/log.h>  

 #include "cmdutils.h"
 #include "config.h"
 #include <ctype.h>
 #include <string.h>
 #include <math.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <signal.h>
 #include <limits.h>
 #include <unistd.h>
 #include "libavformat/avformat.h"
 #include "libavdevice/avdevice.h"
 #include "libswscale/swscale.h"
 #include "libavcodec/opt.h"
 //#include "libavcodec/audioconvert.h"
 #include "libavcore/audioconvert.h"
 #include "libavcore/parseutils.h"
 #include "libavcore/samplefmt.h"
 //#include "libavutil/colorspace.h"
 #include "libavutil/fifo.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/avstring.h"
 //#include "libavutil/libm.h"
 //#include "libavformat/os_support.h"

 #if CONFIG_AVFILTER
 # include "libavfilter/avfilter.h"
 # include "libavfilter/avfiltergraph.h"
 //# include "libavfilter/vsrc_buffer.h"
 #endif

 #if HAVE_SYS_RESOURCE_H
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/resource.h>
 #elif HAVE_GETPROCESSTIMES
 #include <windows.h>
 #endif
 #if HAVE_GETPROCESSMEMORYINFO
 #include <windows.h>
 #include <psapi.h>
 #endif

 #if HAVE_SYS_SELECT_H
 #include <sys/select.h>
 #endif

 #if HAVE_TERMIOS_H
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include <sys/time.h>
 #include <termios.h>
 #elif HAVE_CONIO_H
 #include <conio.h>
 #endif
 #include <time.h>

 #include "libavutil/avassert.h"

 void Java_es_prueba_ffmpeg_MainActivity_loadInfo (JNIEnv * env, jobject this, jstring filename)  {

int64_t ti;

av_log_set_flags(AV_LOG_SKIP_REPEATED);

avcodec_register_all();

#if CONFIG_AVDEVICE
     avdevice_register_all();
 #endif

 #if CONFIG_AVFILTER
     avfilter_register_all();
 #endif

av_register_all();


init_opts();
}

它在 init_opts(); 中崩溃;错误:未定义对“init_opts”的引用,但我包含了具有此功能的 cmdutils.h 文件。

另一个使用 ffmpeg 函数的 c 文件

 #include <jni.h>
 #include <android/log.h>

 #include "libavcodec/avcodec.h"
 #include "libavformat/avformat.h"

 #define LOG_TAG "mylib"
 #define LOGI(...)  __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
 #define LOGE(...)  __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)

 jint Java_es_prueba_ffmpeg_MainActivity_loadInfo(JNIEnv * env, jobject this, jstring filename) {
av_register_all();

AVFormatContext *pFormatCtx;
const jbyte *str;
str = (*env)->GetStringUTFChars(env, filename, NULL);

if(av_open_input_file(&pFormatCtx, str, NULL, 0, NULL)!=0)
{
    LOGE("Can't open file '%s'\n", str);
}
else
{
    LOGI("File was opened\n");
    LOGI("File '%s', Codec %s",
        pFormatCtx->filename,
        pFormatCtx->iformat->name
    );
}
}
4

0 回答 0