当前位置: 首页 > news >正文

FFmpeg For Android入门NDK打印版本号

本文用到的FFmpeg for Android 的开发库,需要先在Ubuntu上完成编译,关于编译的过程参见我的上一篇文章。

Android Studio版本为Android Studio Dolphin | 2021.3.1 Patch 1

1.打开Android Studio,新建工程,选择Native C++

 最小API版本须与FFmpeg库一致

2.在app\src\main目录下创建ffmpeg文件夹,将ffmpeg开发库解压到ffmpeg下

4.在app/build.gradle中添加如下语句

externalNativeBuild {ndk{abiFilters "armeabi-v7a"}}

5.将app\src\main\ffmpeg下的armv7-a文件夹改为armeabi-v7a。这一步很重要,否则后面找不到头文件和库。

 6.编辑app\src\main\cpp\CMakeLists.txt

(1).设置库路径,添加链接库
(2).设置头文件目录
(3).设置具体的链接库文件

# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html# Sets the minimum version of CMake required to build the native library.cmake_minimum_required(VERSION 3.18.1)# Declares and names the project.project("ffmpegandroid2")# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.add_library( # Sets the name of the library.ffmpegandroid2# Sets the library as a shared library.SHARED# Provides a relative path to your source file(s).native-lib.cpp)#1.设置库路径,添加链接库
set(JNI_LIBS_DIR ${CMAKE_SOURCE_DIR}/../ffmpeg)
add_library(avutilSHAREDIMPORTED)
set_target_properties(avutilPROPERTIES IMPORTED_LOCATION${JNI_LIBS_DIR}/${ANDROID_ABI}/lib/libavutil.so )add_library(avresampleSHAREDIMPORTED )set_target_properties(avresamplePROPERTIES IMPORTED_LOCATION${JNI_LIBS_DIR}/${ANDROID_ABI}/lib/libavresample.so )add_library(swresampleSHAREDIMPORTED )set_target_properties(swresamplePROPERTIES IMPORTED_LOCATION${JNI_LIBS_DIR}/${ANDROID_ABI}/lib/libswresample.so )add_library(swscaleSHAREDIMPORTED )set_target_properties(swscalePROPERTIES IMPORTED_LOCATION${JNI_LIBS_DIR}/${ANDROID_ABI}/lib/libswscale.so )add_library(avcodecSHAREDIMPORTED )set_target_properties(avcodecPROPERTIES IMPORTED_LOCATION${JNI_LIBS_DIR}/${ANDROID_ABI}/lib/libavcodec.so )add_library(avformatSHAREDIMPORTED )set_target_properties(avformatPROPERTIES IMPORTED_LOCATION${JNI_LIBS_DIR}/${ANDROID_ABI}/lib/libavformat.so )add_library(avfilterSHAREDIMPORTED )set_target_properties(avfilterPROPERTIES IMPORTED_LOCATION${JNI_LIBS_DIR}/${ANDROID_ABI}/lib/libavfilter.so )add_library(avdeviceSHAREDIMPORTED )set_target_properties(avdevicePROPERTIES IMPORTED_LOCATION${JNI_LIBS_DIR}/${ANDROID_ABI}/lib/libavdevice.so )#2.设置头文件目录
include_directories(${JNI_LIBS_DIR}/${ANDROID_ABI}/include)find_library( # Sets the name of the path variable.log-lib# Specifies the name of the NDK library that# you want CMake to locate.log)# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
#3.设置具体的链接库文件
target_link_libraries( # Specifies the target library.ffmpegandroid2avutilswresampleswscaleavcodecavformatavfilter# Links the target library to the log library# included in the NDK.${log-lib})

7.打开app\src\main\cpp\native-lib.cpp,添加代码

extern "C"{
#include "libavcodec/avcodec.h"
}...
return env->NewStringUTF(av_version_info());

8.点击右上角【同步】(大像)按钮,连接安卓手机点击【运行】按钮开始运行程序

手机上看ffmpeg版本号,说明ffmpeg运行成功。

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • python自动化笔记:os模块和异常处理
  • 什么是设计模式?一文理解,通俗易懂!
  • Nacos原理自问
  • Spring Cloud Gateway实现API访问频率限制
  • uniapp 自定义图片预览组件PicturePreview(Vue3、组合式、ts)
  • 新书速览|Python数据可视化:科技图表绘制(送书)
  • 【机器学习】 Sigmoid函数:机器学习中的关键激活函数
  • jmeter-beanshell学习16-自定义函数
  • 【ML】pre-train model 是什么如何微调它,如何预训练
  • pip笔记
  • POST_CRC
  • ceph分布式存储系统
  • 多头注意力用单元矩阵实现以及原因
  • SO_REUSEADDR 和 SO_REUSEPORT 的区别
  • WEB渗透-未授权访问篇
  • 《Java编程思想》读书笔记-对象导论
  • canvas 高仿 Apple Watch 表盘
  • CSS3 聊天气泡框以及 inherit、currentColor 关键字
  • Elasticsearch 参考指南(升级前重新索引)
  • Git初体验
  • JSDuck 与 AngularJS 融合技巧
  • JS正则表达式精简教程(JavaScript RegExp 对象)
  • macOS 中 shell 创建文件夹及文件并 VS Code 打开
  • Netty 框架总结「ChannelHandler 及 EventLoop」
  • Python爬虫--- 1.3 BS4库的解析器
  • Ruby 2.x 源代码分析:扩展 概述
  • SSH 免密登录
  • 阿里云Kubernetes容器服务上体验Knative
  • 纯 javascript 半自动式下滑一定高度,导航栏固定
  • 关于使用markdown的方法(引自CSDN教程)
  • 警报:线上事故之CountDownLatch的威力
  • 正则学习笔记
  • 从如何停掉 Promise 链说起
  • 关于Android全面屏虚拟导航栏的适配总结
  • ​RecSys 2022 | 面向人岗匹配的双向选择偏好建模
  • #android不同版本废弃api,新api。
  • #图像处理
  • (14)目标检测_SSD训练代码基于pytorch搭建代码
  • (非本人原创)史记·柴静列传(r4笔记第65天)
  • (三)模仿学习-Action数据的模仿
  • (转载)Linux网络编程入门
  • *ST京蓝入股力合节能 着力绿色智慧城市服务
  • .bat批处理(九):替换带有等号=的字符串的子串
  • .mysql secret在哪_MySQL如何使用索引
  • .Net 4.0并行库实用性演练
  • .net 开发怎么实现前后端分离_前后端分离:分离式开发和一体式发布
  • .NET大文件上传知识整理
  • .NET开发不可不知、不可不用的辅助类(三)(报表导出---终结版)
  • .net中生成excel后调整宽度
  • /etc/shadow字段详解
  • @拔赤:Web前端开发十日谈
  • [ Linux Audio 篇 ] 音频开发入门基础知识
  • [ 物联网 ]拟合模型解决传感器数据获取中数据与实际值的误差的补偿方法
  • [AHK] WinHttpRequest.5.1报错 0x80092004 找不到对象或属性
  • [Android]Android开发入门之HelloWorld