Search code examples
phplaravelffmpegvideo-thumbnailsffmpeg-php

Error while generating video thumbnail in laravel


I am using ffmpeg and Pawlox/video-thumbnail package to generate thumbnail. I have already installed both ffmpeg and pawlox/video-thumbnail.

Here is my code.

VideoThumbnail::createThumbnail(url('/storage/app/accident_report_videos/ynvO5D9GzUJsLPj8vPlyiOEND0ag9MeFGr4NFu5k.mp4'), asset('thumbnAils'), '111.jpg', 2, 600, 600);

Error:

error:getimagesize(http://54.255.240.102/storage/app/accident_report_videos/thumbs/ynvO5D9GzUJsLPj8vPlyiOEND0ag9MeFGr4NFu5k.jpg): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found

Video path and thumbnail path are both right. But it is using thumbnail method in videothumbnail.php to create thumbnail. This function is generating thumbnail. So after that it calls resizeCropImage() function in which they uses getimagesize() funtion. And getiamgesize() function does not get image from because it is never generated.


Solution

  • You don't want to use url() here - it's going to generate a full HTTP URL, which means your server's going to have to download the full MP4 file (which could be gigabytes!) to screenshot it.

    (Your storage directory is also typically not available via HTTP...)

    Use an actual path, via the storage_path() helper.

    VideoThumbnail::createThumbnail(storage_path('app/accident_report_videos/ynvO5D9GzUJsLPj8vPlyiOEND0ag9MeFGr4NFu5k.mp4'), storage_path('app/accident_report_videos/thumbs'), '111.jpg', 2, 600, 600);