gpt4 book ai didi

php - FFmpeg 文件转换超过最大执行时间

转载 作者:行者123 更新时间:2023-12-04 23:00:38 25 4
gpt4 key购买 nike

我有一个文件上传系统,可以检查文件格式等,并在必要时转换为 mp4。只要视频文件的总长度小于 30 秒,就可以正常工作。
我一直在测试这两个短片段,每个片段大约 10 秒,它工作正常,但是当我用一个 33 秒的片段测试它时,我得到了错误:

Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\own_it_all\global.func\file_upload.php on line 59



我可以增加 php.ini 文件中的最大执行时间,但由于视频的最大长度为 20 分钟,这似乎对用户不太友好,让用户每个视频等待 20 分钟。
有没有办法立即或尽可能近地转换视频?

这是我拥有的 exec cmd:
$cmd = "ffmpeg -i $input -vcodec h264 -acodec aac -strict -2 $o";

由于 uploader 允许多次上传,因此它位于 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 并设置 Max Execution Time。就我而言,5 分钟的视频比 ffmpeg 的转换时间超过 30 分钟。
您可以使用 ajax 来调用您的“转换器”php 脚本,并使用 jscript 放置一个“加载器”。

关于php - FFmpeg 文件转换超过最大执行时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23469408/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com