我試圖從使用FFMPEG和FFMPEG-PHP擴展的電影中的隨機點生成縮略圖。使用PHP + FFMPEG生成隨機縮略圖
我的腳本工作正常..但需要20分鐘只是爲了生成5-10縮略圖!
該腳本通過生成稍後用作幀號的隨機數來工作。所有生成的數字都在電影幀數內。
你能解釋爲什麼這個腳本需要20分鐘才能完成? 如果沒有,更好的解決方案?
<?php
//Dont' timeout
set_time_limit(0);
//Load the file (This can be any file - still takes ages)
$mov = new ffmpeg_movie('1486460.mp4');
//Get the total frames within the movie
$total_frames = $mov->getFrameCount();
//Loop 5-10 times to generate random frames 5-10 times
for ($i = 1; $i <= 5;) {
// Generate a number within 200 and the total number of frames.
$frame = mt_rand(200,$total_frames);
$getframe = $mov->getFrame($frame);
// Check if the frame exists within the movie
// If it does, place the frame number inside an array and break the current loop
if($getframe){
$frames[$frame] = $getframe ;
$i++;
}
}
//For each frame found generate a thumbnail
foreach ($frames as $key => $getframe) {
$gd_image = $getframe->toGDImage();
imagejpeg($gd_image, "images/shot_".$key.'.jpeg');
imagedestroy($gd_image);
echo $key.'<br/>';
}
?>
腳本應該生成有效的幀號? START - END內的任何內容應該是有效的幀數?然而,循環需要很長時間!
30分鐘?什麼?我會轉換1TB的視頻。 – 2015-03-05 23:31:50