FFMpeg runs on the command line, but not in a PHP script

I use FFMpeg to convert videos, and it works fine from the command line. I use the following command:

ffmpeg -i input.avi -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv output.flv

However, when I run the command using a PHP script, the output video is not encoded.

exec("ffmpeg -i input.avi -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv output.flv",$output, $returnvalue);

$returnvalue = 127;

Installed FFMPEG path:

[root@localhost ~]# which ffmpeg

/root/bin/ffmpeg

My Script Path:

www.domainname.com/core/foldername/ffmpeg.php

Please provide me a solution for the same ASAP.

Thank.

+4
source share
3 answers

The natural way to run ffmpegfrom PHP scripts is something like:

<?php
    echo "Starting ffmpeg...\n\n";
    echo shell_exec("ffmpeg -i input.avi output.avi &");
    echo "Done.\n";
?>

, . , , , , ffmpeg ( "&" ), PHP ffmpeg . , PHP exec(), :

, , . PHP .

, shell_exec() ​exec(). PHP- .

, , - :

<?php
    echo "Starting ffmpeg...\n\n";
    echo shell_exec("ffmpeg -i input.avi output.avi >/dev/null 2>/dev/null &");
    echo "Done.\n";
?>

, " > /dev/null" , OUTDUT (stdout) ffmpeg /dev/null ( ) 2 > /dev/null " ERROR (stderr) /dev/null ( ). : " > /dev/null 2 > & 1". , -.

. ffmpeg stderr , stdout ( , ffmpeg, ). , ffmpeg , , , stderr , .

, , INPUT (stdin). ffmpeg , ( ) / . ffmpeg , ffmpeg, ( ) stdin. ffmpeg, / ** " ffmpeg :

<?php
    echo "Starting ffmpeg...\n\n";
    echo shell_exec("ffmpeg -y -i input.avi output.avi </dev/null >/dev/null 2>/var/log/ffmpeg.log &");
    echo "Done.\n";
?>

"- y" (output.avi) yes/no. , , , "- n" .

Wrapper

PHP ffmpeg PHP , . PHP-FFMpeg. , ffmpeg ffprobe, PHP. PHP- :

$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->open('video.mpg');
$video
    ->filters()
    ->resize(new FFMpeg\Coordinate\Dimension(320, 240))
    ->synchronize();
$video
    ->save(new FFMpeg\Format\Video\X264(), 'export-x264.mp4')

, . , GearmanClient, .

: ffmpeg-php - , 2007 ( "ffmpeg-0.4.9_pre1 " ), , ffmpeg . / ffmpeg's, ffmpeg-php ffmpeg.

.

+4

, ; PHP - FFMPEG. .

exec("/root/bin/ffmpeg -i input.avi -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv output.flv",$output, $returnvalue);

- , php - , , . , .

, , !

.

+1

I looked at a solution that helps most of the people I talked about about this in a different thread.

fooobar.com/questions/1563022 / ...

Essentially, your user needs access to public directories.

<?php 
   exec('whoami'); // Gives you the running user; often it www-data
?>

Then change your state ownership to the user whoami.

sudo chown -R www-data:root /var/www
0
source

All Articles