【发布时间】:2010-11-09 23:07:52
【问题描述】:
我正在尝试使用 PHP 在后台执行命令,以便 Web 应用程序可以继续加载,但到目前为止没有运气。
该命令用于直播应用,因此涉及以下内容:
<stream pre-process> | ffmpeg <options> | <stream segmenter>
我可以将上述内容粘贴在脚本中,并在后台使用 & 在 bash 中正常执行,但这在 PHP 中不起作用。我之前也尝试过使用 nohup 和“nohup & echo $!”,但没有成功。
我还将所有 stderr 都通过管道传输到 /dev/null,并且我可以在 apache 日志中验证当我执行命令时没有生成输出(但它正在执行)。
下面的一些示例代码..我在这段代码之后的内容在完成之前不会执行,这需要很长时间。
function streamVid ($mid, $width, $height, $br) {
$cdir = "./temp";
$zmstrm = "zmstreamer -m ".$mid." 2> /dev/null";
$seg = "segmenter - 3 ".$cdir."/sample_".$mid." ".$cdir."/stream_".$mid.".m3u8 ./ 2>/dev/null";
$ffparms = "-f mpegts -analyzeduration 0 -acodec copy -s ".$width."x".$height." -vcodec libx264 -b ".$br." -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -subq 5 -trellis 1 -refs 1 -coder 0 -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 200k -maxrate ".$br." -bufsize ".$br." -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 320:240 -g 30 -analyzeduration 0 -async 2 - 2> /dev/null";
$url = $zmstrm . " | ffmpeg -t 10 -analyzeduration 0 -i - ". $ffparms . " | " . $seg;
shell_exec("nohup ". $url." & echo $!");
ob_flush();
flush();
}
【问题讨论】:
标签: php ffmpeg video-streaming