Symfony 进程 - 找不到命令
Symfony Process - Command not found
我正在尝试使用 Symfony 进程组件执行 ffmpeg 命令,但命令未被处理。我究竟做错了什么?
我收到错误
The command "'ffmpeg -i [...........]' failed. Exit Code: 127(Command
not found)"
<?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();
?>
您必须将每个参数放在数组的单独元素中,例如:
$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()
更详细地阅读 how to run a process asynchronously
我正在尝试使用 Symfony 进程组件执行 ffmpeg 命令,但命令未被处理。我究竟做错了什么? 我收到错误
The command "'ffmpeg -i [...........]' failed. Exit Code: 127(Command not found)"
<?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();
?>
您必须将每个参数放在数组的单独元素中,例如:
$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()
更详细地阅读 how to run a process asynchronously