如何修复视频处理和500错误-(Laravel,FFmpeg)

时间:2019-07-19 17:57:12

标签: php laravel video ffmpeg

我正在与Laravel建立一个新网站来上传视频... 我已经阅读了所有可能的解决方案,但没有一个可以帮助我解决问题...

这是我的问题:当我上传一个小文件(<10mb)时,网络运行正常,视频被上传并且视频被转换,仪表板显示转换后的视频---

当我尝试上传大文件时,文件被上传,视频被转换为绿色框(非常不牢固),并且站点出现500服务器错误...

我正在使用Laravel Jobs进行转换。

我的控制器代码:


    <?php

    namespace App\Http\Controllers;

    use Illuminate\Http\Request;
    use Illuminate\Support\Facades\DB;
    use Illuminate\Support\Facades\Storage;
    use Symfony\Component\HttpFoundation\Response;
    use Carbon;
    use Closure;
    use App\Jobs\ConvertVideoForPreview;
    use FFMpeg\FFProbe;
    use FFMpeg\Coordinate\Dimension;
    use FFMpeg\Format\Video\X264;
    use Pawlox\VideoThumbnail\Facade\VideoThumbnail;
    use Pbmedia\LaravelFFMpeg\FFMpegFacade as FFMpeg;
    use Illuminate\Contracts\Filesystem\Filesystem;


    use App\Video;

    class VideoController extends Controller
    {
    public function createVideo(){
        return view('video.createVideo');   
    }
    public function saveVideo(Request $request){


        set_time_limit(0);
        ini_set('memory_limit', '1024M');

        //Validar Formulario

        $validatedData = $this -> validate($request, [

            'title' => 'required',
            'description' => 'required',
            'palabras' => 'required',
            'video' => 'mimetypes:video/mp4,video/quicktime'


        ]);

        $video = new Video();
        $user = \Auth::user();
        $video -> user_id = $user->id;
        $video -> title = $request -> input('title');
        $video -> description = $request -> input('description');
        $video -> palabras = $request -> input('palabras');



        $video_file = $request -> file('video');

        if($video_file){

        $video_path = 'original'.'_'.$video_file ->                                 
        getClientOriginalName();
        Storage::disk('videos')-> put($video_path, 
        \File::get($video_file));

        $videoUrl = storage_path('app/videos/').$video_path;
        $storageUrl = storage_path('app/thumbs/');
        $fileName = 'thumb'.'_'.time().'.jpg';
        $second = 2;

        VideoThumbnail::createThumbnail($videoUrl, $storageUrl,     
        $fileName, $second, $width = 640, $height = 480);

        $video -> preview = $fileName;
        $video -> video_path = $video_path;

      }
        $video -> save();

        ConvertVideoForPreview::dispatch($video);

        return redirect() -> route('home')
                          -> with (array(
            'message' => 'El video se ha enviado con exito'));
      }

        public function getImage($filename){

            $file = Storage::disk('thumbs') -> get($filename);
            return new Response($file, 200);
      }

        public function getVideo($filename){

            $file = Storage::disk('converted_videos') ->   
        get($filename);
            return new Response($file, 200);
      }

      }

这是我的ConvertVideo工作:

    <?php

     namespace App\Jobs;

     use App\Video;

     use Carbon\Carbon;
     use FFMpeg;
     use FFMpeg\Format\Video\X264;

     use Illuminate\Http\Request;
     use Illuminate\Bus\Queueable;
     use Illuminate\Queue\SerializesModels;
     use Illuminate\Queue\InteractsWithQueue;
     use Illuminate\Contracts\Queue\ShouldQueue;
     use Illuminate\Foundation\Bus\Dispatchable;

     class ConvertVideoForPreview implements ShouldQueue

        {
          use Dispatchable, InteractsWithQueue, Queueable, 
          SerializesModels;

          public $video;


          public function __construct(Video $video)
         {
             $this -> video = $video;
         }
          public function handle()
         {

          $converted_name= 'preview'.'-'.$this -> video -> 
          video_path.'.mp4';

          FFMpeg::open('videos/'.$this -> video -> video_path)

                        -> export()
                -> inFormat(new \FFMpeg\Format\Video\X264)
                    -> save('converted_videos/'.$converted_name); 

            $this -> video -> update([
            'video_preview' => $converted_name,
            'processed' => true
             ]);
      }
     }

我的目标之一是上传大型视频文件(<= 4GB),并在视频上传过程中显示一个上传过程栏和一个编码过程栏。

我收到此错误:

 [core:error] [pid 14787:tid 139975366489856] [client 
  201.188.26.12:51022] Script timed out before returning headers: 
  index.php, 

发生这种情况时会处理视频并调用重定向到家庭仪表板的情况...

FFMPEG起作用:

[2019-07-19 17:20:41] local.INFO: ffprobe executed command successfully  
[2019-07-19 17:21:52] local.INFO: ffmpeg executed command successfully  
[2019-07-19 17:21:52] local.INFO: ffmpeg running command '/usr/local/bin/ffmpeg' '-y' '-i' '/home/tribus/public_html/storage/app/videos/original_Sequence 01.mov' '-threads' '12' '-vcodec' 'libx264' '-acodec' 'libfaac' '-b:v' '1000k' '-refs' '6' '-coder' '1' '-sc_threshold' '40' '-flags' '+loop' '-me_range' '16' '-subq' '7' '-i_qfactor' '0.71' '-qcomp' '0.6' '-qdiff' '4' '-trellis' '1' '-b:a' '128k' '-pass' '2' '-passlogfile' '/tmp/ffmpeg-passes5d31fbe9010e6ldt9s/pass-5d31fbe90152d' '/home/tribus/public_html/storage/app/converted_videos/preview-original_Sequence 01.mov.mp4'

我尝试过:更改PHP.ini,Nginx,Apache中的所有内存和文件大小...(可能我丢失了一个)...

也更改了超时时间。

我的环境:VPS 4GB 50GB,APACHE 2.4,PHP7.3,MySql MariaDB,Web服务器:Apache-Nginx,Laravel 5.8。

有人可以帮助我实现这一目标吗?...

这是转换后的大型视频的外观,并在浏览器中显示500错误: Error video processed

0 个答案:

没有答案