PHP從FLV文件獲取視頻預(yù)覽圖的方法
本文實(shí)例講述了PHP從FLV文件獲取視頻預(yù)覽圖的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
// references http://www.longtailvideo.com/support/forum/Modules/12661/External-PHP-with-FFmpeg-using-readfile-
// generate a preview image from an FLV file on-the-fly, or to save
// call with: ffmpeg_image.php?file=video.flv&time=00:00:05&browser=true
// call with: ffmpeg_image.php?file=video.flv&percent=75.3&browser=true
// no time defaults to "00:00:01" (one second), no browser defaults to "true"
$videofile = (isset($_GET['file'])) ? strval($_GET['file']) : 'video.flv';
$image = substr($videofile, 0, strlen($videofile) - 4);
$time = (isset($_GET['time'])) ? strval($_GET['time']) : '00:00:01';
// debug (" File: ", $videofile);
// debug (" Image: ", $image);
// debug (" Time: ", $time);
// check time format
if (!preg_match('/\d\d:\d\d:\d\d/', $time))
{
$time = "00:00:00";
}
if (isset($_GET['percent']))
{
$percent = $_GET['percent'];
// debug (" Percent: ", $percent);
ob_start();
exec("/usr/bin/ffmpeg -i \"". $videofile . "\" 2>&1");
$duration = ob_get_contents();
ob_end_clean();
// debug ("Duration: ", $duration);
preg_match('/Duration: (.*?),/', $duration, $matches);
$duration = $matches[1];
// debug ("Duration: ", $duration);
$duration_array = split(':', $duration);
$duration = $duration_array[0] * 3600 + $duration_array[1] * 60 + $duration_array[2];
$time = $duration * $percent / 100;
// debug (" Time: ", $time);
$time = intval($time/3600) . ":" . intval(($time-(intval($time/3600)*3600))/60) . ":" . sprintf("%01.3f", ($time-(intval($time/60)*60)));
// debug (" Time: ", $time);
}
$browser = (isset($_GET['browser'])) ? strval($_GET['browser']) : 'true';
// debug (" Browser: ", $browser);
if ($browser == "true")
{
header('Content-Type: image/png');
exec("/usr/bin/ffmpeg -vcodec png -i \"" . $videofile . "\" -ss " . $time . " -vframes 1 -f image2 -");
//header('Content-Type: image/jpeg');
//exec("/usr/bin/ffmpeg -vcodec mjpeg -i \"" . $videofile . "\" -ss " . $time . " -vframes 1 -f image2 -");
}
else
{
exec("/usr/bin/ffmpeg -vcodec png -i \"" . $videofile . "\" -ss " . $time . " -vframes 1 -f image2 \"" . $image . "\"%d.png");
//exec("/usr/bin/ffmpeg -vcodec mjpeg -i \"" . $videofile . "\" -ss " . $time . " -vframes 1 -f image2 \"" . $image . "\"%d.jpg");
}
?>
希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。
- PHP編程獲取音頻文件時(shí)長(zhǎng)的方法【基于getid3類】
- 解析用PHP讀寫音頻文件信息的詳解(支持WMA和MP3)
- PHP獲取音頻文件的相關(guān)信息
- php利用ffmpeg提取視頻中音頻與視頻畫面的方法詳解
- Thinkphp5框架實(shí)現(xiàn)圖片、音頻和視頻文件的上傳功能詳解
- PHP 獲取視頻時(shí)長(zhǎng)的實(shí)例代碼
- PHP基于ffmpeg實(shí)現(xiàn)轉(zhuǎn)換視頻,截圖及生成縮略圖的方法
- php使用FFmpeg接口獲取視頻的播放時(shí)長(zhǎng)、碼率、縮略圖以及創(chuàng)建時(shí)間
- php截取視頻指定幀為圖片
- PHP getID3類的使用方法學(xué)習(xí)筆記【附getID3源碼下載】
相關(guān)文章
阿里云的WindowsServer2016上部署php+apache
這篇文章主要介紹了阿里云的WindowsServer2016上部署php+apache的相關(guān)資料,需要的朋友可以參考下2018-07-07PHP 實(shí)現(xiàn)判斷用戶是否手機(jī)訪問(wèn)
這篇文章主要介紹了PHP 實(shí)現(xiàn)判斷用戶是否手機(jī)訪問(wèn)的方法,十分實(shí)用的功能,推薦給有需要的小伙伴。2015-01-01PHP的CURL方法curl_setopt()函數(shù)案例介紹(抓取網(wǎng)頁(yè),POST數(shù)據(jù))
本文主要對(duì)PHP的CURL方法curl_setopt()函數(shù)案例進(jìn)行介紹:1.抓取網(wǎng)頁(yè)的簡(jiǎn)單案例;2.POST數(shù)據(jù)案例...下面就跟小編一起來(lái)看下吧2016-12-12php判斷某個(gè)方法是否存在函數(shù)function_exists (),method_exists()與is_callabl
這篇文章主要介紹了php判斷某個(gè)方法是否存在函數(shù)function_exists (),method_exists()與is_callable()區(qū)別與用法,結(jié)合實(shí)例形式分析了php function_exists (),method_exists()與is_callable()基本功能、用法、區(qū)別與操作注意事項(xiàng),需要的朋友可以參考下2020-04-04PHP大小寫問(wèn)題:函數(shù)名和類名不區(qū)分,變量名區(qū)分
這篇文章主要介紹了PHP大小寫問(wèn)題,php中變量名是區(qū)分大小寫的,而函數(shù)名與類名是不區(qū)分的2013-06-06PHP實(shí)現(xiàn)根據(jù)銀行卡號(hào)判斷銀行
公司業(yè)務(wù)需要用到根據(jù)銀行卡號(hào)查詢銀行卡的相關(guān)信息,如歸屬地,歸屬銀行,卡的種類等,仔細(xì)研究了一番,分享給大家2015-04-04