简体   繁体   中英

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.

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

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)

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM