回答
這是我的代碼獲取的幀,並生成從所述視頻圖像...
// get the duration and a random place within that
$cmd = "ffmpeg -i " . $videoPath . " 2>&1";
if (preg_match('/Duration: ((\d+):(\d+):(\d+))/s', `$cmd`, $time)) {
$total = ($time[2] * 3600) + ($time[3] * 60) + $time[4];
$second = rand(1, ($total - 1));
}
exec($cmd);
// get the screenshot
exec("ffmpeg -i " . $videoPath . " -deinterlace -an -ss $second -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg " . $imageOutput . " 2>&1");
$第二變量是0和總的持續時間之間的隨機數。 和第二個exec()是從選定的幀創建一個圖像文件。
$ imageOutput是生成圖像的絕對路徑位置。 例如:/home/ariawan/image-generated.jpg
我使用PHP和FFMPEG得到視頻的持續時間。
$cmd = "ffmpeg -i " . $videoPath . " 2>&1";
if (preg_match('/Duration: ((\d+):(\d+):(\d+))/s', `$cmd`, $time)) {
$total = ($time[2] * 3600) + ($time[3] * 60) + $time[4];
}
exec($cmd);
print_r()要查看的$ time變量。 確保你的機器上安裝了ffmpeg .. 希望這會有所幫助。
還有一個FFMPEG PHP擴展ie。 apt-get install php5-ffmpeg
然後
$movie = new ffmepg_movie("path/to/movie.flv"); $duration_in_seconds = $movie->getDuration();
這對我以前的工作。該擴展適用於檢索元數據並測試上傳的文件是否爲FLV等。
然後除以60獲得分鐘和模60得到其餘秒 – 2010-10-26 07:59:58
很酷......我也會嘗試這個選項。非常感謝你! – Ciprian 2010-10-28 06:45:53
我使用的是getID3 PHP library
,用普通的舊版PHP編寫,沒有任何依賴關係。
它不僅會以秒爲單位給出.flv
電影的持續時間,而且會將其轉換爲minute:seconds
格式。下面是用v一個代碼示例1.7.9(的getid3
最新穩定版):
<?php
// getId3 library uses deprecated eregi_* functions
// which generate errors under PHP 5.3 - so I excluded them
error_reporting(E_ALL^E_DEPRECATED);
// just for debugging/sample
header('Content-Type: text/plain');
// include the getid3 base class in order to use the lib
require_once('./lib/getid3.php');
// path to your .flv file
$filename = './sample.flv';
$getID3 = new getID3();
$fileInfo = $getID3->analyze($filename);
// echoes something like 127.8743
print 'Playtime in seconds: ' . $fileInfo['playtime_seconds'];
print chr(10);
// echoes something like: 2:07
print 'Playtime in minute:seconds format: ' . $fileInfo['playtime_string'];
謝謝你。我感謝您的幫助。但是我最終使用了第二個建議。任何想法如何抓住縮略圖? – Ciprian 2010-10-27 09:14:47
+1爲getid3因爲它沒有依賴關係 – 2010-10-27 09:49:28
@ciprian如何抓住縮略圖應該是一個單獨的問題。 – 2010-10-27 09:50:13
謝謝你的幫助。我也想從flv文件生成縮略圖。我正在嘗試使用此代碼來完成此操作。但我似乎做錯了什麼。
$cmd = "ffmpeg -i /home/web1/wpmu.site.com/htdocs/wp-content/blogs.dir/7/files/2010/10/4973_3.flv -f image2 -vframes 1 -ss 00:00:01 -y -s 100x100 /home/web1/wpmu.site.com/htdocs/wp-content/blogs.dir/7/files/2010/10/4973_3.png";
exec($cmd, $output, $return);
我將它包含在test.php頁面上。它應該只是通過刷新頁面來運行?我自己添加了png文件的路徑。這有什麼問題?
由於
我已經爲您的生成縮略圖問題添加了另一個答案。我也附上了代碼,但我在ffmpeg上使用的選項是jpeg。 – ariawan 2010-10-27 09:48:26
- 1. FLV持續時間從類
- 2. 用AS3顯示FLV的持續時間
- 3. 如何在java中獲得flv持續時間?
- 4. 獲取AVFoundation視頻的持續時間
- 5. 獲取gif動畫的持續時間
- 6. 獲取AJAX請求持續時間
- 7. SQL從持續時間獲取數據
- 8. 獲取視頻的持續時間
- 9. 從.wav文件獲取持續時間
- 10. 從BackgroundAudioPlayer獲取持續時間
- 11. 如何獲取Soundpool的持續時間
- 12. 從YouTube獲取持續時間url
- 13. 在android中獲取mp3持續時間
- 14. 獲取mxf文件的持續時間
- 15. 從開始時間和持續時間獲取結束時間
- 16. SQL事件探查器持續時間與SSMS持續時間
- 17. 如何提取只包含持續時間的持續時間?
- 18. 獲得視頻持續時間與ffmpeg的,PHP函數
- 19. 在ffmpeg中獲取音頻的持續時間在php
- 20. CakePHP(或只是PHP)獲取會話持續時間
- 21. 獲取日期時間格式之間的持續時間
- 22. Music21獲取所有筆記與持續時間
- 23. PHP - 如何獲得時間戳的持續時間?
- 24. 獲取從會話(「date_time」)登錄時間的持續時間
- 25. 持續時間
- 26. 從FLV獲取流(PHP,CURL)
- 27. 如何通過shell命令讀取FLV文件的持續時間?
- 28. 獲取連續記錄視圖的持續時間
- 29. php臨時文件持續時間
- 30. 時間片持續時間
ariawan,非常感謝你的幫助人。我能夠在文件夾中獲取圖像,但它是空的0字節。這是我有: – Ciprian 2010-10-27 13:04:30
我不知道發生了什麼,但我正在工作的服務器已重新啓動,現在一切正常。非常感謝! – Ciprian 2010-10-28 06:41:27
好的..很棒... – ariawan 2010-10-28 15:14:30