ffmpeg: not found when running ffmpeg via php xampp (mac) - php

I am trying to execute ffmpeg from php. I have installed ffmpeg locally on my mac via homebrew and I am able to run the commands I need via terminal.
When I try to execute the following code:
<?php
echo "Starting ffmpeg";
$output = shell_exec("ffmpeg -i test.mp3 -codec:a libmp3lame -b:a 128k out.mp3 2>&1");
echo "<pre>$output</pre>";
?>
I am receiving the following on my browser:
Starting ffmpeg
sh: 1: ffmpeg: not found
I am assuming that I somehow need to install ffmpeg to my xampp server but it is not obvious how to do that. After searching online I can find linux and Windows tutorials but I couldn't figure out something out by looking at them.
What I tried doing was to download the ffmpeg static build form https://ffmpeg.org/download.html#build-mac and placed it in the htdocs holder, and then tried to execute ffmpeg as if it was an executable (after changing chmod), but that gave me
sh: 1: ./ffmpeg: Exec format error
How would one go and install and then run ffmpeg on their xampp server?

First check for installation of tha package by "ffmpeg -version"
If it is installed then check for path "whereis ffmpeg", then try your command with full ffmpeg path

I realised that the apache server that xampp starts is a debian instance. I was using the wrong static build (mac instead of debian one). Downloading and using the debian one resolved my issue.

Related

No response from FFMPEG from inside php (works in command line)

So I have this executable working fine in a Windows 10 dev environment:
$cmd = 'C:/ffmpeg/bin/ffmpeg.exe -i video.mp4 -i audio.mp3 -c:v copy -c:a aac output.mp4';
exec($cmd, $output)
However when I move it into the Ubuntu staging environment and change the path to:
/usr/bin/ffmpeg
there is no response from it.
The following works in the ubuntu terminal
ffmpeg -v, ffmpeg -i, php -v, ...
but there is no response from it from inside php.
Am I missing something here?
I've also tried adding sudo to the above command which seems to make no difference.
(Yes I know I should be developing in the same environment as the staging/prod servers but it's not an option in this specific case).

bash: php: command not found in VSC only

php -v works in individual terminals, but do not work in Visual Studio Code Terminal.
I tried php -v in Git Bash and Command Prompt in Windows, and all worked.
So I tried in VSC where I set default shell to Git Bash, but it shows error with bash: php: command not found
(I added php bin path to Path)
Terminal at VSC do not get PATH variable?
I got the same problem... My problem was in VSC FlatPack version available in the Software Manager in Mint 18.3. I uninstalled it and got the original version on https://code.visualstudio.com See more at: https://github.com/microsoft/vscode/issues/44646

How to exec a command installed with `npm` command in PHP using `exec()`?

In PHP running on Ubuntu, I can run exec('npm -v') and the output is good,
but I can't run exec('gitbook xxxx').
gitbook is a npm package I installed by
npm install gitbook -g
I can run gitbook xxxx in the Ubuntu terminal, how can I run it from my PHP code?
If you run php by nginx or apache (for example, visit url example.com/index.php), sometime you need to export the PATH
exec("export PATH=/usr/local/bin && gitbook build);
after I added export PATH, everything works fine.
I tried once like this on UNIX-based OS:
You can run shell commands via the exec() function:
// make an php file to execute shell script
exec("node yourscript.js &", $output);
Well output here become array of each line of output along with process id. You can kill process by processid also.
exec("kill " . $processid);
This how I was did. Other then this you can use node supervisor. Hope it will help you. Try your also with node command.

How do I run ffmpeg with PHP on a Mac with XAMPP

There is literally nothing on this anywhere, the little there is does not work and is too advanced for me. If you can answer this you would make my life. How do I run ffmpeg commands from php which is running on my localhost? I prefer XAMPP, but MAMP will do just fine, at this stage I will use anything. Do I need to install ffmpeg on the XAMPP server itself, or does it just need to be installed on the mac? I can run the ffmpeg commands fine from terminal, for example,
ffmpeg -i Tmpfile.mp4 -c:v libx264 -preset ultrafast video.mp4
works fine, but
echo shell_exec("ffmpeg -i Tmpfile.mp4 -c:v libx264 -preset ultrafast video.mp4");
does nothing when I load the webpage with the index.php that that code is in.
I will buy you a cookie if you can solve my problem :)
You should be more specific when describing the problem, e.g. including OSX version, ffmpeg version, etc.
I successfully managed to reproduce your case, here it is the procedure:
1. ffmpeg
I installed ffmpeg via brew. ffmpeg version is currently 3.2.4.
2. PHP server
On macOS Sierra (but other previous versions offer this feature as well), you can start a PHP server by just typing
$ php -S 0.0.0.0:8080
in your shell. The web server will listen on port 8080 in that case.
3. The PHP script
I basically used the script you gave in your question, with a little modification:
<?php
echo "loading, please wait...";
echo shell_exec("ffmpeg -i temp.mp4 -c:v libx264 -preset ultrafast video.mp4 2>&1");
Did you notice the 2>&1? It is used to redirect the sterr output to the stdoutput as ffmpeg would not print anything on standard output :)
4. Safe mode?
Please be sure to disable PHP safe mode, as the shell_exec method is disabled when safe mode is ON (reference here).
Ah, I have found the answer. I needed to add this to the beginning of the php script
exec('unset DYLD_LIBRARY_PATH ;');
putenv('DYLD_LIBRARY_PATH');
putenv('DYLD_LIBRARY_PATH=/usr/bin');

How to install ffmpeg using xampp

I am trying to install ffmpeg onto my localhost server. I have followed countless blogs and tutorials online form other people who are stuck with this same problem. I follow everything to the letter.
Unzip the file
Copy php_ffmpeg.exe to ext folder in php
copy the rest to system 32
As it says however when I do this I get this error when I start apache.
Fair play but it is in the folder
I also get this error as well:
And Again, here it is:
I have added the extention to my php.ini file
extension=php_ffmpeg.dll
The first time I go this to work I placed the ffmpeg.exe file onto my local host server and ran commands like this:
$cmd = "$ffmpegpath -i $input -an -ss $sec -s $size $output";
shell_exec($cmd);
This works fine on my computer but not on an actual server. Could somebody offer some advice or guidene on where I have one wrong installing the extension or why running the .exe file on a lunix server with shell_exec doesn't work
Yeah ive had problems with the extension version, with windows. I found it is much easier to not use the PHP extension and just call the standard FFMPEG for windows binary with exec() within a simple class, ive added an example script. It will be trivial for you to add a ffmpeg_convert() method to the class.
VideoThumbNailer.example.zip
Edit
Just noticed this statement,
Could somebody offer some advice or guidene on where I have one wrong
installing the extension or why running the .exe file on a lunix
server with shell_exec doesn't work
Linux has its own versions of FFMPEG, you cant mix the two. Your need to install FFMPEG on linux with something like:
sudo apt-get -qqy php5-ffmpeg
And change the path to FFMPEG in your cmd to, leaving out the .exe part:
ffmpeg -i $input -an -ss $sec -s $size $output
Hope it helps

Categories