如何获取视频封面截图


  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. ?>  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM