因为写了一个相册系统,所以发现这个问题,这年头谁还只是傻傻的照相啊,肯定是外带拍N多的视频啦。好吧,代码再改改,添加上传视频的功能。
只是说起来简单,做起来啰嗦。这视频不如照片信息的格式统一,不过还好,基本上应付市面上机器拍摄的视频信息提取函数也大概写出来了。
注意:这是基于FFMpeg的,所以不管是Windows还是Linux都是安装FFMpeg才行。
function getVideoInfo($path){ $fileNameArray = explode('.',$path); $ext = strtolower($fileNameArray[count($fileNameArray)-1]); ob_start(); passthru(sprintf('ffmpeg -i "%s" 2>&1',$path)); $info = ob_get_contents(); ob_end_clean(); $data = []; switch ($ext) { case 'mov': if(preg_match("/com.apple.quicktime.make:(.*)/",$info,$res)) $data['Make'] = $res[1]; if(preg_match("/creation_time :(.*)/",$info,$res)){ $date = strtotime(str_replace('/',' ',trim($res[1]))); $data['date'] = date('Y-m-d H:i:s',$date); } // if(preg_match("/com.apple.quicktime.creationdate:(.*)/",$info,$res)) $data['Date'] = date('Y-m-d H:i:s',strtotime($res[1])); if(preg_match("/com.apple.quicktime.model:(.*)/",$info,$res)) $data['Model'] = $res[1]; if(preg_match("/com.apple.quicktime.location.ISO6709:(.*)/",$info,$res)){ $local = explode('+',$res[1]); $data['latitude'] = $local[2]; $data['longitude'] = $local[1]; } if (preg_match("/Duration: (.*?), start: (.*?), bitrate: (\d*) kb\/s/", $info, $res)){ $data['duration'] = $res[1]; $data['bitrate'] = $res[3].'kb/s'; } break; case 'avi': if(preg_match("/encoder :(.*)/",$info,$res)){ $data['make'] = explode(' ',trim($res[1]))[0]; $data['model'] = explode(' ',trim($res[1]))[1]; } if(preg_match("/creation_time :(.*)/",$info,$res)){ $date = strtotime(str_replace('/',' ',trim($res[1]))); $data['date'] = date('Y-m-d H:i:s',$date); } if (preg_match("/Duration: (.*?), start: (.*?), bitrate: (\d*) kb\/s/", $info, $res)){ $data['duration'] = $res[1]; $data['bitrate'] = $res[3].'kb/s'; } break; case 'mp4': if(preg_match("/creation_time :(.*)/",$info,$res)){ $date = strtotime(str_replace('/',' ',trim($res[1]))); $data['date'] = date('Y-m-d H:i:s',$date); } if(preg_match("/location :(.*)/",$info,$res)){ $local = explode('+',$res[1]); $data['latitude'] = $local[2]; $data['longitude'] = $local[1]; } if (preg_match("/Duration: (.*?), start: (.*?), bitrate: (\d*) kb\/s/", $info, $res)){ $data['duration'] = $res[1]; $data['bitrate'] = $res[3].'kb/s'; } case '3gp': if(preg_match("/creation_time :(.*)/",$info,$res)){ $date = strtotime(str_replace('/',' ',trim($res[1]))); $data['date'] = date('Y-m-d H:i:s',$date); } if(preg_match("/location :(.*)/",$info,$res)){ $local = explode('+',$res[1]); $data['latitude'] = $local[2]; $data['longitude'] = $local[1]; } if (preg_match("/Duration: (.*?), start: (.*?), bitrate: (\d*) kb\/s/", $info, $res)){ $data['duration'] = $res[1]; $data['bitrate'] = $res[3].'kb/s'; } break; default: if(preg_match("/creation_time :(.*)/",$info,$res)){ $date = strtotime(str_replace('/',' ',trim($res[1]))); $data['date'] = date('Y-m-d H:i:s',$date); } if(preg_match("/location :(.*)/",$info,$res)){ $local = explode('+',$res[1]); $data['latitude'] = $local[2]; $data['longitude'] = $local[1]; } if (preg_match("/Duration: (.*?), start: (.*?), bitrate: (\d*) kb\/s/", $info, $res)){ $data['duration'] = $res[1]; $data['bitrate'] = $res[3].'kb/s'; } break; } return $data;}