- <?php
- header("content-type:text/html;charset=utf-8");
- date_default_timezone_set('Asia/Shanghai');
- function getCoverImages($fileUrl){
- $result = array();
- if(!empty($fileUrl)){
- $filePath = str_replace("http://img.baidu.cn/", "/data/images/", $fileUrl);
- if(is_file($filePath)){
- $result = execCommandLine($filePath);
- }
- }
- return json_encode($result);
- }
- function execCommandLine($file){
- $result = array();
- $pathParts = pathinfo($file);
- $filename = $pathParts['dirname']."/".$pathParts['filename']."_";
- $times = array(8,15,25);
- foreach ($times as $k => $v) {
- $destFilePath = $filename.$v.".jpg";
- $command = "/usr/bin/ffmpeg -i {$file} -y -f image2 -ss {$v} -vframes 1 -s 640x360 {$destFilePath}";
- exec($command);
- //chmod($filename.$v."jpg",0644);
- $destUrlPath = str_replace("/data/images/", "http://img.baidu.cn/", $destFilePath);
- $selected = $k == 0 ? "1" : "0";//默认将第一张图片作为封面图
- array_push($result,array($destUrlPath,$selected));
- }
- return $result;
- }
- $fileUrl="http://img.baidu.cn/14221916FLVSDT1.mp4"
- getCoverImages($fileUrl);//截取第8、15、25秒为封面图
- ?>