How to Run Ffmpeg Command in Php

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");
3

3 Answers

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.

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();
3

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

then after run this command

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest