Php 在后台返回FFMPEG

Php 在后台返回FFMPEG,php,ffmpeg,proc-open,Php,Ffmpeg,Proc Open,我正在编写一个代码,通过FFMPEG 我有这个密码: function FFMPEG($videocode, $dirvideo) { $ffmpeg = '"D:\FFMPEG\bin\ffmpeg.exe"' . " -hide_banner -loglevel verbose -n -i https://linkplaylist/{$videocode}.m3u8 -map 0:1 -map 0:2 -acodec copy -bsf:a aac_adtstoasc -vcode

我正在编写一个代码,通过
FFMPEG

我有这个密码:

function FFMPEG($videocode, $dirvideo) {

    $ffmpeg = '"D:\FFMPEG\bin\ffmpeg.exe"' . " -hide_banner -loglevel verbose -n -i https://linkplaylist/{$videocode}.m3u8 -map 0:1 -map 0:2 -acodec copy -bsf:a aac_adtstoasc -vcodec copy {$dirvideo} 1> log.txt  2>&1";

    exec($ffmpeg, $output, $var);

    return $var;
}

$code = FFMPEG('football', 'football.mp4');

if($code){
    {ERROR CODE}; 
    }else{

    {SUCCESS CODE}
}   
$descriptorspec = array(
   0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
   1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
   2 => array("file", "error-output.txt", "a") // stderr is a file to write to
);

function FFMPEG($videocode, $dirvideo) {
$cmd = 'start /B D:\FFMPEG\bin\ffmpeg.exe  -y -i "https://linkplaylist/{$videocode}.m3u8" -map p:0 -acodec copy -bsf:a aac_adtstoasc -vcodec copy {$dirvideo}';
proc_close(proc_open ($cmd
,$descriptorspec, $foo));
}
初始问题 这很有效。我可以下载视频,并知道它是完全下载或有一些错误

问题在于,该代码“挂起”页面正在加载的exec()中的脚本,直到finalize exec()和超时错误(共享服务器)的脚本为止。此外,对于页面加载的访问者来说,该代码在视觉上是陌生的

初始问题的解决 经过研究,我认为解决方案是将代码执行置于后台,因此我发现以下代码:

function FFMPEG($videocode, $dirvideo) {

    $ffmpeg = '"D:\FFMPEG\bin\ffmpeg.exe"' . " -hide_banner -loglevel verbose -n -i https://linkplaylist/{$videocode}.m3u8 -map 0:1 -map 0:2 -acodec copy -bsf:a aac_adtstoasc -vcodec copy {$dirvideo} 1> log.txt  2>&1";

    exec($ffmpeg, $output, $var);

    return $var;
}

$code = FFMPEG('football', 'football.mp4');

if($code){
    {ERROR CODE}; 
    }else{

    {SUCCESS CODE}
}   
$descriptorspec = array(
   0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
   1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
   2 => array("file", "error-output.txt", "a") // stderr is a file to write to
);

function FFMPEG($videocode, $dirvideo) {
$cmd = 'start /B D:\FFMPEG\bin\ffmpeg.exe  -y -i "https://linkplaylist/{$videocode}.m3u8" -map p:0 -acodec copy -bsf:a aac_adtstoasc -vcodec copy {$dirvideo}';
proc_close(proc_open ($cmd
,$descriptorspec, $foo));
}
最后是我目前的问题 这对于加载和超时问题很有效,但我无法从下载成功完成时获得返回

1°proc_open这是解决我最初问题的最佳方案吗

2°当ffmpeg成功完成运行且脚本继续流动时,我如何从中获得回报

额外信息
我正试图构建一个在windows(xampp)上运行的解决方案,但我的最终服务器是linux。

我也面临同样的挑战,希望有人能完成我的贡献

这只是我不知道如何为Windows完成的部分答案。根据ffmpeg,诀窍显然在管道中,但解决方案适用于Unix:

还要注意的是标准输入(stdin)。 命令行ffmpeg工具被设计为一个交互式实用程序 接受用户输入(通常来自键盘)并报告错误日志 在用户的当前屏幕/终端上。当我们在 背景,我们想告诉ffmpeg,不应接受任何输入 (也没有等待)从标准输入。我们可以使用I/O将其告知ffmpeg “再次重定向” 我尝试使用
-nostdin
,但没有效果