PHP exec() 不适用于 ffmpeg

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2411988/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 06:22:24  来源:igfitidea点击:

PHP exec() Not Working With ffmpeg

phpffmpegexec

提问by Dodinas

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. (It echoes back "Success")

另外,当我运行上面相同的代码,但用“whoami”代替 ffmpeg 的东西时,它可以工作。(它呼应“成功”)

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

关于为什么这不起作用的任何想法?谢谢。

采纳答案by geocar

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

apache/web 用户可以访问/home/johnboy/ffmpeg/ffmpeg吗?也就是说,也许/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? Even when running as the apache user?

如果您将脚本运行到 php cli sapi,它的行为是否正确?即使以 apache 用户身份运行?

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

strace -ff当apache web用户通过php cli运行php脚本时显示什么?

回答by user432864

get the stderr will give the result

得到 stderr 将给出结果

try

尝试

ffmpeg -i inputfile [more_params] 2>&1

回答by karthi

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

回答by Luká? Lalinsky

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

您正在使用文件名的相对路径。您确定在正确的目录中执行命令吗?

回答by deddihp

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.

如果您想以这种方式执行某事,则会出现一些问题。
1.也许你有一些权限问题,网络服务器有限制来处理系统的一些执行。
2. 可能你的路径文件不正确。
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. 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.

无论如何,为了使我的执行顺利进行,我将编写 2 个程序,它们之间包含消息传递,例如客户端服务器程序。服务器会等待来自客户端的一些消息来执行一些命令(所有的命令,都没有权限问题)。您在 Web 中所需要做的就是调用您的客户端应用程序。

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.

希望这有帮助。

回答by rook

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

函数 exec() 只返回输出的最后一行,我怀疑该命令的最后一行是空白的。如果你想要命令的全部内容,你应该使用 shell_exec()。

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

还要跟踪命令的执行位置,请尝试: print(shell_exec("pwd"));

回答by Mark

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

Notice the 2>&1 part ...

注意 2>&1 部分...

回答by ITGuru

Enable safemode and it will work

启用安全模式,它将起作用