Search code examples
phpsymfonysymfony-process

Symfony Process - Command not found


I'm trying to execute ffmpeg commands using Symfony Process Component but command is not being processed. What am I doing wrong? I get the error

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();
?>

Solution

  • You have to put each argument in a separate element of the array, for example:

    $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",
    ]);
    

    And I think you should either: