[英]FFmpeg file conversion exceeds maximum execution time
我有一個文件上傳系統,檢查文件格式等,並在必要時轉換為mp4。 只要視頻文件的總長度小於30秒,此方法就可以正常工作。 我一直在測試這兩個短片,每個短片大約10秒,並且工作正常,但是當我用這33秒的短片測試時,我得到了錯誤:
致命錯誤 :第59行的C:\\ xampp \\ htdocs \\ own_it_all \\ global.func \\ file_upload.php中超過30秒的最大執行時間
我可以增加php.ini文件中的最大執行時間,但是由於視頻的最大長度為20分鍾,因此這似乎不太用戶友好,因為用戶需要每個視頻等待20分鍾。 是否可以立即或盡可能近地轉換視頻?
這是我有的執行命令:
$cmd = "ffmpeg -i $input -vcodec h264 -acodec aac -strict -2 $o";
由於上載程序允許多次上傳,因此這在for循環內。
foreach($_FILES['file']['name'] as $key => $name){
if($_FILES['file']['error'][$key] === 0){
$temp = $_FILES['file']['tmp_name'][$key];
$ext = explode('.',$name);
$ext = strtolower(end($ext));
$_file = md5($temp).time();
$file = $_file.'.'.$ext;
if(in_array($ext,$allowed) === true && move_uploaded_file($temp,"../uploads/{$file}") === true){
$file_type = explode('/',$_FILES['file']['type'][$key]);
if($file_type[0] === 'image'){
$succedeed[] = array('name' => $name,'file' => $file, 'type' => 'image');
}else{
$ffmpeg = 'ffmpeg';
$output = dirname(__DIR__).'/uploads/thumbs/'.$_file.'.jpg';
$input = dirname(__DIR__).'/uploads/'.$file;
$mov = new ffmpeg_movie($input);
$d = $mov->getDuration();
$iscopy = $mov->getCopyright();
$h = $mov->getFrameHeight();
$w = $mov->getFrameWidth();
$pos = ceil((int)$d /3);
$size = $w.'x'.$h;
$i = explode('.',$input);
$o = $i[0].'.mp4';
if(ceil($d) < 1200){
if($ext != 'mp4'){
$cmd = "ffmpeg -i $input -vcodec h264 -acodec aac -strict -2 $o";
//$cmd = "ffmpeg -i $input -vcodec h264 -acodec aac -s $size $o";
shell_exec($cmd);
$toclear[] = array('file' => $file);
}
$cmd = "ffmpeg -ss $pos -i $o -an -s $size $output";
shell_exec($cmd);
$total_time += $pos;
$succedeed[] = array('name' => $name,'file' => 'thumbs/'.$_file.'.jpg', 'type' => 'mp4');
}else{
$failed[] = array('name' => $name, 'file' => $file, 'error' => 'Video length cannot exceed 20mins.');
}
}
}else{
$failed[] = array('name' => $name, 'file' => $file, 'error' => 'File type not allowed');
}
}
}
檢查您的php ini並設置最大執行時間。 就我而言,5分鍾的視頻比ffmpeg的轉換要多30分鍾。 您可以使用ajax調用您的“轉換器” php腳本,並使用jscript放置“加載程序”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.