FFMpeg working in command line but not in PHP usin

2019-05-07 05:24发布

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.

3条回答
混吃等死
2楼-- · 2019-05-07 05:38

I would probably try:

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

Also, transcoding can take a while. Are you certain you are waiting long enough for the transcode to complete?

查看更多
闹够了就滚
3楼-- · 2019-05-07 05:51

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().

查看更多
在下西门庆
4楼-- · 2019-05-07 05:52

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)
查看更多
登录 后发表回答