php使用FFmpeg接口獲取視頻的播放時(shí)長(zhǎng)、碼率、縮略圖以及創(chuàng)建時(shí)間
FFmpeg是一個(gè)視頻插件,我們可以利用調(diào)用FFmpeg接口來(lái)獲取視頻的相關(guān)信息,包括視頻的播放時(shí)長(zhǎng),視頻的碼率,視頻的縮略圖以及視頻創(chuàng)建時(shí)間,本文章向大家介紹php如何使用FFmpeg接口獲取視頻信息,需要的朋友可以參考一下。
FFmpeg獲得視頻文件的縮略圖:
function getVideoCover($file,$time,$name) { if(empty($time))$time = '1';//默認(rèn)截取第一秒第一幀 $strlen = strlen($file); // $videoCover = substr($file,0,$strlen-4); // $videoCoverName = $videoCover.'.jpg';//縮略圖命名 //exec("ffmpeg -i ".$file." -y -f mjpeg -ss ".$time." -t 0.001 -s 320x240 ".$name."",$out,$status); $str = "ffmpeg -i ".$file." -y -f mjpeg -ss 3 -t ".$time." -s 320x240 ".$name; //echo $str."</br>"; $result = system($str); }
Fmpeg讀取視頻播放時(shí)長(zhǎng)和碼率
<?php define('FFMPEG_PATH', '/usr/local/ffmpeg2/bin/ffmpeg -i "%s" 2>&1'); function getVideoInfo($file) { $command = sprintf(FFMPEG_PATH, $file); ob_start(); passthru($command); $info = ob_get_contents(); ob_end_clean(); $data = array(); if (preg_match("/Duration: (.*?), start: (.*?), bitrate: (\d*) kb\/s/", $info, $match)) { $data['duration'] = $match[1]; //播放時(shí)間 $arr_duration = explode(':', $match[1]); $data['seconds'] = $arr_duration[0] * 3600 + $arr_duration[1] * 60 + $arr_duration[2]; //轉(zhuǎn)換播放時(shí)間為秒數(shù) $data['start'] = $match[2]; //開(kāi)始時(shí)間 $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']; //實(shí)際播放時(shí)間 } $data['size'] = filesize($file); //文件大小 return $data; } //用法 $video_info = getVideoInfo('video.mp4'); print_r($video_info); ?>
Fmpeg獲得視頻文件的總長(zhǎng)度時(shí)間和創(chuàng)建時(shí)間
function getTime($file){ $vtime = exec("ffmpeg -i ".$file." 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/,//");//總長(zhǎng)度 $ctime = date("Y-m-d H:i:s",filectime($file));//創(chuàng)建時(shí)間 //$duration = explode(":",$time); // $duration_in_seconds = $duration[0]*3600 + $duration[1]*60+ round($duration[2]);//轉(zhuǎn)化為秒 return array('vtime'=>$vtime, 'ctime'=>$ctime ); }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- PHP中使用FFMPEG獲取視頻縮略圖和視頻總時(shí)長(zhǎng)實(shí)例
- PHP使用FFmpeg獲取視頻播放總時(shí)長(zhǎng)與碼率等信息
- 利用Ffmpeg獲得flv視頻縮略圖和視頻時(shí)間的代碼
- php 調(diào)用ffmpeg獲取視頻信息的簡(jiǎn)單實(shí)現(xiàn)
- php使用ffmpeg獲取視頻信息并截圖的實(shí)現(xiàn)方法
- PHP基于ffmpeg實(shí)現(xiàn)轉(zhuǎn)換視頻,截圖及生成縮略圖的方法
- php利用ffmpeg提取視頻中音頻與視頻畫(huà)面的方法詳解
- php使用ffmpeg向視頻中添加文字字幕的實(shí)現(xiàn)方法
- php+ffmpeg如何獲取視頻縮略圖、視頻分辨率等相關(guān)信息
相關(guān)文章
實(shí)例講解yii2.0在php命令行中運(yùn)行的步驟
Yii中的資源是和Web頁(yè)面相關(guān)的文件,可為CSS文件,JavaScript文件,圖片或視頻等,資源放在Web可訪問(wèn)的目錄下,直接被Web服務(wù)器調(diào)用。本文通過(guò)實(shí)例講解yii2.0在php命令行中運(yùn)行的步驟,對(duì)yii2.0 php相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)吧2015-12-12Laravel中重寫(xiě)資源路由自定義URL的實(shí)現(xiàn)方法
這篇文章主要給大家介紹了關(guān)于Laravel中重寫(xiě)資源路由自定義URL的實(shí)現(xiàn)方法,需要的朋友可以參考下2017-08-08PHP中常見(jiàn)的錯(cuò)誤與異常處理總結(jié)大全
任何程序員在開(kāi)發(fā)時(shí)都可能遇到過(guò)一些失誤,或其他原因造成錯(cuò)誤的發(fā)生。當(dāng)然,用戶如果不愿意或不遵循應(yīng)用程序的約束,也會(huì)在使用時(shí)引起一些錯(cuò)誤發(fā)生。下面這篇文章主要給大家介紹了關(guān)于PHP中常見(jiàn)的錯(cuò)誤與異常處理,需要的朋友可以參考下,2017-08-08PHP實(shí)現(xiàn)轉(zhuǎn)盤(pán)抽獎(jiǎng)算法分享
這篇文章主要為大家詳細(xì)介紹了PHP實(shí)現(xiàn)大轉(zhuǎn)盤(pán)抽獎(jiǎng)算法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-04-04Linux基于php-fpm模式的lamp搭建phpmyadmin的方法
這篇文章主要介紹了Linux基于php-fpm模式的lamp搭建phpmyadmin的方法,以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。2018-10-10PHP如何獲取當(dāng)前主機(jī)、域名、網(wǎng)址、路徑、端口等參數(shù)
本篇文章主要介紹了PHP如何獲取當(dāng)前主機(jī)、域名、網(wǎng)址、路徑、端口等參數(shù),具有一定的參考價(jià)值,有興趣的可以了解下2017-06-06