Android NDK Guide
Integrating FFmpeg 7+ with Kotlin via JNI
A complete, step-by-step visual guide to integrating pre-compiled FFmpeg 7 dynamic libraries (.so) into a modern Android project using CMake, JNI, and Jetpack Compose.
Step 1: Project Structure
Organize C/C++ headers and dynamic libraries
First, you need pre-compiled FFmpeg 7.x libraries for Android. Place the include folder (headers) and libs folder (.so files for arm64-v8a, etc.) into your app's app/src/main/cpp/ffmpeg directory.
Ensure your package name context matches your app setup. For this guide, we assume the app is com.papa.ffmpeg.
Directory Tree
- app/src/main/
- cpp/
- ffmpeg/
- include/ /* headers */
- libs/
- arm64-v8a/
- libavcodec.so
- libavutil.so
- CMakeLists.txt
- native-lib.cpp
- java/com/papa/ffmpeg/
- FFmpegHelper.kt
- MainActivity.kt
Step 2: Build Configuration
Link the shared libraries in build scripts
1. app/build.gradle.kts
2. app/src/main/cpp/CMakeLists.txt
Step 3: C++ JNI Implementation
Bridge Kotlin with FFmpeg C API
native-lib.cpp
Step 4: Kotlin & Jetpack Compose UI
Load the library and render the result on screen
FFmpegHelper.kt
MainActivity.kt
12:00
Papa FFmpeg Integration
Core Version:
7.0.1
JNI Call Successfully Executed
Simulated Render of Compose UI
