PHP exec() Not Working With ffmpeg

纵饮孤独 提交于 2021-02-07 03:47:38

问题


I'm attempting to run the following command in PHP (on Ubuntu):

<?php
 if (exec("/home/johnboy/ffmpeg/ffmpeg -i test1.mp4 -acodec aac -ab 128kb -vcodec mpeg4 -b 1220kb -mbd 1 -s 320x180 final_video.mov")) 
      { echo "Success"; }
      else { echo "No good"; }

And I always get "No good" echoed back, and no file created.

Interestingly, if I run the same exact command in Shell, it works, no problems.

Also, when I run the same code above, but subsitute "whoami" instead of the ffmpeg stuff, it works. (It echoes back "Success")

Any ideas on why this wouldn't be working? Thanks.


回答1:


Can the apache/web user reach /home/johnboy/ffmpeg/ffmpeg? That is, perhaps /home/johnboy is 0700 instead of 0755?

Perhaps there are resource limits affecting loading of such a large program and all its libraries?

If you run the script to the php cli sapi, does it behave correctly? Even when running as the apache user?

What does strace -ff show when the apache web user runs the php script through the php cli?




回答2:


get the stderr will give the result

try

ffmpeg -i inputfile [more_params] 2>&1



回答3:


Use this

$ffmpeg = "ffmpeg Installed path";
$flvfile = "source video file with root path";
$png_path " "Destination video file with root path and file type";


exec("$ffmpeg -y -i $flvfile -vframes 1 -ss 00:01:60 
     -an -vcodec png -f rawvideo -s 110x90 $png_path");



回答4:


You are using relative paths to the file names. Are you sure you are executing the command in the right directory?




回答5:


There would be some issues if you want to execute something that way.
1. Maybe you have some permission issue, the webserver have limitation to handle some execution to the system.
2. Maybe your path file is incorrect.
3. you can try to use shell_exec to perform the execution to the system.

Anyway, what I would do to make my execution would go smoothly are, I will write 2 programs with message passing included between them, for example client server program. The server would wait some messages from the client to execute some command (all of the command, it would be no permission issues). All you have to do in you web is to call your client application.

What I emphasize is to build some interface from web and the system. It would solve a lot of problem with permission issues.

hope this help.




回答6:


The function exec() only returns the last line of output, I suspect that the last line of that command is blank. if you want the entire contents of the command you should use shell_exec().

Also keep track of where the command is executing, try: print(shell_exec("pwd"));




回答7:


Enable safemode and it will work




回答8:


$output = shell_exec('/home/person/www/ffmpeg 2>&1');
echo "<pre>$output</pre>";

Notice the 2>&1 part ...



来源:https://stackoverflow.com/questions/2411988/php-exec-not-working-with-ffmpeg

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!