PHP exec() does not run Ffmpeg

Asked

Viewed 171 times

0

The following code works at the prompt but not in php, why?

$ffmpeg = 'C:/ffmpeg/bin/ffmpeg.exe';
$video = 'C:/absolute-path-para-o-video';
$output = 'C:/minha-pasta/thumbnail.jpg'; 
$cmd = '$ffmpeg -ss 3 -i $video -vf "select=gt(scene\,0.4)" -frames:v 5 -vsync vfr -vf fps=fps=1/600 $output &';

exec($cmd);

Works perfectly in Windows Prompt, but in PHP does not run and gets this error in Apache

'$ffmpeg' is not recognized as an Internal or External command, operable program or batch file.

  • 1

    Use double quotes on $cmd

  • @Augusto and no select=gt... I leave with apostrofe or leave without ?

1 answer

3


This is an error message windows, saying he couldn’t execute $ffmpeg.

I noticed that you put the full path to the executable on the first line, so I guess you just forgot to concatenate the variable with the rest of the command.

In fact, the variables $video and $output are also going as literals to the command

It is also important to leave the variable $video in double quotes, not to be wrong if there are spaces in the file path.

$cmd = $ffmpeg. ' -ss 3 -i "' . $video . '" -vf "select=gt(scene\,0.4)" -frames:v 5 -vsync vfr -vf fps=fps=1/600 ' . $output . ' &';
  • Thank you, now worked perfectly well and without errors, in virtually all tutorials I found none specified that the variables had to be concatenated

Browser other questions tagged

You are not signed in. Login or sign up in order to post.