
Generate Thumbnail from video in Laragon server using Laravel.
In this article, we show how we can generate thumbnails from an uploaded video by the user in laravel.
Step 1: Download FFmpeg/FFmprobe's .exe file
First, we have to download ffmpeg.exe and ffmprobe.exe and this file you can download using the below URL,
https://ffmpeg.org/download.html
Step 2: Extract the folder and get ffmpeg.exe, ffmprobe.exe and put that in the bin folder of laragon.
Now, extract the folder and get ffmpeg.exe,ffmprob.exe copy that file, and put it in the bin folder of laragon.
Step 3: Install the package for FFmpeg in Laravel.
This package will help you with image processing in laravel.
composer require php-ffmpeg/php-ffmpeg
Step 4: Use that package for image processing
In this article, we generate 3 thumbnails from different times using the below code
// It will generate 3 different Thumbnail from different time
// This will return duration of video
$ffprobe = \FFMpeg\FFProbe::create();
$duration = $ffprobe->format($orignal_video_path)->get('duration');
$seconds = ceil(round($duration) / 3);
$initial_seconds= 0;
// This will generate three thumbnail and store into your given path
$ffmpeg = \FFMpeg\FFMpeg::create();
$video = $ffmpeg->open($orignal_video_path);
for ($i = 1; $i < 4; $i++) {
$thum_name = time() . '_' . $i . ".png";
$thumbnail = $thumbnail_upload_path . $thum_name;
$frame = $video->frame(\FFMpeg\Coordinate\TimeCode::fromSeconds($initial_seconds));
$initial_seconds = $initial_seconds+ $seconds;
$frame->save($thumbnail);
}
Step 5: Run Project and generate thumbnails
Run your project in local server and generate thumbnails