1. <?php
  2. $num_thumbs = 9;
  3. $input_file = 'yourfile.mpg';
  4. $output_file_prefix = 'yourfile';
  5. $output_file_format = 'png';
  6.  
  7. $time_from_end = 0.5;
  8.  
  9. $input_duration = trim ( `ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "{$input_file}"` );
  10. $interval = (float) ( $input_duration / $num_thumbs );
  11.  
  12. for ( $i = 0; $i < $num_thumbs; $i++ ) {
  13. if ( $i === ( $num_thumbs - 1 ) ) { $interval_time = $input_duration - $time_from_end; }
  14. else { $interval_time = $interval * $i; }
  15. $num = str_pad ( $i + 1, 2, '0', STR_PAD_LEFT );
  16. $cmd = "ffmpeg -ss {$interval_time} -i \"{$input_file}\" -frames:v 1 \"{$output_file_prefix}.{$num}.{$output_file_format}\"";
  17. echo "\n\n" . $cmd . "\n\n";
  18. passthru ( $cmd );
  19. }
  20.  
  21. ?>