Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to include ffmpeg in an Android app? #3137

Open
Rotgal opened this issue Mar 29, 2025 · 9 comments
Open

Is there a way to include ffmpeg in an Android app? #3137

Rotgal opened this issue Mar 29, 2025 · 9 comments
Labels
feature-request need-discussion The issue or pull request needs a discussion to take a team decission recipe

Comments

@Rotgal
Copy link

Rotgal commented Mar 29, 2025

Hi, I'm working on an Android app using kivy and buildozer. The app focuses on video and audio editing, similar to CapCut and relies on FFmpeg as its backbone for processing. On Windows, I use a system-installed FFmpeg (the one you download and add to the system PATH) and call it using subprocess commands. This setup works perfectly.

However, since the FFmpeg package you install with pip on Windows doesn't meet my app needs, I'm assuming adding FFmpeg to the requirements in the buildozer.spec file wouldn't work.

Is there a way to include the full build FFmpeg in my Android app?
Are there alternative ways to integrate FFmpeg with Kivy/Buildozer that work well on Android?

@T-Dynamos
Copy link
Contributor

Yes you can get ffmpeg binary in android, you need to modify its recipe to include binary as .so file in android lib dir then load that .so as bin file.

Copy link

👋 @Rotgal,
Sorry to hear you are having difficulties with Kivy's python-for-android; Kivy unites a number of different technologies, so building apps can be temperamental.
We try to use GitHub issues only to track work for developers to do to fix bugs and add new features to python-for-android.
However, this issue appears to be a support request. Please use our support channels to get help with the project.
If you're having trouble installing python-for-android, please see our quickstart guide.
If you're having trouble using python-for-android, please see our troubleshooting guide and FAQ.
Let us know if this comment was made in error, and we'll be happy to reopen the issue.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 29, 2025
@Rotgal
Copy link
Author

Rotgal commented Mar 29, 2025

Can you elaborate a bit? Am I supposed to use this recipe or use something like ffmpeg-kit? Any documentations/tutorials would be appreciated

@T-Dynamos
Copy link
Contributor

@ElliotGarbus I think this was not a support request?

It was a feature request: "Expose ffmpeg binary"

@ElliotGarbus
Copy link

@T-Dynamos
I don't understand. There is already a recipe for ffmpeg. This seems like a rather straight forward support request. What an I missing?

@PitRc47
Copy link

PitRc47 commented Mar 30, 2025

This question troubles me as well.
I was able to compile ffmpeg as an .so library, but I don't seem to have a way to execute it.

Is my knowledge lacking somewhere?

@AndreMiras
Copy link
Member

This is what @T-Dynamos said basically:

Yes you can get ffmpeg binary in android, you need to modify its recipe to include binary as .so file in android lib dir then load that .so as bin file.

It could also be updating some configure/build flags so that the binary is built.
For instance in the recipe there's:

            # disable binaries / doc
            flags += [
                '--disable-programs',
                '--disable-doc',
            ]

Go play with this a bit.
However we probably don't want to ship if for everyone as it would increase build size, so maybe with a custom recipe or something

@kuzeyron kuzeyron added recipe need-discussion The issue or pull request needs a discussion to take a team decission feature-request and removed support labels Mar 30, 2025
@kuzeyron kuzeyron reopened this Mar 30, 2025
@Rotgal
Copy link
Author

Rotgal commented Mar 30, 2025

Am I supposed to modify the recipe here /.buildozer/android/platform/python-for-android/pythonforandroid/recipes/ffmpeg? And should I run buildozer android clean afterwards?

@T-Dynamos
Copy link
Contributor

Here is my hacky tmp fix: https://github.com/T-Dynamos/python-for-android/tree/ffmpeg_bin

To use it:
in buildozer.spec:

p4a.fork = T-Dynamos
p4a.branch = ffmpeg_bin

To run ffmpeg bin in android:
(test code):

import subprocess
from android import mActivity
from jnius import autoclass
from os.path import join

app_info = mActivity.getApplicationInfo()
native_lib_dir = app_info.nativeLibraryDir

ffmpeg_bin = join(native_lib_dir, "libffmpegbin.so")

print(
    subprocess.run(
        [ffmpeg_bin, "-version"], capture_output=True, text=True, check=True
    ).stdout
)

It works by copying ffmpeg executable file to libffmpegbin.so so it get's automatically copied to android lib dir and from there we can execute it. We cannot execute it in any another path or with any other name due to android restrictions.

So it kinda impersonates executable file as library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request need-discussion The issue or pull request needs a discussion to take a team decission recipe
Projects
None yet
Development

No branches or pull requests

6 participants