title: ffmpeg-php to create thumbnail of video
body: <p>I am trying to use this script to create thumbnail of a video using <strong>ffmpeg</strong>. At first I used <code>phpinfo();</code> and I found ffmpeg is installed on my server.</p>
  
  <p>Then I copied <strong>ffmpeg-php</strong> onto my server and run the test file</p>
  
  <p>I got to know that many function are working on my server</p>
  
  <p>I got output like this</p>
  
  <p><strong>Output:-</strong></p>
  
  <pre><code>Functions available in /usr/lib/php/extensions/no-debug-non-zts-20060613/ffmpeg.so extension:
  
  Methods available in class ffmpeg_movie:
  __construct
  getduration
  getframecount
  getframerate
  getfilename
  getcomment
  gettitle
  getauthor
  getartist
  getcopyright
  getalbum
  getgenre
  getyear
  gettracknumber
  getframewidth
  getframeheight
  getframenumber
  getpixelformat
  getbitrate
  hasaudio
  hasvideo
  getnextkeyframe
  getframe
  getvideocodec
  getaudiocodec
  getvideostreamid
  getaudiostreamid
  getaudiochannels
  getaudiosamplerate
  getaudiobitrate
  getvideobitrate
  getpixelaspectratio
  getpixelaspectratio
  getvideobitrate
  getaudiobitrate
  getaudiosamplerate
  getaudiochannels
  getaudiostreamid
  getvideostreamid
  getaudiocodec
  getvideocodec
  getframe
  getnextkeyframe
  hasvideo
  hasaudio
  getbitrate
  getpixelformat
  getframenumber
  getframeheight
  getframewidth
  gettracknumber
  getyear
  getgenre
  getalbum
  getcopyright
  getartist
  getauthor
  gettitle
  getcomment
  getfilename
  getframerate
  getframecount
  getduration
  __construct
  </code></pre>
  
  <p>I wrote this code and tried any possible path to assign <code>$ffmpeg;</code></p>
  
  <pre><code>&lt;?php
  
      $thumb_stdout;
      $retval=0;
      $ffmpeg = '/home/lib/ffmpeg';
  
  // change "demo.mpg" to your mpg file name!
  $video  = dirname(__FILE__) . 'demo.mpg';
  
  // change "demo.jpg" to whichever name you like or don't
  // for this example, the name of the output jpg file does not matter
  $image  = dirname(__FILE__) . 'demo.jpg';
  
  $second = 1;
  
  $cmd = "$ffmpeg -i $video 2&gt;&amp;1";
  if (preg_match('/Duration: ((\d+):(\d+):(\d+))/s', '$cmd', $time)) {
      $total = ($time[2] * 3600) + ($time[3] * 60) + $time[4];
      $second = rand(1, ($total - 1));
  }
  
  //$cmd = "$ffmpeg -i $video -deinterlace -an -ss $second -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg $image 2&gt;&amp;1";
  $cmd = "$ffmpeg -i $video -r 1 -ss 00:00:05 -t 00:00:01 -s 250x250 -f image2 $image";
  echo $cmd;
  exec($cmd);
  //$return = '$cmd';
  
  echo '&lt;br&gt;done!';
  ?&gt;
  </code></pre>