Problem executing ffmpeg which was installed from Termux app

Post your questions and help other users.

Moderator: Martin

jaejunks
Posts: 13
Joined: 03 Apr 2018 13:31

Problem executing ffmpeg which was installed from Termux app

Post by jaejunks » 26 Dec 2018 08:49

FYI, my Android 6 phone is rooted and Automagic has been granted root access via Superuser app.

The ffmpeg program is located in below path.

Code: Select all

/data/data/com.termux/files/usr/bin/ffmpeg
So I use the "Execute Root Command" action to execute it. It's command line is e.g.

Code: Select all

/data/data/com.termux/files/usr/bin/ffmpeg -i /storage/emulated/0/Download/sample.mp4
The action succeeded but ffmpeg gives non zero exit code and it outputs below message to the standard error handle.

Code: Select all

CANNOT LINK EXECUTABLE: library "libavfilter.so" not found
page record for 0x7f80e0b010 was not found (block_size=16)
I know that ffmpeg can't find the "libavfilter.so" file because it's located in a different path which is:

Code: Select all

/data/data/com.termux/files/usr/lib/libavfilter.so
So I use below path as the working directory for the "Execute Root Command" action.

Code: Select all

/data/data/com.termux/files/usr/lib/
But now the action triggers an exception. Here's the exception message:

Code: Select all

Error running exec(). Command: [su] Working Directory: /data/data/com.termux/files/usr/lin Environment: null
And here's the exception stack trace:

Code: Select all

java.io.IOException: Error running exec(). Command: [su] Working Directory: /data/data/com.termux/files/usr/lib Environment: null
	at java.lang.ProcessManager.exec(ProcessManager.java:211)
	at java.lang.Runtime.exec(Runtime.java:174)
	at ch.gridvision.ppam.androidautomagic.model.a.ao$1.a(SourceFile:211)
	at ch.gridvision.ppam.androidautomagic.model.a.ao$1.c(SourceFile:176)
	at ch.gridvision.ppam.androidautomagiclib.util.ci$1.run(SourceFile:40)
	at java.lang.Thread.run(Thread.java:818)
Caused by: java.io.IOException: Permission denied
	at java.lang.ProcessManager.exec(Native Method)
	at java.lang.ProcessManager.exec(ProcessManager.java:209)
	... 5 more
What went wrong here? I thought Automagic already have root access?
How to solve this problem?

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Problem executing ffmpeg which was installed from Termux

Post by Desmanto » 27 Dec 2018 06:27

I remember ever get the similar problem, but not when in Automagic. It seems it is the lib folder or probably the data/data/com.termux/files/usr/lib/libavfilter.so doesn't have the proper permission. Try to change the permission of that file to 755. (at least must be executeable).
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

jaejunks
Posts: 13
Joined: 03 Apr 2018 13:31

Re: Problem executing ffmpeg which was installed from Termux

Post by jaejunks » 27 Dec 2018 13:37

I'm not familiar enough with linux security, but AFAIK, shouldn't the root access already have higher access level to the point that file/directory permission mechanism doesn't matter any more?

Anyway... I've tried changing the permission for the `libavfilter.so` file as well as the `lib` directory which are originally 700, to 755. But the result is the same. Same exception message and stack trace.

I've also tried changing the permission for `ffmpeg` file as well as the `bin` directory from 700 to 755. But still same result too. :(

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Problem executing ffmpeg which was installed from Termux

Post by Desmanto » 27 Dec 2018 17:08

No, we still have to set the binary as executeable permission. But using root, we can easily chmod the file to executeable. I simply use MiXplorer, browse to the file and set the permission by ticking the exec perm.

Can you try executing the ffmpeg directly from termux with su? Just to test whether the binary is working properly and producing proper output. Some binary required to be compiled for ROM specific. Example, I tried several sqlite binary and it doesn't work, probably the same error as your ffmpeg (I forgot the exact error message). But the sqlite binary I got from the Titanium Backup, is working properly. It is also located at the /data/data folder, and by default has been set to 755. Using execute root command can execute the sqlite binary properly, without any error.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

jaejunks
Posts: 13
Joined: 03 Apr 2018 13:31

