VIDEO TUTORIAL - https://youtu.be/F8yJwRof948
FFmpegKit
is a collection of tools to use FFmpeg
in Android
applications.
It includes scripts to build FFmpeg
native libraries, a wrapper library to run FFmpeg
/FFprobe
commands in
applications.
- Scripts to build FFmpeg native libraries
FFmpegKit
wrapper library to runFFmpeg
/FFprobe
commands in applications- Supports native platforms: Android
- Based on FFmpeg
v4.5-dev
or later with optional system and external libraries
- Supports
API Level 25+
on Main releases. - Includes
arm-v7a
,arm-v7a-neon
,arm64-v8a
,x86
andx86_64
architectures - Can handle Storage Access Framework (SAF) Uris
- Camera access on supported devices
- Builds shared native libraries (.so)
- Creates Android archive with .aar extension
NOTE: If you are having lower quality exports, add "-q:v 1 -q:a 1" before your output file/path. 1 for highest.
0) Add SmartExpetion Common and SmartExeption java from (https://github.com/tanersener/smart-exception/releases/tag/v0.2.1)
1) and the FFMPEG aar(https://github.com/Blackysh/ffmpeg-kit-python/releases/tag/tag) tab or the one generated by you to your projects folder.
2) In Buildozer spec file add jnius to requirements and the aar file. (Alongside what you already have)
requirements = pyjnius
android.add_aars = ffmpeg-kit-release.aar
android.add_jars = smart-exception-common-0.2.1.jar, smart-exception-java-0.2.1.jar
android.minapi = 25
The minimum api number can be anything above 25.
3) Using Pyjnius, declare the variables in Python (https://pyjnius.readthedocs.io/en/stable/)
#IMPORTING jnius
from jnius import autoclass
from jnius import *
#Declaring Variable so it can be used
FFMPEG = autoclass('com.sahib.pyff.ffpy')
BOTH (FFMPEG and FFPROBE) RETURN OUTPUT OF THE COMMAND
#EXECUTED FFMPEG COMMAND, COMMAND IS STRING
ffmpegCommand = FFMPEG.Run("COMMAND")
#PRINTS RETURN (OUTPUT OF THE COMMAND)
print(ffmpegCommand)
#EXECUTED FFProbe COMMAND, COMMAND IS STRING
probeCommand = FFMPEG.RunProbe("Command")
#PRINTS RETURN (OUTPUT OF THE COMMAND)
print(probeCommand)
NOTE - FILTER_COMPLEX can not be used. (IDK why, if you have solution tell me please)
Deployment fail, send it's adb debugging logs. also it is working for me, i have used it in a private application, i used alot more than htis tutorial or the docs show, i may have missed something that it needs since i relied on my memory while writing the tutorial instead of accually recreating the steps i had used to use it in my own application. I am sorry for inconvenience.
But i do recommend some things which may or may not have caused it to work/fail -
Manage storage permission (all storage instead of media)
Try testing the application on a device with developer mode enabled, it may be the cause.
I don't remember anything else that i did differently in my own application from the tutorial.
Sorry for inconvenience and IF these don't work i will try recreating a small application using this without bloat for documentation purposes
-Me, unwilling to recreate unless something really fails...
from jnius import autoclass
from jnius import *
#Declaring Variable so it can be used
FFMPEG = autoclass('com.sahib.pyff.ffpy')
#THIS COVERTS VIDEO INTO an audio file (MP4 TO WAV)
d = FFMPEG.Run(str("-i video.mp4 -ab 160k -ac 2 -ar 44100 -vn TEMP/audio.wav"))
#THIS PRINTS THE OUTPUT (I don't think you even need output in ffmpeg unless for trouble shooting)
print(d)
from jnius import autoclass
from jnius import *
#Declaring Variable so it can be used
FFMPEG = autoclass('com.sahib.pyff.ffpy')
#Gets Framerate of video
frameRate = FFMPEG.RunProbe("-v error -select_streams v -of default=noprint_wrappers=1:nokey=1 -show_entries stream=r_frame_rate video.mp4")
#This command outputs 30/1 at 30 frames
frameRate = frameRate.split("/")[0]
#this makes it 30 instead of 30/1
frameRate = int(frameRate)
print(frameRate)
#Converts framerate to integer and prints it
Run android.sh
at project root directory to build ffmpeg-kit
and ffmpeg
shared libraries.
Please note that FFmpegKit
project repository includes the source code of FFmpegKit
only. android.sh
needs
network connectivity and internet access to github.com
in order to download the source code of FFmpeg
and
external libraries enabled.
android.sh
requires the following tools and packages.
- Android SDK Build Tools
- Android NDK r22b or later with LLDB and CMake (See #292 if you want to use NDK r23b)
- Java (openjdk)
Use your package manager (apt, yum, dnf, brew, etc.) to install the following packages.
sdkmanager autoconf automake libtool pkg-config curl cmake gcc gperf texinfo yasm nasm bison autogen git wget autopoint meson ninja
Set ANDROID_SDK_ROOT
and ANDROID_NDK_ROOT
environment variables before running android.sh
. (not NDK-bundle, Preferably install using sdkmanager)
sdkmanager command:
sdkmanager --install "build-tools;24.0.3" "tools;24.4.1" "platform-tools;24.0.0" "ndk;r22b" "cmake;3.22.1" "ndk-bundle;r22b"
export ANDROID_SDK_ROOT=<Android SDK Path>
export ANDROID_NDK_ROOT=<Android NDK Path>
Use --enable-<library name>
flag to support additional external or system libraries and
--disable-<architecture name>
to disable architectures you don't want to build.
./android.sh --enable-fontconfig --disable-arm-v7a-neon
Run --help
to see all available build options.