Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFMpeg working in command line but not in PHP using exec();

I am using FFMpeg to covert videos and it is working fine from the command line. I am using the following command:

ffmpeg -i input.mpg  -vcodec libx264 -b 819200 -s 100x100 -g 15 -bf 3 -b_strategy 1 -coder 1 -qmin 10 -qmax 51 -sc_threshold 40 -flags +loop -cmp +chroma -me_range 16 -me_method hex -subq 5 -i_qfactor 0.71 -qcomp 0.6 -qdiff 4 -directpred 1 -flags2 +fastpskip -dts_delta_threshold 1 -acodec libfaac -ab 48000 output.m4v

However, when I run the command using PHP exec(), the output video is not encoded correctly and is distorted and cropped. I am using the following in PHP:

$output = exec($cmd . ' 2>&1', $output, $return);

The $output returns a '0' successful code.

Does any one have any suggestions?

Thank you.

like image 884
Kit Avatar asked Jan 20 '23 09:01

Kit


2 Answers

This is unusual. It is possible that you have more than one ffmpeg binary installed, and the one that is being called by the PHP/Apache user is not the same as the one you call as your user from the command line.

Try specifying the full path to your ffmpeg binary (/usr/bin/ffmpeg or whatever) inside your exec().

like image 197
glomad Avatar answered Jan 28 '23 13:01

glomad


It sounds like some command line options are getting lost/altered. I would try to split this into a 2 part process:

  1. write a shell script on-the-fly (from PHP) that has all the proper command arguments (make it executable)
  2. execute the shell script (from PHP)
like image 21
Teddy Avatar answered Jan 28 '23 12:01

Teddy