Android Studio2.2.3 通過JNI引用ffmpeg庫小結

來源:互聯網
上載者:User

標籤:android studio;ffmpeg;ndk;jni

修改步驟:

  1. 首先通過NDK14編譯出libffmpeg.so ,將include目錄取出

  2. 通過AS建立基於jni的工程項目,將include目錄放到cpp下;建立jniLibs/armeabi目錄,將libffmpeg.so放到裡邊

    650) this.width=650;" src="https://s1.51cto.com/wyfs02/M00/9B/C7/wKiom1lnD5Sh5vzsAABjn9nLj1w935.jpg-wh_500x0-wm_3-wmp_4-s_4100660184.jpg" title="36020170713141223334.jpg" alt="wKiom1lnD5Sh5vzsAABjn9nLj1w935.jpg-wh_50" />

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 <jni.h>
#include <string>
#include <android/log.h>

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://zyg0227.blog.51cto.com/1043164/1947097

Android Studio2.2.3 通過JNI引用ffmpeg庫小結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.