简体   繁体   English

PHP执行不执行命令

[英]PHP exec not executing command

I have used php's exec to execute FFmpeg command but its not woking when I open it in browser. 我已经使用php的exec来执行FFmpeg命令,但是当我在浏览器中打开它时它不会被唤醒。 But when i run this php file script in terminal it works fine.And my php safe mode is off. 但是当我在终端中运行这个php文件脚本时它运行正常。我的php安全模式已关闭。 please help me to get it solved. 请帮我解决。 my php code is 我的PHP代码是

<?php
$output=exec("ffmpeg -f image2 -i /home/phedra/imgs/image/img%03d.png -r 12 -s 610x489 /home/phedra/imgs/video/out.avi", $out);
echo $out;
echo $output;
?>

try giving full path where the ffmpeg application is located. 尝试给出ffmpeg应用程序所在的完整路径。

eg 例如

/usr/bin/ffmpeg

So your function might look like: 所以你的功能可能如下:

$output=exec("/usr/bin/ffmpeg -f image2 -i /home/phedra/imgs/image/img%03d.png -r 12 -s 610x489 /home/phedra/imgs/video/out.avi", $out);

You must check what is the location of "ffmpeg". 你必须检查“ffmpeg”的位置。

I had this problem and it turned out it was Apache's permission on the public directory. 我遇到了这个问题,事实证明这是Apache对公共目录的许可。

Note: I am running Ubuntu 14 on AWS 注意:我在AWS上运行Ubuntu 14

After installing FFmpeg I had to change the /var/www/* ownership to www-data . 安装FFmpeg后,我不得不将/var/www/*所有权更改为www-data

sudo chown -R www-data:root /var/www

(the www-data is the important part here) www-data是这里的重要部分)

Then I had the following code running, and it works when I access it via URL (Apache) 然后我运行了以下代码,当我通过URL(Apache)访问它时它可以工作

// test.php

$run = system("/opt/ffmpeg/bin/ffmpeg -i /var/www/html/input.mp4 -vf scale=640:480 /var/www/html/output.mp4 &");

if($run) {
    echo "success";
} else {
    echo "failed";
}

The /opt/ffmpeg/bin/ffmpeg is where my FFmpeg is running from. /opt/ffmpeg/bin/ffmpeg是我的FFmpeg运行的地方。 Yours might be /usr/bin/ffmpeg or something else. 你的可能是/usr/bin/ffmpeg或其他东西。 You can locate it by typing locate ffmpeg in the command line and looking through the list it gives you. 您可以通过在命令行中键入locate ffmpeg并查看它为您提供的列表来locate ffmpeg它。

The input file was a public .mp4 file and the output.mp4 file was going to the same location. 输入文件是一个公共.mp4文件,output.mp4文件将转到同一位置。

Run this in your command line: php test.php - works Run this from your browser: yourwebsite.com/test.php - works 在命令行中运行: php test.php - works从浏览器运行:yourwebsite.com/test.php - works

Note that if you are on windows you must use COMMAS. 请注意,如果您在Windows上,则必须使用COMMAS。 IE: IE:

$output=exec('"/usr/bin/ffmpeg" -f image2 -i /home/phedra/imgs/image/img%03d.png -r 12 -s 610x489 /home/phedra/imgs/video/out.avi', $out);

Like @Arfeen mentioned in his answer, you should execute the command with the path of ffmpeg, but, the given path in the answer "/usr/bin/ffmpeg" is not always the same. 就像@Arfeen在他的回答中提到的那样,你应该用ffmpeg的路径执行命令,但是,答案“/ usr / bin / ffmpeg”中的给定路径并不总是相同的。

First locate your ffmpeg by using the command : 首先使用以下命令找到您的ffmpeg:

which ffmpeg

The result in my case is : 我的结果是:

/usr/local/bin/ffmpeg 在/ usr / local / bin目录/的ffmpeg

Then go back to your php code and replace "ffmpeg" in the command by the path of ffmpeg (which is /usr/local/bin/ffmpeg in my case). 然后回到你的PHP代码,并在命令中用ffmpeg的路径替换“ffmpeg”(在我的例子中是/ usr / local / bin / ffmpeg)。

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

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