2

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

Irene T.
  • 1,393
  • 2
  • 20
  • 40

1 Answers1

3

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!

Paulo Freitas
  • 13,194
  • 14
  • 74
  • 96
  • I got will paste in seperate edits what i got my friend: /usr/lib64/php/modules/ffmpeg.soFFmpeg version 0.6, Copyright (c) 2000-2010 the FFmpeg developers built on Nov 7 2013 15:35:47 with gcc 4.4.7 20120313 (Red Hat 4.4.7-3) configuration: libavutil 50.15. 1 / 50.15. 1 libavcodec 52.72. 2 / 52.72. 2 libavformat 52.64. 2 / 52.64. 2 libavdevice 52. 2. 0 / 52. 2. 0 libswscale 0.11. 0 / 0.11. 0 sample.mp4: could not seek to position 208.044 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'sample.mp4': Metadata: major_brand : dash minor_version : 0 compatible_brands: iso6avc1mp41 Duration: 00:03:18.03 – Irene T. Nov 10 '13 at 13:34
  • AND: start: 178.044367, bitrate: 26 kb/s Stream #0.0(und): Video: h264, yuv420p, 640x360, 29.97 tbr, 90k tbn, 59.94 tbc Unrecognized option 'frames:v' – Irene T. Nov 10 '13 at 13:35
  • 1
    So you're using an unrecognized option `-frames:v`... I think you want to use `-vframes` option instead. Updated my answer to use that one. :) – Paulo Freitas Nov 10 '13 at 13:38
  • Yes was an unrecongized command but i am still cannot get the thumb... I got also sample.mp4: could not seek to position 238.044 – Irene T. Nov 10 '13 at 13:57
  • 1
    Ermmm, didn't know why you got `could not seek to position 238.044`, seems to be specific to your `sample.mp4` file... Note that your `$finalfilename` is using an unitialized `$randomfilename` variable, so in the end it's getting `images/.jpg` value, which in a Unix system mean a hidden file. I think if you initialize `$randomfilename` it'll work as expected, seems like that you can ignore that seek error... If not, it's specific to the file, since the command is right for your need. :) – Paulo Freitas Nov 10 '13 at 14:12