Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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");
like image 471
PreeT Avatar asked Mar 06 '15 13:03

PreeT


People also ask

How to use FFMpeg in PHP?

FFMpeg\FFMpeg is the main object to use to manipulate medias. To build it, use the static FFMpeg\FFMpeg::create : $ffmpeg = FFMpeg\FFMpeg::create(); FFMpeg will autodetect ffmpeg and ffprobe binaries.

What is FFMpeg command?

FFmpeg MOV to MP4 (Convert Video/Audio to Another Format) FFmpeg is extremely useful to convert your video file to another format. For example, to convert MOV to MP4 with FFmpeg, run the command below. ffmpeg -i input.mov output.mp4. Similarly, you can transcode audio files with FFmpeg by specifying the output format.


2 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.

like image 135
slhck Avatar answered Oct 09 '22 03:10

slhck


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();
like image 39
Saadettin Sivaz Avatar answered Oct 09 '22 02:10

Saadettin Sivaz