FFMpeg runs on the command line, but not in PHP using exec ();

I use FFMpeg for hidden videos and it works fine from the command line . I use 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 incorrectly encoded and distorted and cropped . I use the following in PHP:

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

Result $ returns the successful code '0'.

Does anyone have any suggestions?

Thanks.

+4
source share
3 answers

It's unusual. You may have more than one ffmpeg binary installed, and the one that is called by the PHP / Apache user is different from the one you invoke as the user from the command line.

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

+7
source

Some command line options seem to be lost / modified. I would try to break this down into a 2-part process:

  • write a shell script on the fly (from PHP) that has all the necessary arguments to the command (make it executable)
  • execute shell script (from PHP)
+1
source

I would probably try:

1) change '2> & 1' to '2> & 1 &'

In addition, transcoding may take some time. Are you sure you are waiting for the completion of the transcode?

0
source

Source: https://habr.com/ru/post/1341346/


All Articles