Android Compile python module binding with C/C++ libraries
#1
Hello,
i would like to use ffmpeg/ffprobe in order to get video information such as codec and resolution. Video file could be a remote http url or a local file.
I tried to use ffmpeg with subprocess but on Android 10+ it is not possibile because of "permission denied" .
So I'm trying to compile package named "PyAV" with cython, that has ffmpeg C functions binding. In this case, I think, ffmpeg will be executed inside python process so Android should not block my script.

Unfortunately, after compiling package for arm7 and trying to import package in my addon, it has not correctly imported. No errors, but none of module's function are available

I wander is it possibile to import a compiled module in kodi addon?
How can I correctly compile my package in order to use it in my addon?

thanks in advance
Reply
#2
(2021-10-01, 15:39)fatshotty Wrote: Hello,
i would like to use ffmpeg/ffprobe in order to get video information such as codec and resolution. Video file could be a remote http url or a local file.
I tried to use ffmpeg with subprocess but on Android 10+ it is not possibile because of "permission denied" .
So I'm trying to compile package named "PyAV" with cython, that has ffmpeg C functions binding. In this case, I think, ffmpeg will be executed inside python process so Android should not block my script.

Unfortunately, after compiling package for arm7 and trying to import package in my addon, it has not correctly imported. No errors, but none of module's function are available

I wander is it possibile to import a compiled module in kodi addon?
How can I correctly compile my package in order to use it in my addon?

thanks in advance

This is a good question, im just curious about how ffmpeg is likely to be triggered?
Like you've imported the PyAv module you've compiled and are then trying to trigger ffmpeg, where is ffmpeg coming from?

Under normal circumstances it would need to be an installed program which could be called on its own right? So if this were on regular python and it was installed on the machine.

But presumably part of the issue is not being able to install ffmpeg? Or not being able to call ffmpeg which is installed?

I would have throught that without the relevant environment variables the kodi CPython environment wouldnt know where ffmpeg is?

I've done stuff on kodi importing modules from other addons when I couldnt figure out how to do something any other way, so for one case that required changing the current python directory eg:

python:

    import sys
    import os,sys,inspect
    currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
    parentdir = os.path.dirname(currentdir) + '/plugin.some.other.addon/res'
    sys.path.insert(0,parentdir)

Probably thats something you have already tried, but maybe adding the correct directory to the python environment will help?
Reply
#3
Building binary extensions for Android is a tricky thing. And if you want to build Python bindings for ffmpeg you need to have it statically linked. Otherwise where will ffmpeg come from?
Reply
#4
(2021-10-07, 19:39)henryjfry Wrote:
(2021-10-01, 15:39)fatshotty Wrote: Hello,
i would like to use ffmpeg/ffprobe in order to get video information such as codec and resolution. Video file could be a remote http url or a local file.
I tried to use ffmpeg with subprocess but on Android 10+ it is not possibile because of "permission denied" .
So I'm trying to compile package named "PyAV" with cython, that has ffmpeg C functions binding. In this case, I think, ffmpeg will be executed inside python process so Android should not block my script.

Unfortunately, after compiling package for arm7 and trying to import package in my addon, it has not correctly imported. No errors, but none of module's function are available

I wander is it possibile to import a compiled module in kodi addon?
How can I correctly compile my package in order to use it in my addon?

thanks in advance

This is a good question, im just curious about how ffmpeg is likely to be triggered?
Like you've imported the PyAv module you've compiled and are then trying to trigger ffmpeg, where is ffmpeg coming from?

Under normal circumstances it would need to be an installed program which could be called on its own right? So if this were on regular python and it was installed on the machine.

But presumably part of the issue is not being able to install ffmpeg? Or not being able to call ffmpeg which is installed?

I would have throught that without the relevant environment variables the kodi CPython environment wouldnt know where ffmpeg is?

I've done stuff on kodi importing modules from other addons when I couldnt figure out how to do something any other way, so for one case that required changing the current python directory eg:

python:

    import sys
    import os,sys,inspect
    currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
    parentdir = os.path.dirname(currentdir) + '/plugin.some.other.addon/res'
    sys.path.insert(0,parentdir)

Probably thats something you have already tried, but maybe adding the correct directory to the python environment will help?
thanks for reply
Yes, I've already tried to "insert" the correct path in my code. No success Sad
however I read about the script "Application Binary Interface" (ABI) that correctly imports any binary python module. 
Unfortunately it doesn't work for me, because it imports only one module and not the entire folder module (with all sub-module, I mean).
For example:
PyAV has been built in the "py-av-build" folder. In that folder I found all compiled module such  as the "core.so", "container.so", "video.so" etc....
The ABI script is made to import only one module, so I need to specify which file I want to import: one of "core", "container", "video"...
Maybe do I need to import the entire folder module?

Next step
Just for test, I forced to import the "core" module. It fails because the ffmpeg binding is looking for libwscale.so system library that Android not have :/
I did understand that the problem now is to compile PyAV with shared-reference of ffmpeg (as usual), but  I need to compile ffmpeg with static-reference for all other libraries.
In this way I can't compile PyAV because of a lot of compiling error, but I don't know the reason :/
Reply
#5
(2021-10-12, 08:53)Roman_V_M Wrote: Building binary extensions for Android is a tricky thing. And if you want to build Python bindings for ffmpeg you need to have it statically linked. Otherwise where will ffmpeg come from?
thanks for reply
indeed ffmpeg is statically compiled with PyAV. Everything works fine on my pc, but it fails running on android :/
As per my previous post, I encountered some errors during compiling PyAV with ffmpeg with static-reference with other libraries

Thanks
Reply
#6
the only way to make this work on android is to add pyAV to kodi's build system, like a few other addons with binary dependencies like pycrytodome and pil.
It would then be part of kodi, linked against kodi's ffmpeg.
Reply
#7
(2021-10-17, 07:07)wsnipex Wrote: the only way to make this work on android is to add pyAV to kodi's build system, like a few other addons with binary dependencies like pycrytodome and pil.
It would then be part of kodi, linked against kodi's ffmpeg.

thanks for reply
unfortunately I didn't understand what I should do :/
What do you mean with "add pyAV to kodi's build system" ? How could I add PyAV to kodi? 
I would like to create a third-party addon which can be used as external-dependency on any other addon... Isn't it possible?

Thanks
Reply

Logout Mark Read Team Forum Stats Members Help
Compile python module binding with C/C++ libraries0