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

How to setup ffmpeg #3

Closed
LyanRicci opened this issue May 8, 2022 · 16 comments
Closed

How to setup ffmpeg #3

LyanRicci opened this issue May 8, 2022 · 16 comments

Comments

@LyanRicci
Copy link

As the title says, i want to use ffmpeg, how can i do it? I managed to get a compiled version of it (libffmpeg.so), I want to use it with your app because I can't use termux, and after months using your app I started to love it!
Oh another thing, do you think that I could replace libnode.so on the apk with a newer version of node would work? Or I would need to do more adjustments to make it work with a new version of node?

@warren-bank
Copy link
Owner

warren-bank commented May 8, 2022

Hi 😃

  1. cool.. I'm glad you like the app
    • I didn't think anyone knew about it.. or used it
  2. regarding updating Node.js
  3. regarding FFmpeg..
    • interesting ask
    • to use a pre-compiled library..
      • would require some coding to make it accessible from Java (ie: the Android app).. but that doesn't expose it to the Javascript runtime (ie: the code you run in Node.js)
      • to expose an API directly in Javascript would require updates to Node.js itself.. which is way out of scope
    • to use a pre-compiled executable..
      • shouldn't be too hard
      • if you download a binary for your ABI (ex: armv7-a) and save it (after being decompressed) to a directory that the front-end app can access (ex: /storage/emulated/0/Download/ffmpeg)
      • then (in theory) you should (?) be able to call it from Node.js w/ child_process
        • using any of: spawn, fork, exec
        • ex: child_process.execFileSync('/storage/emulated/0/Download/ffmpeg', ['-version'], {maxBuffer: 1024 * 1024 * 10})

@warren-bank
Copy link
Owner

PS: I'm going on a bit of a tangent here, but if you don't want to "roll your own" FFmpeg commands into a Node.js app.. this app is a front-end for FFmpeg that looks like a great utility.. written by the same developer who published the pre-compiled FFmpeg executables (mentioned previously).. and its releases include a separate APK for every individual ABI

@LyanRicci
Copy link
Author

You are a nice person! You actually answered my questions!

Regarding node my idea was downloading an app that uses nodejs.so (With an upper version) and then pasting it using apkeditor, I was wondering if that could work, but meh I'm fine with node v12. It works for now, I was just thinking in discord.js that needs an upper version. Well, I don't need it.

The reason behind the "I can't use termux" is that I have android 6. Unfortunately.

Regarding ffmpeg...

Well, on windows for example, I included fluent ffmpeg in my work so all I needed to use ffmpeg was setting the environment variable of the folder with the executable of ffmpeg. Now your app can use environment variables, but I don't know how to actually make it work, I have armeabi v7 (Obviously) so... I have 2 problems.

1: I don't know how a folder with ffmpeg Linux armeabiv7 looks like
2: Even if I find it, how to add it to the frontend app? Using environment variables?

I'm... Kinda new in all of this, my work is just a WhatsApp not, after all. I have only a year of experience with nodejs so sorry if I mess up things. Any idea you may have? Or ffmpeg can't be used with your nice and easy to use app?

@warren-bank
Copy link
Owner

Don't feel bad about using Android 6. I still have a ton of Android 4.1 and 4.4 devices onhand, and to be perfectly honest.. I prefer them over more recent versions of Android. With every update, Android seems to just strip away features and functionalities.. all in the name of tighter security. The one exception being Android 5.0 ..which gave us an upgradable System WebView; that was a worthwhile update.

I took a quick peek at the javascript npm module: fluent-ffmpeg.
Thoughts:

  • on 1st glance, it seems like it could make things simpler
  • on 2nd thought, passing command-line arguments directly would make testing much simpler and ensure that all features are called properly
    • personally, I'd avoid using a library that abstracts how the arguments are passed to the executable
  • this library (for some reason) requires a ffprobe executable.. in addition to ffmpeg
    • which might be hard to find for arm platforms
  • however, if you were to find one.. then it would be used in the following way:
    1. ffmpeg
      • download armv7-a-lite.tar.bz2 to your Windows laptop
      • use 7-zip to extract the ffmpeg binary executable
      • copy this ffmpeg binary executable to your phone and take a note of its absolute path
        • for example: /storage/emulated/0/Download/ffmpeg
      • when configuring your Node.js application in this frontend app:
        • set the environment variables:
          • FFMPEG_PATH=/storage/emulated/0/Download/ffmpeg
    2. ffprobe
      • download and save on your phone.. noting its absolute path
        • for example: /storage/emulated/0/Download/ffprobe
      • when configuring your Node.js application in this frontend app:
        • set the environment variables:
          • FFPROBE_PATH=/storage/emulated/0/Download/ffprobe

