Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- # usage : http://technoslab.blogspot.com
- #
- # tecShot::genThumb('e:\video\b.avi',9,'e:\video\ffmpeg.exe');
- #
- # Class
- final class tecShot{
- private function error($msg){
- exit("<b>tecShot</b>: $msg");
- }
- public function genThumb($video_path,$ss_no,$ffmpeg_path="/usr/local/bin/ffmpeg"){
- if(!is_file($video_path)){
- $this->error("'$video_path' contains no such video.");
- }
- if($ss_no<=0){
- $this->error("'$ss_no' is less that or equal to 0.");
- }
- if($ss_no>50){
- $this->error("You can't generate more than 50 thumbs at a time.");
- }
- if(!is_dir("./thumb")){
- $this->error("Create a folder with proper permissions and rename it to '<b>thumb</b>'.");
- }
- ob_start();
- passthru("{$ffmpeg_path} -i \"$video_path\" 2>&1");
- $duration = ob_get_contents();
- ob_end_clean();
- $search='@Duration: ([^:]*):([^:]*):([^(:|.)]*)(.[^,]*|)@is';
- preg_match($search, $duration, $matches);
- $hr=$matches[1];
- $min=$matches[2];
- $sec=$matches[3];
- $tot = $hr * 3600 + $min * 60 + $sec;
- $r=round($ss_no/$tot,2);
- $name = "thumb/".basename($video_path)."_";
- ob_start();
- $exec="{$ffmpeg_path} -i \"{$video_path}\" -r $r -vframes $ss -an -y \"$name%d.png\" 2>&1";
- passthru($exec);
- $duration = ob_get_contents();
- ob_end_clean();
- for($i=1;$i<=$ss_no;$i++){
- $newName = $name.$i.".png";
- echo " <img src='$newName' style='max-width:300px' />";
- if($i%3==0)echo"<br />";
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment