php+ffmpeg如何獲取視頻縮略圖、視頻分辨率等相關(guān)信息_第1頁(yè)
php+ffmpeg如何獲取視頻縮略圖、視頻分辨率等相關(guān)信息_第2頁(yè)
php+ffmpeg如何獲取視頻縮略圖、視頻分辨率等相關(guān)信息_第3頁(yè)
php+ffmpeg如何獲取視頻縮略圖、視頻分辨率等相關(guān)信息_第4頁(yè)
php+ffmpeg如何獲取視頻縮略圖、視頻分辨率等相關(guān)信息_第5頁(yè)
已閱讀5頁(yè),還剩3頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

第php+ffmpeg如何獲取視頻縮略圖、視頻分辨率等相關(guān)信息目錄前言下面介紹使用ffmpeg獲取視頻首幀的方法。FFmpeg獲得視頻文件的縮略圖Fmpeg讀取視頻信息Fmpeg獲得視頻文件的總長(zhǎng)度時(shí)間和創(chuàng)建時(shí)間總結(jié)

前言

ffmpeg是一款開源、跨平臺(tái)的視頻處理程序,可用在Windows、mac、linux等平臺(tái),可以方便的運(yùn)用多種語(yǔ)言腳本來調(diào)用其執(zhí)行視頻的操作。

下面介紹使用ffmpeg獲取視頻首幀的方法。

php

//待處理視頻

$in_file='/video/2025/12/25/222834_f93690f37496456a9674763d69bcd9c0.mp4';

//縮略圖保存路徑

$out_file='./test.jpg';

//shell腳本

$shell="ffmpeg-i$in_file-y-fimage2-ss00:00:01-vframes1$out_file2

//調(diào)用php的exec方法去執(zhí)行腳本

exec($shell,$output,$return_val);

//獲取輸出信息

print_r($output);

FFmpeg獲得視頻文件的縮略圖

functiongetVideoCover($file,$time,$name){

if(empty($time))$time='1';//默認(rèn)截取第一秒第一幀

$strlen=strlen($file);

//exec("ffmpeg-i".$file."-y-fmjpeg-ss".$time."-t0.001-s320x240".$name."",$out,$status);

$str="ffmpeg-i".$file."-y-fmjpeg-ss3-t".$time."-s320x240".$name;

$result=system($str);

Fmpeg讀取視頻信息

php

define('FFMPEG_PATH','/usr/local/ffmpeg2/bin/ffmpeg-i"%s"21');

functiongetVideoInfo($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];//開始時(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í)間

functiongetTime($file){

$vtime=exec("ffmpeg-i".$file."21|grep'Duration'|cut-d''-f4|seds/,//");//總長(zhǎng)度

$ctime=date("Y-m-dH:i:s",filectime($file));//創(chuàng)建時(shí)間

//$duration=explode(":",$time);

//$duration_in_seconds=$duration[0]*3600+$duration[1]*60+round($duration[2]);//轉(zhuǎn)化為秒

returnarray('vtime'=$vtime,

'ctime'=$ctime

另外一種方法

ffprobe-vquiet-print_formatjson-show_format-show_streamstest.mp4

結(jié)果

{

streams:[

{

index:0,

codec_name:h264,

codec_long_name:H.264/AVC/MPEG-4AVC/MPEG-4part10,

profile:High,

codec_type:video,

codec_time_base:1/1200,

codec_tag_string:avc1,

codec_tag:0x31637661,

width:538,

height:888,

coded_width:544,

coded_height:896,

has_b_frames:0,

sample_aspect_ratio:0:1,

display_aspect_ratio:0:1,

pix_fmt:yuv420p,

level:31,

color_range:tv,

color_space:bt709,

color_transfer:bt709,

color_primaries:bt709,

chroma_location:left,

refs:2,

is_avc:1,

nal_length_size:4,

r_frame_rate:30/1,

avg_frame_rate:30/1,

time_base:1/600,

start_pts:0,

start_time:0.000000,

duration_ts:6040,

duration:10.066667,

bit_rate:1022789,

bits_per_raw_sample:8,

nb_frames:302,

disposition:{

default:1,

dub:0,

original:0,

comment:0,

lyrics:0,

karaoke:0,

forced:0,

hearing_impaired:0,

visual_impaired:0,

clean_effects:0,

attached_pic:0

},

tags:{

creation_time:2025-01-0115:59:27,

language:und,

handler_name:CoreMediaVideo

}

},

{

index:1,

codec_name:aac,

codec_long_name:AAC(AdvancedAudioCoding),

profile:LC,

codec_type:audio,

codec_time_base:1/44100,

codec_tag_string:mp4a,

codec_tag:0x6134706d,

sample_fmt:fltp,

sample_rate:44100,

channels:1,

channel_layout:mono,

bits_per_sample:0,

r_frame_rate:0/0,

avg_frame_rate:0/0,

time_base:1/44100,

start_pts:-2112,

start_time:-0.047891,

duration_ts:442368,

duration:10.031020,

bit_rate:45569,

max_bit_rate:48000,

nb_frames:432,

disposition:{

default:1,

dub:0,

original:0,

comment:0,

lyrics:0,

karaoke:0,

forced:0,

hearing_impaired:0,

visual_impaired:0,

clean_effects:0,

attached_pic:0

},

tags:{

creation_time:2025-01-0115:59:27,

langu

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論