-2

我正在尝试使用 Symfony Process Component 执行 ffmpeg 命令,但未处理命令。我究竟做错了什么?我得到错误

命令“'ffmpeg -i [...........]'失败。退出代码:127(找不到命令)”

<?php 
$info = pathinfo($file);
$dir = "{$info['dirname']}/{$info['filename']}";
File::makeDirectory($dir, 0755, true)
$process = new Process(["ffmpeg -i {$info['basename']} -codec copy -map 0 -f segment -segment_list {$dir}/playlist.m3u8 -segment_list_flags +live -segment_time 10 {$dir}/{$info['filename']}_%02d.ts"]);
$process->setWorkingDirectory($info['dirname']);
$process->start();
if (!$process->isSuccessful()) {
    throw new ProcessFailedException($process);
}
echo $process->getOutput();
?>
4

1 回答 1

4

您必须将每个参数放在数组的单独元素中,例如:

$process = new Process([
    "ffmpeg",
    "-i",
    "{$info['basename']}",
    "-codec",
    "copy",
    "-map",
    "0",
    "-f",
    "segment",
    "-segment_list",
    "{$dir}/playlist.m3u8",
    "-segment_list_flags",
    "+live",
    "-segment_time",
    "10",
    "{$dir}/{$info['filename']}_%02d.ts",
]);

我认为你应该:

  • 使用$process->run()而不是$process->start()
  • 或者更详细地阅读如何异步运行进程$process->start()
于 2020-12-14T14:44:41.560 回答