Re: Problem executing ffmpeg which was installed from Termux

Post by jaejunks » 28 Dec 2018 11:27

Yes, ffmpeg can be executed from the Termux console.

I also found out that even if I set the command line to:

Code: Select all

echo 123
And specify the working directory like previously mentioned, the action triggers the same exception.

If I don't specify the working directory, the action works fine and outputs `123` to the standard output.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Problem executing ffmpeg which was installed from Termux

Post by Martin » 29 Dec 2018 14:40

The working directory is used to execute the entire root process that will then execute the specified command so Automagic attempts to set the working directory before the process actually gained root privileges.
In this case it's probably better to change the working directory before executing the command. A command like cd /data/data/com.termux/files/usr/bin/ffmpeg && ./ffmpeg -i /storage/emulated/0/Download/sample.mp4 might work (but untested).

Regards,
Martin

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Problem executing ffmpeg which was installed from Termux

Post by Desmanto » 30 Dec 2018 11:51

Strange, I try to set the working directory to Titanium Backup's folder and still echo fine. I usually don't set the working directory. But I prepared the command in another script prior the execute command. example

Code: Select all

cmd = "echo 123";
Later at the execute root command, just use

Code: Select all

{cmd}
It provide a better view for longer script in the script and much easier to put variable at there.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

jaejunks
Posts: 13
Joined: 03 Apr 2018 13:31

Re: Problem executing ffmpeg which was installed from Termux

Post by jaejunks » 30 Dec 2018 14:35

@Desmanto:

If you're using a different system configuration, it may work. FYI, mine is Android 6 (Marshmallow) in a rooted Samsung phone with Superuser.

@Martin:

Well, I tried to use these command lines and left the working directory blank. The actions for both succeeded, but gave the `CANNOT LINK EXECUTABLE: library "libavfilter.so" not found` error message.

Code: Select all

cd /data/data/com.termux/files/usr/lib && /data/data/com.termux/files/usr/bin/ffmpeg -i /storage/emulated/0/Download/sample.mp4

Code: Select all

cd /data/data/com.termux/files/usr/bin && ./ffmpeg -i /storage/emulated/0/Download/sample.mp4
I also noticed that when in Termux console, there's an environment variable called `LD_LIBRARY_PATH` like below:

Code: Select all

LD_LIBRARY_PATH=/data/data/com.termux/files/usr/lib
That's the only environment variable which has a reference to Termux's `files/usr/lib` directory, BTW. A variable which doesn't exist in the "Execute Root Command" action's terminal session. So I thought that's the reason why ffmpeg can't find the `libavfilter.so` module. Then I thought about defining that variable before executing ffmpeg, i.e.:

Code: Select all

set LD_LIBRARY_PATH=/data/data/com.termux/files/usr/lib && /data/data/com.termux/files/usr/bin/ffmpeg -i /storage/emulated/0/Download/sample.mp4
That failed too unfortunately, with the same `library "libavfilter.so" not found` error message.

Then I found out that the environment variable doesn't even get defined based on below command line. i.e. the `LD_LIBRARY_PATH` environment variable isn't listed when `set` command (without any argument) is issued.

Code: Select all

set LD_LIBRARY_PATH=/data/data/com.termux/files/usr/lib && set
Why didn't the environment variable got defined? Did I use the `set` command syntax incorrectly? Also, is the `LD_LIBRARY_PATH` environment variable a standard *nix system environment variable for specifying the library path?

jaejunks
Posts: 13
Joined: 03 Apr 2018 13:31

Re: Problem executing ffmpeg which was installed from Termux

Post by jaejunks » 30 Dec 2018 14:40

Oh, I found it! Finally it works! Using below command line.

Code: Select all

export LD_LIBRARY_PATH=/data/data/com.termux/files/usr/lib && /data/data/com.termux/files/usr/bin/ffmpeg -i /storage/emulated/0/Download/sample.mp4

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Problem executing ffmpeg which was installed from Termux

Post by Desmanto » 31 Dec 2018 14:16

Oh, so you need to set the lib path first. You can actually just put it into 2 lines. But you must type the command in other place first and copy-paste it to the Execute Root Command field. It will appear as no newline, but actually the line is separated.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Post Reply