Connect with us

Java/Android Programming

How to Compile Latest ffmpeg for Android and Use it in Android Studio 2023

Published

on

Share this Article

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.

So i show you How you Can Use ffmpeg in your Android Studio project.

How to use ffmpeg in Android studio Projects.

Follow this Steps :

  • Now Create jniLibs folder inside your projects /main folder.
Example \<Your Project Directory>\<Your Project>\src\main\jniLibs
  • Copy and paste these ffmpegAndroid files inside jniLibs folder.
  • And after that add following code in Your cmakeList.txt file.

set(IMPORT_DIR ${CMAKE_SOURCE_DIR}/../jniLibs)

# FFmpeg include file
include_directories(${IMPORT_DIR}/${ANDROID_ABI}/include)
# Codec library
add_library(
        avcodec
        SHARED
        IMPORTED
)
set_target_properties(
        avcodec
        PROPERTIES IMPORTED_LOCATION
        ${IMPORT_DIR}/${ANDROID_ABI}/libavcodec.so
)
# The filter library is temporarily out of use
add_library(
        avfilter
        SHARED
        IMPORTED
)
set_target_properties(
        avfilter
        PROPERTIES IMPORTED_LOCATION
        ${IMPORT_DIR}/${ANDROID_ABI}/libavfilter.so
)

# File format libraries are required for most operations
add_library(
        avformat
        SHARED
        IMPORTED
)

set_target_properties(
        avformat
        PROPERTIES IMPORTED_LOCATION
        ${IMPORT_DIR}/${ANDROID_ABI}/libavformat.so
)

# Tool library
add_library(
        avutil
        SHARED
        IMPORTED
)
set_target_properties(
        avutil
        PROPERTIES IMPORTED_LOCATION
        ${IMPORT_DIR}/${ANDROID_ABI}/libavutil.so
)

# The resampling library is mainly used for audio conversion.
add_library(
        swresample
        SHARED
        IMPORTED
)
set_target_properties(
        swresample
        PROPERTIES IMPORTED_LOCATION
        ${IMPORT_DIR}/${ANDROID_ABI}/libswresample.so
)

# Video format conversion library is mainly used for video conversion.
add_library(
        swscale
        SHARED
        IMPORTED
)
set_target_properties(
        swscale
        PROPERTIES IMPORTED_LOCATION
        ${IMPORT_DIR}/${ANDROID_ABI}/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
)
  • 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++14 -fexceptions -frtti"
                arguments "-DANDROID_STL=c++_shared"
            }
        }

    }

And now just rebuild your project and start using ffmpeg c++ libraries in your Android Studio Project.


Share this Article

Video Games Lover By Passion. Programmer by skills and part time Blogger by Hobby. And Owner of UMIRGAMING.COM and UMIRTECH.COM

Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.