Search code examples
phpffmpegffmpeg-php

Find absolute path to ffmpeg


I installed ffmpeg and ffmpeg-php to my dedicated server and with a small script i am trying to extract an image from specific second.

<?php

$extension = "ffmpeg";
$extension_soname = $extension . "." . PHP_SHLIB_SUFFIX;
$extension_fullname = PHP_EXTENSION_DIR . "/" . $extension_soname;

$timeOffset = "00:00:30";
$videoPath = "sample.mp4";
$extensi = ".jpg";
$folder = "images/";
$finalfilename = $folder . $randomfilename . $extensi;

echo $extension_fullname; //I AM GETING THIS /usr/lib64/php/modules/ffmpeg.so

if (exec("ffmpeg -ss $timeOffset -i $videoPath  -frames:v 1 $finalfilename")){
echo "Done";
}else{
echo "Error";   
}
?>

as you can see in my execution command ther is ffmpeg, but how can i find the absolute path to ffmpeg? Take a look in my screenshot maybe this helps you to tell me..

My last question is what is ffmpeg-php? Do i need it? i already install it.

Thank you

enter image description here


Solution

  • If you're using ffmpeg executable you won't need ffmpeg-php. You might want to use ffmpeg executable only, since together with ffprobe executable you could do anything.

    I didn't get the point of your $extension*'s variables. To know the absolute path where your ffmpeg is installed you could use the which program: which ffmpeg.

    Your exec() call checking is wrong, I'd suggest you to use it this way:

    exec("ffmpeg -v error -y -ss $timeOffset -i $videoPath -vframes 1 $finalfilename 2>&1 >/dev/null", $stderr, $exit_status);
    
    if ($exit_status === 0) {
        print 'Done! :)';
    } else {
        print 'Error... :/';
        // implode("\n", $stderr) will help you figure out what happened...
    }
    

    I've added -v error to let ffmpeg output only error messages and -y to avoid $finalfilename file-existing issue. I've also suppressed all STDOUT and moved only STDERR output to $stderr variable. If your exec() call fail for some reason ($exit_status will be non 0), you'll get what happened on that $stderr array.

    If I'm missing something, please, let me know!