简体   繁体   English

PHP exec()不使用ffmpeg

[英]PHP exec() Not Working With ffmpeg

I'm attempting to run the following command in PHP (on Ubuntu): 我试图在PHP中运行以下命令(在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. 有趣的是,如果我在Shell中运行相同的命令,它可以工作,没有问题。

Also, when I run the same code above, but subsitute "whoami" instead of the ffmpeg stuff, it works. 此外,当我运行上面相同的代码,但替代“whoami”而不是ffmpeg的东西,它的工作原理。 (It echoes back "Success") (它回应了“成功”)

Any ideas on why this wouldn't be working? 关于为什么这不起作用的任何想法? Thanks. 谢谢。

get the stderr will give the result 得到stderr会给出结果

try 尝试

ffmpeg -i inputfile [more_params] 2>&1

Can the apache/web user reach /home/johnboy/ffmpeg/ffmpeg ? apache / web用户可以访问/home/johnboy/ffmpeg/ffmpeg吗? That is, perhaps /home/johnboy is 0700 instead of 0755? 也就是说,也许/home/johnboy是0700而不是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? 如果你运行脚本到php cli sapi,它的行为是否正确? Even when running as the apache user? 即使作为apache用户运行?

What does strace -ff show when the apache web user runs the php script through the php cli? 当apache web用户通过php cli运行php脚本时, strace -ff显示什么?

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");

You are using relative paths to the file names. 您正在使用文件名的相对路径。 Are you sure you are executing the command in the right directory? 您确定在正确的目录中执行命令吗?

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. 1.也许你有一些权限问题,网络服务器有限制处理系统的一些执行。
2. Maybe your path file is incorrect. 2.也许您的路径文件不正确。
3. you can try to use shell_exec to perform the execution to the system. 3.您可以尝试使用shell_exec来执行系统执行。

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. 无论如何,我要做的是让我的执行顺利进行,我将编写2个程序,其中包含消息传递,例如客户端服务器程序。 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. 您在Web上所要做的就是调用您的客户端应用程序。

What I emphasize is to build some interface from web and the system. 我强调的是从Web和系统构建一些接口。 It would solve a lot of problem with permission issues. 这将解决许可问题的许多问题。

hope this help. 希望这个帮助。

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

Notice the 2>&1 part ... 注意2>&1部分......

The function exec() only returns the last line of output, I suspect that the last line of that command is blank. 函数exec()只返回最后一行输出,我怀疑该命令的最后一行是空白的。 if you want the entire contents of the command you should use shell_exec(). 如果你想要命令的全部内容,你应该使用shell_exec()。

Also keep track of where the command is executing, try: print(shell_exec("pwd")); 还要跟踪命令执行的位置,尝试: print(shell_exec("pwd"));

启用安全模式,它将工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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