FFMPEG is one of the most popular or powerful media processing library with multiple platform support and it is capable of doing Most of Media processing task.
How to Compile Latest FFMPEG for Android with Latest Android NDK.
Follow These Steps
- First create a Github account or if you already have than login.
- Now fork this Repository https://github.com/umirtech/ffmpegAndroid.
- And after that open android.sh file in write mode.
- And Make Changes as per your Requirement
like you can set Architectures versions you want to compile ffmpeg from these Supported Architectures “armv8a” “armv7a” “x86” “x86-64”
And You can also Select android Api level by describing in this field ANDROID_API_LEVEL=”25″
After that you can make ffmpeg configuration changes in the following fields
### Enable FFMPEG BUILD MODULES ###
ENABLED_CONFIG=”\
–enable-small \
–enable-avcodec \
–enable-avformat \
–enable-avutil \
–enable-jni \
–enable-mediacodec \
–enable-demuxer=mov \
–enable-demuxer=matroska \
–enable-parser=h264 \
–enable-parser=aac \
–enable-parser=hevc \
–enable-decoder=h264 \
–enable-decoder=aac \
–enable-decoder=hevc \
–enable-decoder=opus \
–enable-shared “
### Disable FFMPEG BUILD MODULES ###
DISABLED_CONFIG=”\
–disable-zlib \
–disable-swscale \
–disable-swresample \
–disable-avfilter \
–disable-v4l2-m2m \
–disable-cuda-llvm \
–disable-indevs \
–disable-libxml2 \
–disable-avdevice \
–disable-network \
–disable-static \
–disable-debug \
–disable-ffplay \
–disable-ffprobe \
–disable-doc \
–disable-symver \
–disable-gpl “ - After Configuring android.sh as per your requirement save and commit the file
- And now goto Actions Tab and if you see a massage just click on enable workflows
- And now can see a workflow named Build “FFmpeg for Android” just click on it
- After opening the workflow click on Run Workflow and wait Until the Process completes
- And After the Build process completed you can see an artifact file download it and integrate inside your android studio project with Cmakelist.txt or Android.mk
Also Watch this Video Tutorial:
How to Integrate ffmpeg library into Android studio project?
1. First Compile ffmpeg binaries If you have not already compiled ffmpeg binaries as per above tutorial.
2. Now Create jniLibs folder inside your projects /main folder.
Example \<Your Project Directory>\<Your Project>\src\main\jniLibs
3. Copy and paste your compiled ffmpegAndroid files inside jniLibs folder.
4. And after that add following code in Your cmakeList.txt file.
set(IMPORT_DIR ${CMAKE_SOURCE_DIR}/../jniLibs)
# FFmpeg include file
set(FFMPEG_INCLUDE_DIR ${IMPORT_DIR}/${ANDROID_ABI}/include)
set(FFMPEG_LIB_DIR ${IMPORT_DIR}/${ANDROID_ABI}/lib)
include_directories(${FFMPEG_INCLUDE_DIR})
# Codec library
add_library(
avcodec
SHARED
IMPORTED
)
set_target_properties(
avcodec
PROPERTIES IMPORTED_LOCATION
${FFMPEG_LIB_DIR}/libavcodec.so
)
# The filter library is temporarily out of use
add_library(
avfilter
SHARED
IMPORTED
)
set_target_properties(
avfilter
PROPERTIES IMPORTED_LOCATION
${FFMPEG_LIB_DIR}/libavfilter.so
)
# File format libraries are required for most operations
add_library(
avformat
SHARED
IMPORTED
)
set_target_properties(
avformat
PROPERTIES IMPORTED_LOCATION
${FFMPEG_LIB_DIR}/libavformat.so
)
# Tool library
add_library(
avutil
SHARED
IMPORTED
)
set_target_properties(
avutil
PROPERTIES IMPORTED_LOCATION
${FFMPEG_LIB_DIR}/libavutil.so
)
# The resampling library is mainly used for audio conversion.
add_library(
swresample
SHARED
IMPORTED
)
set_target_properties(
swresample
PROPERTIES IMPORTED_LOCATION
${FFMPEG_LIB_DIR}/libswresample.so
)
# Video format conversion library is mainly used for video conversion.
add_library(
swscale
SHARED
IMPORTED
)
set_target_properties(
swscale
PROPERTIES IMPORTED_LOCATION
${FFMPEG_LIB_DIR}/libswscale.so
)
# The main android library, native window, requires this library
target_link_libraries(
<Your-Native-Library>
${log-lib}
android
avcodec
avfilter
avformat
avutil
swresample
swscale
)
5. Also Add following code in your Module build.gradle file.
defaultConfig {
//............//
ndk.abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
externalNativeBuild {
cmake {
cppFlags "-std=c++17 -fexceptions -frtti"
arguments "-DANDROID_STL=c++_shared"
}
}
}
6. And now just rebuild your project and start using ffmpeg c++ libraries in your Android Studio Project.
Great
Hi , Thank you for code and article, followed your steps but
stddef.h
stdint.h
and many other files not found