Repository navigation
recipes: new mpv recipe #3420
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
Merged
Merged
recipes: new mpv recipe #3420
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b2ccaa5
recipes: add mpv, libplacebo, libass, and fribidi
T-Dynamos abb8c17
recipes: split libmpv native recipe and python-mpv mpv recipe
T-Dynamos 943b53a
recipes(mpv): auto-configure Android JavaVM and SDL GL proc address
T-Dynamos b416748
recipes(mpv,libplacebo,libmpv): address PR review comments and enable…
T-Dynamos 95509df
recipes(libplacebo,libmpv): disable Vulkan and drop vulkan.pc
T-Dynamos d43b4cd
recipes: rename fribidi to libfribidi
T-Dynamos 8259147
recipes(mpv): detect Kivy SDL2/SDL3 order and search Kivy.libs first
T-Dynamos fdb345b
recipes(mpv): use O(1) window_sdl check in _sdl_search_order
T-Dynamos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| from multiprocessing import cpu_count | ||
| from os.path import join | ||
|
|
||
| import sh | ||
| from pythonforandroid.logger import info, shprint | ||
| from pythonforandroid.recipe import Recipe | ||
| from pythonforandroid.util import current_directory | ||
|
|
||
|
|
||
| class LibassRecipe(Recipe): | ||
| version = "0.17.5" | ||
| url = "https://github.com/libass/libass/releases/download/{version}/libass-{version}.tar.xz" | ||
| depends = ["libfribidi", "freetype", "harfbuzz"] | ||
| built_libraries = {"libass.so": "installation/lib"} | ||
|
|
||
| def get_recipe_env(self, arch=None): | ||
| env = super().get_recipe_env(arch) | ||
|
|
||
| fribidi_install = join( | ||
| self.get_recipe("libfribidi", self.ctx).get_build_dir(arch.arch), | ||
| "installation", | ||
| ) | ||
| freetype_install = join( | ||
| self.get_recipe("freetype", self.ctx).get_build_dir(arch.arch), | ||
| "install", | ||
| ) | ||
| harfbuzz_dir = self.get_recipe("harfbuzz", self.ctx).get_build_dir(arch.arch) | ||
|
|
||
| env["FRIBIDI_CFLAGS"] = f"-I{join(fribidi_install, 'include', 'fribidi')}" | ||
| env["FRIBIDI_LIBS"] = f"-L{join(fribidi_install, 'lib')} -lfribidi" | ||
| env["FREETYPE_CFLAGS"] = f"-I{join(freetype_install, 'include', 'freetype2')}" | ||
| env["FREETYPE_LIBS"] = f"-L{join(freetype_install, 'lib')} -lfreetype" | ||
| env["HARFBUZZ_CFLAGS"] = f"-I{join(harfbuzz_dir, 'src')}" | ||
| env["HARFBUZZ_LIBS"] = f"-L{join(harfbuzz_dir, 'src', '.libs')} -lharfbuzz" | ||
| env["PKG_CONFIG_LIBDIR"] = "" | ||
| env["PKG_CONFIG_PATH"] = "" | ||
| return env | ||
|
|
||
| def build_arch(self, arch): | ||
| source_dir = self.get_build_dir(arch.arch) | ||
| install_dir = join(source_dir, "installation") | ||
| env = self.get_recipe_env(arch) | ||
|
|
||
| with current_directory(source_dir): | ||
| info(f"Configuring libass {self.version} for {arch.arch}") | ||
| shprint( | ||
| sh.Command("./configure"), | ||
| f"--host={arch.command_prefix}", | ||
| f"--prefix={install_dir}", | ||
| "--enable-shared", | ||
| "--disable-static", | ||
| "--disable-fontconfig", | ||
| "--disable-require-system-font-provider", | ||
| "--disable-libunibreak", | ||
| "--disable-asm", | ||
| _env=env, | ||
| ) | ||
| shprint(sh.make, "-j", str(cpu_count()), _env=env) | ||
| shprint(sh.make, "install", _env=env) | ||
|
|
||
|
|
||
| recipe = LibassRecipe() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| from os.path import join | ||
|
|
||
| from pythonforandroid.logger import info, shprint | ||
| from pythonforandroid.recipe import MesonRecipe | ||
| from pythonforandroid.util import ensure_dir | ||
|
|
||
|
|
||
| class LibfribidiRecipe(MesonRecipe): | ||
| version = "1.0.18" | ||
| url = "https://github.com/fribidi/fribidi/releases/download/v{version}/fribidi-{version}.tar.xz" | ||
| depends = [] | ||
| skip_python = True | ||
| built_libraries = {"libfribidi.so": "installation/lib"} | ||
|
|
||
| def get_recipe_meson_options(self, arch): | ||
| options = super().get_recipe_meson_options(arch) | ||
| options["binaries"]["pkgconfig"] = "pkg-config" | ||
| return options | ||
|
|
||
| def build_arch(self, arch): | ||
| super().build_arch(arch) | ||
| source_dir = self.get_build_dir(arch.arch) | ||
| build_dir = join(source_dir, "p4a_meson_build") | ||
| install_dir = join(source_dir, "installation") | ||
| ensure_dir(build_dir) | ||
| env = self.get_recipe_env(arch, with_flags_in_cc=True) | ||
| meson = self.get_meson_command(env) | ||
|
|
||
| info(f"Configuring fribidi {self.version} for {arch.arch}") | ||
| shprint( | ||
| meson, | ||
| "setup", | ||
| build_dir, | ||
| source_dir, | ||
| "--cross-file", | ||
| "/tmp/android.meson.cross", | ||
| f"--prefix={install_dir}", | ||
| "--libdir=lib", | ||
| "--buildtype=release", | ||
| "-Ddefault_library=shared", | ||
| "-Ddocs=false", | ||
| "-Dtests=false", | ||
| "-Dbin=false", | ||
| _env=env, | ||
| ) | ||
| shprint(meson, "compile", "-C", build_dir, _env=env) | ||
| shprint(meson, "install", "-C", build_dir, _env=env) | ||
|
|
||
|
|
||
| recipe = LibfribidiRecipe() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| import shutil | ||
| from os.path import join | ||
|
|
||
| from pythonforandroid.logger import info, shprint | ||
| from pythonforandroid.recipe import MesonRecipe | ||
| from pythonforandroid.util import ensure_dir | ||
|
|
||
|
|
||
| class LibmpvRecipe(MesonRecipe): | ||
| version = "0.42.0" | ||
| url = "https://github.com/mpv-player/mpv/archive/refs/tags/v{version}.tar.gz" | ||
| depends = ["ffmpeg", "libass", "libplacebo"] | ||
| skip_python = True | ||
| built_libraries = {"libmpv.so": "installation/lib"} | ||
|
|
||
| def get_recipe_meson_options(self, arch): | ||
| options = super().get_recipe_meson_options(arch) | ||
| options["binaries"]["pkgconfig"] = "pkg-config" | ||
| options["properties"].pop("sys_root", None) | ||
| return options | ||
|
|
||
| def get_recipe_env(self, arch, with_flags_in_cc=True): | ||
| env = super().get_recipe_env(arch, with_flags_in_cc=with_flags_in_cc) | ||
| ffmpeg_dir = self.get_recipe("ffmpeg", self.ctx).get_build_dir(arch.arch) | ||
| libass_install = join( | ||
| self.get_recipe("libass", self.ctx).get_build_dir(arch.arch), | ||
| "installation", | ||
| ) | ||
| libplacebo_install = join( | ||
| self.get_recipe("libplacebo", self.ctx).get_build_dir(arch.arch), | ||
| "installation", | ||
| ) | ||
| fribidi_install = join( | ||
| self.get_recipe("libfribidi", self.ctx).get_build_dir(arch.arch), | ||
| "installation", | ||
| ) | ||
| freetype_install = join( | ||
| self.get_recipe("freetype", self.ctx).get_build_dir(arch.arch), | ||
| "install", | ||
| ) | ||
| harfbuzz_dir = self.get_recipe("harfbuzz", self.ctx).get_build_dir(arch.arch) | ||
|
|
||
| pkg_paths = [ | ||
| join(ffmpeg_dir, "lib", "pkgconfig"), | ||
| join(libass_install, "lib", "pkgconfig"), | ||
| join(libplacebo_install, "lib", "pkgconfig"), | ||
| join(fribidi_install, "lib", "pkgconfig"), | ||
| join(freetype_install, "lib", "pkgconfig"), | ||
| join(harfbuzz_dir, "src"), | ||
| ] | ||
| existing = env.get("PKG_CONFIG_PATH", "") | ||
| env["PKG_CONFIG_PATH"] = ":".join(pkg_paths + ([existing] if existing else [])) | ||
| env["PKG_CONFIG_LIBDIR"] = env["PKG_CONFIG_PATH"] | ||
| return env | ||
|
|
||
| def build_arch(self, arch): | ||
| super().build_arch(arch) | ||
| source_dir = self.get_build_dir(arch.arch) | ||
| build_dir = join(source_dir, "p4a_meson_build") | ||
| install_dir = join(source_dir, "installation") | ||
| shutil.rmtree(build_dir, ignore_errors=True) | ||
| ensure_dir(build_dir) | ||
| env = self.get_recipe_env(arch, with_flags_in_cc=True) | ||
| meson = self.get_meson_command(env) | ||
|
|
||
| info(f"Configuring mpv {self.version} for {arch.arch}") | ||
| shprint( | ||
| meson, | ||
| "setup", | ||
| build_dir, | ||
| source_dir, | ||
| "--cross-file", | ||
| "/tmp/android.meson.cross", | ||
| f"--prefix={install_dir}", | ||
| "--libdir=lib", | ||
| "--buildtype=release", | ||
| "-Dlibmpv=true", | ||
| "-Dcplayer=false", | ||
| "-Dgl=enabled", | ||
| "-Degl=disabled", | ||
| "-Degl-android=enabled", | ||
| "-Dandroid-media-ndk=enabled", | ||
| "-Dopensles=enabled", | ||
| "-Daaudio=disabled", | ||
| "-Dlua=disabled", | ||
| "-Ddvdnav=disabled", | ||
| "-Dlcms2=disabled", | ||
| "-Dlibbluray=disabled", | ||
| "-Dvapoursynth=disabled", | ||
| "-Dzimg=disabled", | ||
| "-Ddrm=disabled", | ||
| "-Dgbm=disabled", | ||
| "-Djpeg=disabled", | ||
| "-Dvdpau=disabled", | ||
| "-Dvaapi=disabled", | ||
| "-Dvulkan=disabled", | ||
| "-Dwayland=disabled", | ||
| "-Dx11=disabled", | ||
| "-Dx11-clipboard=disabled", | ||
| "-Dxv=disabled", | ||
| "-Dtests=false", | ||
| _env=env, | ||
| ) | ||
| shprint(meson, "compile", "-C", build_dir, _env=env) | ||
| shprint(meson, "install", "-C", build_dir, _env=env) | ||
|
|
||
|
|
||
| recipe = LibmpvRecipe() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import shutil | ||
| from os.path import join | ||
|
|
||
| from pythonforandroid.logger import info, shprint | ||
| from pythonforandroid.recipe import MesonRecipe | ||
| from pythonforandroid.util import ensure_dir | ||
|
|
||
|
|
||
| class LibplaceboRecipe(MesonRecipe): | ||
| version = "v7.387.0" | ||
| url = "git+https://code.videolan.org/videolan/libplacebo.git" | ||
| depends = [] | ||
| skip_python = True | ||
| hostpython_prerequisites = ["jinja2>=3.1,<4", "glad2>=2.0,<3"] | ||
| built_libraries = {"libplacebo.so": "installation/lib"} | ||
|
|
||
| def get_recipe_meson_options(self, arch): | ||
| options = super().get_recipe_meson_options(arch) | ||
| options["binaries"]["pkgconfig"] = "pkg-config" | ||
| return options | ||
|
|
||
| def build_arch(self, arch): | ||
| super().build_arch(arch) | ||
| source_dir = self.get_build_dir(arch.arch) | ||
| build_dir = join(source_dir, "p4a_meson_build") | ||
| install_dir = join(source_dir, "installation") | ||
| shutil.rmtree(build_dir, ignore_errors=True) | ||
| ensure_dir(build_dir) | ||
| env = self.get_recipe_env(arch, with_flags_in_cc=True) | ||
| meson = self.get_meson_command(env) | ||
|
|
||
| info(f"Configuring libplacebo {self.version} for {arch.arch}") | ||
| shprint( | ||
| meson, | ||
| "setup", | ||
| build_dir, | ||
| source_dir, | ||
| "--cross-file", | ||
| "/tmp/android.meson.cross", | ||
| f"--prefix={install_dir}", | ||
| "--libdir=lib", | ||
| "--buildtype=release", | ||
| "-Ddefault_library=shared", | ||
| "-Dopengl=enabled", | ||
| "-Dvulkan=disabled", | ||
| "-Dvk-proc-addr=disabled", | ||
| "-Dglslang=disabled", | ||
| "-Dshaderc=disabled", | ||
| "-Dlcms=disabled", | ||
| "-Dlibdovi=disabled", | ||
| "-Dd3d11=disabled", | ||
| "-Dtests=false", | ||
| "-Ddemos=false", | ||
| "-Dxxhash=disabled", | ||
| "-Dunwind=disabled", | ||
| _env=env, | ||
| ) | ||
| shprint(meson, "compile", "-C", build_dir, _env=env) | ||
| shprint(meson, "install", "-C", build_dir, _env=env) | ||
|
|
||
|
|
||
| recipe = LibplaceboRecipe() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import shutil | ||
| from os.path import join | ||
|
|
||
| from pythonforandroid.recipe import PyProjectRecipe | ||
|
|
||
|
|
||
| class MpvRecipe(PyProjectRecipe): | ||
| name = "mpv" | ||
| version = "1.0.8" | ||
| url = "https://pypi.io/packages/source/p/python-mpv/python_mpv-{version}.tar.gz" | ||
| depends = ["python3", "libmpv"] | ||
| patches = ["android.patch"] | ||
|
|
||
| def prebuild_arch(self, arch): | ||
| super().prebuild_arch(arch) | ||
| shutil.copyfile( | ||
| join(self.get_recipe_dir(), "mpv_android.py"), | ||
| join(self.get_build_dir(arch.arch), "mpv_android.py"), | ||
| ) | ||
|
|
||
|
|
||
| recipe = MpvRecipe() |
|
T-Dynamos marked this conversation as resolved.
Resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| --- a/pyproject.toml | ||
| +++ b/pyproject.toml | ||
| @@ -3,7 +3,7 @@ | ||
| build-backend = "setuptools.build_meta" | ||
|
|
||
| [tool.setuptools] | ||
| -py-modules = ['mpv'] | ||
| +py-modules = ['mpv', 'mpv_android'] | ||
|
|
||
| [project] | ||
| name = "python-mpv" | ||
| --- a/mpv.py | ||
| +++ b/mpv.py | ||
| @@ -68,9 +68,13 @@ | ||
| locale.setlocale(locale.LC_NUMERIC, 'C') | ||
|
|
||
| sofile = ctypes.util.find_library('mpv') | ||
| - if sofile is None: | ||
| - raise OSError("Cannot find libmpv in the usual places. Depending on your distro, you may try installing an mpv-devel or mpv-libs package. If you have libmpv around but this script can't find it, consult the documentation for ctypes.util.find_library which this script uses to look up the library filename.") | ||
| - backend = CDLL(sofile) | ||
| + if sofile is not None: | ||
| + backend = CDLL(sofile) | ||
| + else: | ||
| + try: | ||
| + backend = CDLL('libmpv.so') | ||
| + except OSError as e: | ||
| + raise OSError("Cannot find libmpv in the usual places. Depending on your distro, you may try installing an mpv-devel or mpv-libs package. If you have libmpv around but this script can't find it, consult the documentation for ctypes.util.find_library which this script uses to look up the library filename.") from e | ||
| fs_enc = sys.getfilesystemencoding() | ||
|
|
||
|
|
||
| @@ -2157,6 +2161,11 @@ | ||
| class MpvRenderContext: | ||
| def __init__(self, mpv, api_type, **kwargs): | ||
| self._mpv = mpv | ||
| + if sys.platform == 'android': | ||
| + import mpv_android | ||
| + mpv_android.ensure_android_java_vm() | ||
| + if api_type == 'opengl' and 'opengl_init_params' not in kwargs: | ||
| + kwargs['opengl_init_params'] = mpv_android.sdl_opengl_init_params() | ||
| kwargs['api_type'] = api_type | ||
|
|
||
| buf = cast(create_string_buffer(sizeof(MpvRenderCtxHandle)), POINTER(MpvRenderCtxHandle)) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.