7

I need to run the ffmpeg command in the PHP.

But php-ffmpeg is no more supports the latest version and out of date.

May i know alternate way to run the ffmpeg command in the webfile (PHP,Javascript,jQuery).

I try the exec() and shell_exec() in the PHP file but gets the blank output.

echo shell_exec("/usr/local/bin/ffmpeg  -i test.mp3  -codec:a libmp3lame -b:a 128k out.mp3");

and

 echo shell_exec("ffmpeg  -i test.mp3  -codec:a libmp3lame -b:a 128k  out.mp3");
luchaninov
  • 6,792
  • 6
  • 60
  • 75
PreeT
  • 119
  • 1
  • 1
  • 7
  • at server side you can try `exec('ffmpeg .....');` – Santa's helper Mar 06 '15 at 13:26
  • 1
    @Santa'shelper i try exec() and shell_exec() but blank output is there. will you plz let me know syntax for change mp3 bitrate. so i clear i did'nt go wrong. – PreeT Mar 06 '15 at 13:30
  • i am not very good at ffmpeg but it should be look like `exec('ffmpeg -i /path/to/my.mp3 -r 44100 /path/to/target.mp3', $output); var_dump($output);` Warning: i am not pretty sure about the -ar 44100 – Santa's helper Mar 06 '15 at 14:01

3 Answers3

17

ffmpeg outputs on stderr, so you need to redirect the output. Add 2>&1 to your command line:

echo shell_exec("/usr/local/bin/ffmpeg -i test.mp3 -codec:a libmp3lame -b:a 128k out.mp3 2>&1");

Then you will see the output.

slhck
  • 36,575
  • 28
  • 148
  • 201
  • 2
    2 points to note here: 1) there must be a space prior to the 2 and 2) you must use double quotes not single – Antony Sep 04 '17 at 14:48
  • i do not understand one thing when i run the file in the browser is ge no such file or directory but when i run in terminal thing are okay Please help – mwangaben Oct 21 '17 at 04:36
  • @mwangaben What do you mean by "file" – do you mean you want to run `ffmpeg`? Make sure that you either call the full path to ffmpeg (e.g., `/usr/local/bin/ffmpeg`) or that your `$PATH` in PHP contains the folder where `ffmpeg` is. – slhck Oct 21 '17 at 11:49
3

use FFMpeg\FFMpeg, you can install with composer: "php-ffmpeg/php-ffmpeg": "0.5.*@dev" (FFMpeg\FFMpeg Git Repository)

Or

use Symfony Process, you can install with composer: "symfony/process" : "~2.0" (Symfony Process Documentation)

Or

use proc_open() function.

FFMpeg\FFMpeg used Symfony Process and Symfony Process used proc_open() function :)

I prefer to use Symfony Process:

require 'vendor/autoload.php';

use Symfony\Component\Process\Process;
$process = new Process('ls -lsa');
$process->run();
-1

first you have to install ffmpeg library in your server. with out install ffmpeg in your server command will not run.

the following link will help you

https://ffmpeg.org/

https://www.resellerspanel.com/articles/dedicated-servers-articles/dedicated-servers-howtos/how-to-install-ffmpeg-on-a-dedicated-server/

then after run this command

 exec("ffmpeg  -i test.mp3  -codec:a libmp3lame -b:a 128k  out.mp3");