由于使用PHP进行FFMPEG转换,Jquery上传文件中的错误 [英] Error in Jquery upload file due to FFMPEG conversion using PHP

查看:151
本文介绍了由于使用PHP进行FFMPEG转换,Jquery上传文件中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是jQuery上传文件插件,当上传视频时,将使用FFMPEG进行转换。对于短尺寸文件,一切都可以正常工作,但是当我尝试上传更大的文件时,响应中不会返回任何内容。我以为这可以让我 max_execution_time 发行,所以我已经删除了限制但仍然发生,但是当我看到文件夹,文件被完全转换并输入到数据库,所以一切echo除了 echo 外,似乎可以使用大文件。我尝试删除一个FFMPEG转换语句,并将文件转换为一个大小,但仍然对大文件的结果是相同的。

I am using jQuery upload file plugin, and when videos are uploaded, they are converted using FFMPEG. For short sized files everything works perfectly but when I try to upload bigger files, nothing is returned in the response. I thought that this could me max_execution_time issue so I have removed the limit but still it happens, but when I see the folder, the files are converted completely and entered into database so everything seems to work of large files except it doesn't echo. I tried to remove one FFMPEG conversion statement and convert file to just one size but still the result is same for large files.

,我看到这个结果

这是我的PHP代码

    $default = ini_get('max_execution_time');
    set_time_limit(0);
    $fileName = $_FILES["myfile"]["name"];
    $fileName = str_ireplace(' ', '_', $fileName);                
    $fn = $_FILES["myfile"]["name"];
    $i = 1;
    $actual_name = pathinfo($fileName,PATHINFO_FILENAME);
    $original_name = $actual_name;
    $extension = strtolower (pathinfo($fileName, PATHINFO_EXTENSION));      
    while(file_exists($output_dir.$fileName))
    {           
       $actual_name = (string)$original_name.$i;
       $fileName = $actual_name.".".$extension;
       $filetoconvert = $actual_name.".mp4";
       $filetoconvertSD=$actual_name."SD.mp4";
       $i++;
    }
    //echo $fileName;
        move_uploaded_file($_FILES["myfile"]["tmp_name"],$output_dir.$fileName);

       $url = $output_dir1.$fileName; 
       $outputnameSD="";
       $time="";
       $del_url = $output_dir.$fileName;


          $i = 1;
          while(file_exists($output_dir.$filetoconvert))
          {           
              $actual_name = (string)$original_name.$i;
              $fileName = $actual_name.".mp4";
              $filetoconvert = $actual_name.".mp4";
              $filetoconvertSD=$actual_name."SD.mp4";
              $i++;
          }
          $outputname = $output_dir1.$filetoconvert;
          $outputnameSD=$output_dir1.$filetoconvertSD;

          $videofile="/var/www/html/".$url; 
          $xyz = shell_exec("ffmpeg -i \"{$videofile}\" 2>&1"); //Get duration 
          $search='/Duration: (.*?),/';
          preg_match($search, $xyz, $matches);
          $tim=explode(".", $matches[1]);
          $time=$tim[0];
          $ret = exec(' ffmpeg -i /var/www/html/'.$url.' -acodec libfaac -b:a 128k -vcodec libx264 -preset fast -vprofile baseline -b:v 400k -maxrate 400k -bufsize 800k -crf 26 -flags +aic+mv4 /var/www/html/'.$outputnameSD, $out, $err);
          $ret = exec(' ffmpeg -i /var/www/html/'.$url.' -acodec libfaac -b:a 196k -vcodec libx264 -preset fast -vprofile high -b:v 1000k -crf 20 -flags +aic+mv4 /var/www/html/'.$outputname, $out, $err);

          unlink($del_url);
          $url = $output_dir1.$fileName;              

       Database QUERY HERE         
       $ret[]= $fileName;
      echo '<li>
      '.$fileName.'
    </li>';
    set_time_limit($default);


推荐答案

有人遇到同样的问题,修复。我将ffmpeg代码更改为

Incase someone encounter same issue, than this is how I fixed it. I changed the ffmpeg code to

 $ret = exec('ffmpeg -i /var/www/html/'.$url.' -vcodec libx264 -crf 20 -preset fast /var/www/html/'.$outputname.' >/dev/null 2>/dev/null &', $out, $err);
 $ret = exec('ffmpeg -i /var/www/html/'.$url.' -vcodec libx264 -crf 26 -preset fast /var/www/html/'.$outputnameSD.' >/dev/null 2>/dev/null &', $out, $err);

最后一部分> / dev / null 2> / dev / null & 让它相信exec命令在后台运行时执行。这个解决方案的唯一缺点是,如果你想像我一样,你不能删除原始文件。

The last part >/dev/null 2>/dev/null & lets it believe that exec command is executed while it runs at the background. The only drawback of this solution is that you can't delete the original file after conversion if you want to like I had to.

为了满足这个解决方案,提供的答案@hdezela是一种方式,即写一个cronjob

To cater this solution, the answer provided by @hdezela is the way to go about it i.e. to write a cronjob

这篇关于由于使用PHP进行FFMPEG转换,Jquery上传文件中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