The configuration area looks like this:
configs

@LyanRicci
Copy link
Author

Hehe you are right, things are way less complicated in those androids, I have root so I can do wherever I want with my phone.
Which is way harder to get in every new version of android.

The great problem here is that I don't have a computer, if I had one I could just do a vbscript to run node on the background, I just have my phone. Alright I'll try what you said, I downloaded that already.

I don't... Think I need ffprobe, I'll check in a moment if the proyect has any reference to it. I'll be right back!

PS: Do you have WhatsApp? Or Discord? You seem like a nice person, and if you want, I would like to talk sometime about things like this and be friends, but only if you want! And if you don't, thank you for your help~!

@LyanRicci
Copy link
Author

IMG-20220508-WA0013
Looking good.
IMG-20220508-WA0012
Welp. This proved that it is possible to do it, but somehow failed, any idea besides searching the error in google and stack overflow? 🗡️

@LyanRicci
Copy link
Author

LyanRicci commented May 9, 2022

Looks like a permission error or something. I will try to copy ffmpeg to the root of the /data/data directory of your app, see? Thank god I have root. If I have success, i will close this issue alright?c:

@warren-bank
Copy link
Owner

you're right.. according to this discussion on SO.. you can't execute a binary from emulated storage.

since you have root, you should be able to copy it elsewhere and chmod +x ffmpeg.
I'm not sure what somebody without root would be able to do..
I'll look a bit more for a workaround.

@LyanRicci
Copy link
Author

LyanRicci commented May 9, 2022

Setting everything on thr folder of ffmpeg in your app data directory (I tried even moving ffmpeg to /system partition, lol) to chmod 777 didn't work either. I'm starting to wonder if the problem is executables permission on android or something. I don't mind giving this app superuser rights, I could try that, any idea on how to make your app to invoke "su"?
Or well, to solve eaccess error?

@warren-bank
Copy link
Owner

this is another interesting/related discussion..

@warren-bank
Copy link
Owner

this might be the reason that you can't execute the binary from within the app's home directory:

Behavior changes: apps targeting API 29+
Untrusted apps that target Android 10 cannot invoke exec() on files within the app's home directory. This execution of files from the writable app home directory is a W^X violation. Apps should load only the binary code that's embedded within an app's APK file.

This frontend app targets API 30.

@warren-bank
Copy link
Owner

Here is a similar issue for termux where they discuss the implications of this change in Android behavior.

It looks like the best solution they could come up with is to lock in: targetSdkVersion=28

What was it that I said earlier about how Android loves to break user-space? ☹️

@warren-bank
Copy link
Owner

warren-bank commented May 9, 2022

based on discussions here and here..

I wonder whether this would work:

su
mkdir '/data/data/com.github.warren_bank.nodejs_frontend/lib'
chmod 777 '/data/data/com.github.warren_bank.nodejs_frontend/lib'
cp '/storage/emulated/0/Download/ffmpeg' '/data/data/com.github.warren_bank.nodejs_frontend/lib/ffmpeg'
chmod 755 '/data/data/com.github.warren_bank.nodejs_frontend/lib/ffmpeg'

And then update your Node.js configs to refer to this new path:
FFMPEG_PATH=/data/data/com.github.warren_bank.nodejs_frontend/lib/ffmpeg

@LyanRicci
Copy link
Author

Alright. To make things less messed up, I moved ffmpeg to root partition, literally /ffmpeg
Chmod on 755 how you said.

I'm on api 23, that applies to me too? Because if so then that with no doubt is the problem, which makes me think in only 2 solutions.

1: Running you app as superuser
2: Somehow editing the app to add ffmpeg and somehow making that accessible to the JavaScript code. Which honestly, doesn't sounds easy.

Any more idea or should I close this as impossible and close the issue?:(

@LyanRicci
Copy link
Author

Look at this, with superuser rights and using root explorer, I copied ffmpeg to /system/bin to make it as a binarie embedded on android, and..... Surprisingly.... It works!

So perhaps I just need to run your app as su and done.
IMG-20220509-WA0001

@LyanRicci
Copy link
Author

Wait. I tried to run ffmpeg on node again, deleting ffmpeg_path and... IT WORKED, well, it leaved me another error, but it worked, it just worked! I think I just discovered something amazing. If you want to run an executable, just copy paste it to /system/bin !
That leaves me thinking... What if I could do that with node and npm? Because I don't have npm right now... ENDLESS POSSIBILITIES, and with no termux!

Thank you for alllll your help, thank you! HAHA TERMUX I DONT NEED YOU.
I will finally leave this as closed.

PS: In case you were wondering about the error, I just need to install libwepb
IMG-20220509-WA0002

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants