Skip to content

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

Closed

Description

@abdullah213141

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?

Activity

  1. T-Dynamos commented on Mar 29, 2025

    @T-Dynamos
    Member

    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.

  2. github-actions commented on Mar 29, 2025

    @github-actions

    👋 @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.

  3. abdullah213141 commented on Mar 29, 2025

    @abdullah213141
    Author

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

  4. T-Dynamos commented on Mar 29, 2025

    @T-Dynamos
    Member

    @ElliotGarbus I think this was not a support request?

    It was a feature request: "Expose ffmpeg binary"

  5. ElliotGarbus commented on Mar 29, 2025

    @ElliotGarbus
    Contributor

    @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?

  6. PitRc47 commented on Mar 30, 2025

    @PitRc47

    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?

  7. AndreMiras commented on Mar 30, 2025

    @AndreMiras
    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

  8. added
    need-discussionThe issue or pull request needs a discussion to take a team decission
    and removed on Mar 30, 2025
  9. abdullah213141 commented on Mar 30, 2025

    @abdullah213141
    Author

    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?

  10. T-Dynamos commented on Mar 30, 2025

    @T-Dynamos
    Member

    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):

    ##################
    from android import mActivity
    from jnius import autoclass
    from os.path import join
    from os import environ
    
    app_info = mActivity.getApplicationInfo()
    native_lib_dir = app_info.nativeLibraryDir
    ffmpeg_bin = join(native_lib_dir, "libffmpegbin.so")
    environ["LD_LIBRARY_PATH"] = native_lib_dir 
    ###################
    
    import subprocess
    
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions