5

I have read this but didnt help too much.

I have a folder called videos and another folder called thumbnails. I have many mp4 videos in video folder and want to catch thumbnails at 4th second to the thumbnails folder using ffmpeg and php.

  1. I am using Wamp server 2.2 on windows whit php 5.3.8 and Apache 2.2.21
  2. I downloaded ffmpeg from FFmpeg Windows Builds section of ffmpeg download page and the static 32 build from this link.
  3. I extracted the 7z file to my website root
    here is my php code:

    $ffmpeg = "includes/ffmpeg/bin/ffmpeg";
    foreach(glob('files/videos/*.mp4') as $pathname){
      $filename = substr($pathname,13,strripos($pathname,'.mp4')-13);
      $thumbnail = 'files/thumbnails/'.$filename.'.jpg';
      exec("ffmpeg -i $pathname -an -y -f mjpeg -ss 00:00:04 -vframes 1 $thumbnail");
    }
    

but nothing happens and the thumbnails folder is always empty!
- How can I find out is ffmpeg installed on my server or not?
- How can I get my script to work?
Please help

Community
  • 1
  • 1
  • Can you check permissions and path is defined properly? – जलजनक Feb 02 '13 at 13:24
  • @DoSparKot what permissions? I am using wamp server and I have windows folders. I have everyone full access to videos and thumbnails. but nothing changed –  Feb 02 '13 at 13:57

3 Answers3

4

try this:

$ffmpeg = "c:/wamp/www/includes/ffmpeg/bin/ffmpeg";
$videos = "c:/wamp/www/files/videos/*.mp4";
$ouput_path = "c:/wamp/www/files/thumbnails/";
foreach(glob($videos) as $v_file){
    $fname = basename($v_file, ".mp4");
    $thmb = $ouput_path.$fname.'_tn.jpg';
    $cmd = "$ffmpeg -i $v_file -an -y -f mjpeg -ss 00:00:04 -vframes 1 $thmb";
    $stat = system ($cmd);
}
1

Try with absolute paths in commands instead of depending on PATH ENV variable: Both exec() and system() works. Resolve the path definitions.

/* Using Absolute paths */
$ffmpeg = "c:/wamp/www/includes/ffmpeg/bin/ffmpeg";
$videos = "c:/wamp/www/files/videos/*.mp4";
$ouput_path = "c:/wamp/www/files/thumbnails/";

foreach(glob($videos) as $video_file){

    $filename = basename($video_file, ".mp4");
    $thumbnail = $ouput_path.$filename.'_tn.jpg';
    $command = "$ffmpeg -i $video_file -an -y -f mjpeg -ss 00:00:04 -vframes 1 $thumbnail";

    $status = system ($command);
/*or
    $status = exec($command);

    if ($status === false) {
        var_dump("ERROR: Conversion Failed!!!!");
    } else
        var_dump($status);
*/
}
जलजनक
  • 3,072
  • 2
  • 24
  • 30
0

I´m not allowed to add a comment, so here (as a Post) is what I found out while dealing with this: The white space in the file name prevents ffmpeg from finding the right file. So one way is to change the file name.

  • The `ffmpeg` cli tool handles spaces just fine with proper quoting or escaping: `ffmpeg -i input "output 1.mp4" 'output 2.mp4' output\ 3.mp4` – llogan Nov 27 '18 at 22:10
  • Thanks, I´ll try that – user2217108 Nov 27 '18 at 22:13
  • I'm not a PHP user (the question is tagged [tag:php]), so my three examples may or may not work for PHP. – llogan Nov 27 '18 at 22:16
  • Oh, it worked just fine, I used the "output 1.mp4" escaping the quotes, in the string, like this: - \"output 1.mp4\" - and voila!!! :) thanks for the tip, I believe this is the reason that it wasn´t working for Pedar Jepeto. – user2217108 Nov 30 '18 at 06:15