[英]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.