The Techjoomla Blog

Stay updated with all the latest happenings at Techjoomla. From news about the developments in your favourite extensions to Tips & Tricks about the Joomla CMS, Framework & Development.
Font size: +
2 minutes reading time (443 words)

How to generate video thumbnails in PHP?

How to generate video thumbnails in PHP?

A Video link without a thumbnail is like a smartphone without a camera, you can use it but no one would like to use it. If you want your visitors to see your video, you need to make sure that your video link has a thumbnail which is forcing users to click on the link.

How can we do this?

1. Generate thumbnails for video using FFmpeg

There is an easy way to generate thumbnails for video in Linux using FFmpeg, it is a nice library for processing videos.

First Install FFmpeg on your server

If you are using ubuntu then refer the following link to install FFmpeg

// Code to generate video thumbnail 

// Location where video thumbnail to store
$thumbnail_path = 'your_site_domain/media/images/thumbnail/';
$second             = 1;
$thumbSize       = '150x150';

// Video file name without extension(.mp4 etc)
$videoname  = 'sample_video';

// FFmpeg Command to generate video thumbnail

$cmd = "{$ffmpeg_installation_path} -i {$video_file_path} -deinterlace -an -ss {$second} -t 00:00:01  -s {$thumbSize} -r 1 -y -vcodec mjpeg -f mjpeg {$path_to_store_generated_thumbnail} 2>&1";

exec($cmd, $output, $retval);

if ($retval)
	echo 'error in generating video thumbnail';
	echo 'Thumbnail generated successfully';
	echo $thumb_path = $thumbnail_path . $videoname . '.jpg';


Sample Image 

2. Vimeo API to get the video thumbnail

Fetching the Vimeo video thumbnail is very simple

 $videoId             =  128122927;
 $thumbnail_size = ‘thumbnail_small’;

$hash = unserialize(file_get_contents("$videoId.php"));

return $hash[0][$thumbnail_size];
  return $hash[0]["thumbnail_small"];
  return $hash[0]["thumbnail_medium"];
  return $hash[0]["thumbnail_large"];

3. Youtube video thumbnail API

Each YouTube video has 4 generated images.

Use either


All of the above URLs are available over https too. Just change HTTP to https in any of the above URLs. Alternatively, you can use the YouTube API to get thumbnail images.

We recently implemented this in one of your Crowdfunding extensions, JGive. When this comes to crowdfunding, investments and donations, videos play a significant role. If a new visitor is on your campaign, a video can explain the kind of work your campaign is doing and the money is in safe hands and is being used in the right way. Thus, help build trust between the visitor and the campaign owner.

It can also solve the purpose of sending a message and thanking all the users for making the campaign successful and much more! This is how by using thumbnails and creating curiosity in the minds of people you can attract more visitors to your campaign.

Note: This feature will be introduced in JGive 1.7. See the entire feature list?

Hope this Blog helps you get maximum users and donations on your campaign!

 Not using JGive yet for your Crowdfunding Joomla Site? Get it now!

Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

Shika Beta 12 gets you a surprise!
PDF Embed plugin v2.1 with Google Viewer and PDF.j...

Related Posts