简体   繁体   English

ffmpeg 命令通过命令行执行,但不通过 PHP 脚本执行

[英]ffmpeg command executes via command line, but not via PHP script

I am working on a simple video upload and compression system and I am currently using the following process.我正在开发一个简单的视频上传和压缩系统,目前我正在使用以下过程。

First Step第一步

I use a multipart/form-data to upload the original video file, which I store in /var/www/site/videos_pre/video.mp4 .我使用multipart/form-data上传原始视频文件,我将其存储在/var/www/site/videos_pre/video.mp4 My public folder is var/www/site/public_html/ .我的公共文件夹是var/www/site/public_html/ I store an entry in my database with the video information.我在我的数据库中存储了一个包含视频信息的条目。

Second step第二步

I have a converter process which is very basic, but does the job (at least in CLI).我有一个非常基本的转换器过程,但可以完成工作(至少在 CLI 中)。

It has the following code:它有以下代码:

public function converter($content_id)
{
    $content = $this->videos_m->get($content_id);

    $id = uniqid();
    $name_mp4 = $content->name_slug.'_'.$id.'.mp4';
    $name_webm = $content->name_slug.'_'.$id.'.webm';

    $command_mp4 = 'ffmpeg -i ../videos_pre/'.$content->original_file.' -b:v 1500k -bufsize 1500k ./videos/'.$name_mp4;
    system($command_mp4);

    $command_webm = 'ffmpeg -i ./videos/'.$name_mp4.' -c:v vp9 -c:a libvorbis ./videos/'.$name_webm;
    system($command_webm);

    $update_video = new stdClass();
    $update_video->archivo_mp4 = $name_mp4;
    $update_video->archivo_webm = $name_webm;

    $this->db->where('content_id', $content_id);
    $this->db->update('Videos', $update_video);
}

Third step - where the problem occurs第三步——出现问题的地方

I have tested this on Windows 10 and Ubuntu 18.04.我已经在 Windows 10 和 Ubuntu 18.04 上对此进行了测试。 The code works on Windows 10 in both php and cli.该代码在 php 和 cli 中都适用于 Windows 10。 The code on Ubuntu only works with cli. Ubuntu 上的代码仅适用于 cli。

The resulting commands are something like this:结果命令是这样的:

// First command to reduce the bitrate of the mp4
ffmpeg -i /var/www/site/videos_pre/video.mp4 -b:v 1500k -bufsize 1500k /var/www/site/public_html/videos/video_5e757d3e0d762.mp4

// Second command to convert the mp4 to a webm to get both types
ffmpeg -i /var/www/site/public_html/videos/video_5e757d3e0d762.mp4 -c:v vp9 -c:a libvorbis /var/www/site/public_html/videos/video_5e757d3e0d762.webm

If I execute those commands they work perfectly.如果我执行这些命令,它们就会完美运行。 If I run the php script, be it in the browser or via CLI, literally nothing happens.如果我运行 php 脚本,无论是在浏览器中还是通过 CLI,实际上都没有任何反应。 No error messages nothing.没有错误信息什么的。

I am not sure if it's a permission issue, if there's something specific for php to run this, or some module I've not activated.我不确定这是否是一个权限问题,是否有特定的 php 来运行它,或者我没有激活某个模块。 I have enough execution time, I have it at 600 seconds, but as I said it doesn't even take time, it just does nothing.我有足够的执行时间,我有 600 秒,但正如我所说,它甚至不需要时间,它什么也不做。

I can even echo the commands and they appear.我什至可以回显命令,然后它们就会出现。 So, basically the problem is I need to be able to run those commands from PHP.所以,基本上问题是我需要能够从 PHP 运行这些命令。 I did it on Windows, but Ubuntu 18.04 won't let me.我是在 Windows 上完成的,但 Ubuntu 18.04 不允许我这样做。 Both OSs have ffmpeg recently installed and I've been able to convert on both of them.两个操作系统最近都安装了ffmpeg ,我已经能够在这两个操作系统上进行转换。

I tried changing paths from absolute to relative, no difference at all.我尝试将路径从绝对路径更改为相对路径,完全没有区别。

So, I managed to solve it, and it turns out it was a permission problem.所以,我设法解决了它,事实证明这是一个权限问题。

I had my /var/www/site folder with permissions like this: myuser:www-data .我的/var/www/site文件夹具有如下权限: myuser:www-data After checking this answer on a similar issue, I changed the folder permission to www-data:root and it worked instantly.在类似问题上检查此答案后,我将文件夹权限更改为www-data:root并立即生效。

I hope that permission change doesn't affect the rest of things, but for now everything's working fine.我希望权限更改不会影响其他事情,但现在一切正常。

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

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