简体   繁体   English

FFMPEG命令在PHP中不起作用。 (与MAMP不相容)

[英]FFMPEG command doesn't work in PHP. (Incompatibilty with MAMP)

I'm a bit of a beginner when it comes to PHP, and I'm trying to create a simple(ish) system where files are input, and then converted to html5 video in various resolutions. 我在PHP方面有点初学者,我正在尝试创建一个简单的(ish)系统,其中输入文件,然后转换为各种分辨率的html5视频。

I've sorted out how to handle multiple file uploads etc, but now I'm having a problem. 我已经整理出如何处理多个文件上传等,但现在我遇到了问题。

I can't seem to get exec to execute FFMPEG in PHP. 我似乎无法让exec在PHP中执行FFMPEG。

For example, if I type this into my command line (Terminal on Mac OSX 10.8), It converts the video correctly: 例如,如果我在我的命令行中键入它(Mac OSX 10.8上的终端),它会正确转换视频:

ffmpeg -i /Users/charlieryan/Desktop/MOV01785.MPG websample.mov

This correctly outputs the converted video file into my home directory. 这会将转换后的视频文件正确输出到我的主目录中。

However if I run this in PHP as follows: 但是如果我在PHP中运行它如下:

exec('ffmpeg -i /Users/charlieryan/Desktop/MOV01785.MPG websample.mov');

Absolutely nothing happens ... my stat monitor doesn't register any change in processor use, and I can't find the output file anywhere on my system. 绝对没有任何反应...我的统计监视器没有记录处理器使用的任何变化,我无法在我的系统上的任何地方找到输出文件。

Since I'm a bit of a noob at this, I'm assuming I'm doing something wrong, but what is it? 由于我在这方面有点像菜鸟,我假设我做错了什么,但它是什么?

Thanks, 谢谢,

Charlie 查理

After alot of help from birgire and a lot of fiddling around I've sorted it. 经过birgire的大量帮助和大量的摆弄后,我对它进行了整理。

This problem comes from an incompatibility with the MAMP sandbox. 此问题来自与MAMP沙箱的不兼容性。 Which can be solved as follows: 哪个可以解决如下:

Go to Terminal and type: 转到终端并键入:

sudo nano /Applications/MAMP/Library/bin/envvars

Then comment out the following lines with a hash (#) 然后使用哈希(#)注释掉以下行

# DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
# export DYLD_LIBRARY_PATH

And then add the following line to the file 然后将以下行添加到文件中

export PATH="$PATH:/opt/local/bin"

Then, go back to MAMP and restart your servers, navigate back to the page, and you'll be good to go. 然后,返回MAMP并重新启动服务器,导航回页面,您将会很高兴。

You should first try to see if exec() is allowed: 您应该首先尝试查看是否允许exec()

<?php echo exec('echo "exec() is working"');?>

if it's working you should get 如果它正常工作你应该得到

exec() is working

If it works you should try 如果它有效,你应该尝试

exec('/full/path/to/ffmpeg -i /Users/charlieryan/Desktop/MOV01785.MPG websample.mov');

I had the same problem, If you use MAMP, the problem is because mamp's php can't find the correct library, I don't know why!, so.. here's the trick. 我有同样的问题,如果你使用MAMP,问题是因为mamp的php无法找到正确的库,我不知道为什么!所以..这就是诀窍。 - You should use system's php to execute the php which will call to ffmpeg - 你应该使用系统的php来执行将调用ffmpeg的php

In your php code (ex: lib.php | index.php): 在你的PHP代码中(例如:lib.php | index.php):

function callToSysPHP ($videoName) {
    // $cmd = '/path to php/php <your php script> args';
    // In my case 
    $cmd = '/usr/bin/php myffmpeg.php ' . $videoName; 
    shell_exec($cmd);
}

In myffmpeg.php: 在myffmpeg.php中:

 $videoName = $argv[1];
 //$cmd = 'path to your ffmpeg/your ffmpeg command';
 // In my case my ffmpeg cmd looks like
 $cmd =  '/usr/sbin/' . 'ffmpeg -f image2 -framerate 25 -i ./files/pngs/%1d.png -vf scale=480:640 -vcodec libx264 -refs 16 -preset ultrafast ./files/pngs/'. $videoName .'.mp4 2>&1';
 echo '<pre>'; print_r(shell_exec($cmd)); echo '</pre>';

Basically from your mamp php, call a system php to execute a php file wich calls a ffmpeg throught shell_exec(); 基本上从您的mamp php,调用系统php执行一个php文件,它通过shell_exec()调用ffmpeg;

I hope this can help you. 我希望这可以帮到你。

have you ffmpeg installed on windows machine? 你有没有在Windows机器上安装ffmpeg? what happens if you run the same command from command line without php, does it work? 如果你从没有php的命令行运行相同的命令会发生什么,它有效吗? If it doesn't, it hasn't to do anything with PHP. 如果没有,它就不会对PHP做任何事情。

If ' /usr/local/bin/ ' is the directory where you can find the ffmepg executable try this one: 如果' / usr / local / bin / '是你可以找到ffmepg可执行文件的目录,试试这个:

<?php
$cmd = 'PATH="/usr/local/bin/"; ffmpeg -i /your/file/destination/batman.mp4 2>&1';
echo "<pre>".shell_exec($cmd)."</pre>";
?>

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

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