Guest User

Untitled

a guest
Feb 17th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. function _get_video_attributes($video, $ffmpeg) {
  2.  
  3. $command = $ffmpeg . ' -i ' . $video . ' -vstats 2>&1';
  4. $output = shell_exec($command);
  5.  
  6. $regex_sizes = "/Video: ([^,]*), ([^,]*), ([0-9]{1,4})x([0-9]{1,4}), ([^,]*), ([0-9]{1,4})/"; // or : $regex_sizes = "/Video: ([^rn]*), ([^,]*), ([0-9]{1,4})x([0-9]{1,4})/"; (code from @1owk3y)
  7. if (preg_match($regex_sizes, $output, $regs)) {
  8. $codec = $regs [1] ? $regs [1] : null;
  9. $width = $regs [3] ? $regs [3] : null;
  10. $height = $regs [4] ? $regs [4] : null;
  11. $fps = $regs [6] ? $regs [6] : null;
  12. }
  13.  
  14. $regex_duration = "/Duration: ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}).([0-9]{1,2})/";
  15. if (preg_match($regex_duration, $output, $regs)) {
  16. $hours = $regs [1] ? $regs [1] : null;
  17. $mins = $regs [2] ? $regs [2] : null;
  18. $secs = $regs [3] ? $regs [3] : null;
  19. $ms = $regs [4] ? $regs [4] : null;
  20. }
  21.  
  22. return array('codec' => $codec,
  23. 'width' => $width,
  24. 'height' => $height,
  25. 'hours' => $hours,
  26. 'mins' => $mins,
  27. 'secs' => $secs,
  28. 'ms' => $ms,
  29. 'fps' => $fps,
  30. );
  31. }
  32.  
  33. if($duration < 10){
  34. $interval = floor($duration / 2);
  35. $image = "thumb/".$filenopath."_thumb_".$num.".jpg";
  36. shell_exec($ffmpeg." -ss ".$interval." -i ".$upfile." -vf select='eq(pict_type,I)' -vframes 1 -vf scale=-1:240 ".$thumb."00".$i.".jpg");
  37. rename($image,"thumb/".$image);
  38. }else{
  39. for ($i = 1; $i <= 6; $i++) {
  40. $interval = floor(($i - 0.5) * $duration / $i);
  41. $log = $ffmpeg." -ss ".$interval." -i ".$upfile." -vf select='eq(pict_type,I)' -vframes 1 -vf scale=-1:240 ".$thumb."00".$i.".jpg".PHP_EOL;
  42. //file_put_contents('./log'.date("j.n.Y").'.txt', $log, FILE_APPEND);
  43. shell_exec($ffmpeg." -ss ".$interval." -i ".$upfile." -vf select='eq(pict_type,I)' -vframes 1 -vf scale=-1:240 ".$thumb."00".$i.".jpg");
  44. }
Add Comment
Please, Sign In to add comment