寶塔終端安裝ffmpeg
wget http://download.bt.cn/install/ext/ffmpeg.sh && sh ffmpeg.sh
檢查是否安裝成功
ffmpeg -version
php代碼
public function getVideoInfo($file) {
define('FFMPEG_PATH', '/usr/local/bin/ffmpeg -i "%s" 2>&1');//安裝地址
$command = sprintf(FFMPEG_PATH,$file);
ob_start();
passthru($command);
$info = ob_get_contents();
ob_end_clean();
//var_dump($info);
$data =array();
if (preg_match("/Duration: (.*?), start: (.*?), bitrate: (\d*) kb\/s/",$info,$match)) {
$data['duration'] =$match[1];//播放時間
$arr_duration =explode(':',$match[1]);
$data['seconds'] =$arr_duration[0] * 3600 +$arr_duration[1] * 60 +$arr_duration[2];//轉換播放時間為秒數
$data['start'] =$match[2];//開始時間
$data['bitrate'] =$match[3];//碼率(kb)
}
if (preg_match("/Video: (.*?), (.*?), (.*?)[,\s]/",$info,$match)) {
$data['vcodec'] =$match[1];//視頻編碼格式
$data['vformat'] =$match[2];//視頻格式
$data['resolution'] =$match[3];//視頻解析度
$arr_resolution =explode('x',$match[3]);
$data['width'] =$arr_resolution[0];//寬
$data['height'] =$arr_resolution[1];//高
}
if (preg_match("/Audio: (\w*), (\d*) Hz/",$info,$match)) {
$data['acodec'] =$match[1];//音頻編碼
$data['asamplerate'] =$match[2];//音頻采樣頻率
}
if (isset($data['seconds']) && isset($data['start'])) {
$data['play_time'] =$data['seconds'] +$data['start'];//實際播放時間
}
$data['size'] =filesize($file);//檔案大小
return $data;
}
tp5框架呼叫
$this->getVideoInfo("視頻檔案地址");
寶塔解除passthru函式

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/376053.html
標籤:其他
上一篇:深度學習目標檢測---資料集的格式轉換及訓練集、驗證集的劃分
下一篇:01-Docker安裝及基本操作
