修改步骤:
3. 配置 CMakeLists.txt
添加如下:
- #add the ffmpeg lib include_directories($ {
- CMAKE_CURRENT_SOURCE_DIR
- }
- /src/main / cpp / include) add_library(ffmpeg - lib SHARED IMPORTED ) set_target_properties(ffmpeg - lib PROPERTIES IMPORTED_LOCATION $ {
- CMAKE_CURRENT_SOURCE_DIR
- }
- /src/main / jniLibs / armeabi / libffmpeg.so)
- target_link_libraries( native - lib ffmpeg - lib #ffmpeg lib android #use the android log lib $ {
- log - lib
- } )
4. 配置 build.gradle
主要添加 arguments 和 ndk 的配置
- externalNativeBuild { cmake { cppFlags " " arguments ' - DANDROID_TOOLCHAIN = clang',
- ' - DANDROID_STL = gnustl_static'
- }
- ndk { abiFilters 'armeabi'
- }
- }
5.native_lib.cpp
#include
#include
#include
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#include "libavutil/imgutils.h"
#include "libavutil/avutil.h"
}
#define LOG_TAG "MyTagFFmpeg"
#define ALOGE(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
extern "C"
jstring
Java_letv_com_myffmpeg_MainActivityFFmpeg_stringFromJNI(
JNIEnv *env,
jobject /* this */) {
std::string hello = "Hello ,this is the first ffmpeg test !";
ALOGE("%s",hello.c_str());
char info[10000] = {0};
sprintf(info,"%s\n", avcodec_configuration());
hello += info;
return env->NewStringUTF(hello.c_str());
}
That's all.
来源: http://www.bubuko.com/infodetail-2167927.html