简体   繁体   English

FFmpeg文件转换超出最大执行时间

[英]FFmpeg file conversion exceeds maximum execution time

I have a file upload system the checks the file format, etc and converts to an mp4 if necessary. 我有一个文件上传系统,检查文件格式等,并在必要时转换为mp4。 This works fine as long as the video file(s) total length is less than 30 seconds. 只要视频文件的总长度小于30秒,此方法就可以正常工作。 I have been testing this two short clips about 10 seconds each and it work fine but when I test this with a clip that this 33 seconds I get the error : 我一直在测试这两个短片,每个短片大约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 致命错误 :第59行的C:\\ xampp \\ htdocs \\ own_it_all \\ global.func \\ file_upload.php中超过30秒的最大执行时间

I could just increase the maximum execution time in the php.ini file but as the max length of a video is 20 mins this wouldn't seem very user friendly making the user wait 20 mins per video. 我可以增加php.ini文件中的最大执行时间,但是由于视频的最大长度为20分钟,因此这似乎不太用户友好,因为用户需要每个视频等待20分钟。 Is there a way of converting the video instantly or as near as? 是否可以立即或尽可能近地转换视频?

This is the exec cmd i have: 这是我有的执行命令:

$cmd = "ffmpeg -i $input -vcodec h264 -acodec aac -strict -2 $o";

As the up-loader allows multiple uploads this is inside a for loop. 由于上载程序允许多次上传,因此这在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');
            }
        }
    }

Check your php ini and set Max Execution Time. 检查您的php ini并设置最大执行时间。 In my case, 5 min of video is more than 30 min of conversion with ffmpeg. 就我而言,5分钟的视频比ffmpeg的转换要多30分钟。 You can use ajax for call your "converter" php script and put a "loader" with jscript. 您可以使用ajax调用您的“转换器” php脚本,并使用jscript放置“加载程序”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM