如何获取视频封面截图

  1. <?php  
  2. header("content-type:text/html;charset=utf-8");  
  3. date_default_timezone_set('Asia/Shanghai');  
  4. function getCoverImages($fileUrl){  
  5. $result = array();  
  6. if(!empty($fileUrl)){  
  7. $filePath = str_replace("http://img.baidu.cn/", "/data/images/", $fileUrl);  
  8. if(is_file($filePath)){  
  9. $result = execCommandLine($filePath);  
  10. }  
  11. }  
  12. return json_encode($result);  
  13. }  
  14. function execCommandLine($file){  
  15. $result = array();  
  16. $pathParts = pathinfo($file);  
  17. $filename = $pathParts['dirname']."/".$pathParts['filename']."_";  
  18. $times = array(8,15,25);  
  19. foreach ($times as $k => $v) {  
  20. $destFilePath = $filename.$v.".jpg";  
  21. $command = "/usr/bin/ffmpeg -i {$file} -y -f image2 -ss {$v} -vframes 1 -s 640x360 {$destFilePath}";  
  22. exec($command);  
  23. //chmod($filename.$v."jpg",0644);  
  24. $destUrlPath = str_replace("/data/images/", "http://img.baidu.cn/", $destFilePath);  
  25. $selected = $k == 0 ? "1" : "0";//默认将第一张图片作为封面图  
  26. array_push($result,array($destUrlPath,$selected));  
  27. }  
  28. return $result;  
  29. }  
  30. $fileUrl="http://img.baidu.cn/14221916FLVSDT1.mp4"  
  31. getCoverImages($fileUrl);//截取第81525秒为封面图  
  32. ?>  
posted @ 2017-11-30 15:35  傻糊糊  阅读(5524)  评论(0编辑  收藏  举报