Grab single or multiple thumbnails from videos

Here you can learn how to get single or multiple thumbnails from any video format using ASP.NET Media Handler Pro.

Features available Media Handler Pro for grabbing thumbs.

The following features provided by Media Handler Pro for getting single or multiple thumbnails or images from videos. You can use Media Handler Pro for capturing single or multiple thumbs.
Grab single thumbnail or image
  • Grab single thumbnai or image from any video format.
  • Grab single thumbnail or imagein any image format, recommended jpg, png.
  • Grab single thumbnail or image from any specified duration e.g "00:00:15" represent grabbing thumbnail from 15th second of video.
  • Grab single thumbnail or image in any specified size or in default video size.
Grab multiple thumbnails or images
  • Grab multiple thumbnails or images from any video format.
  • Grab multiple thumbnails or images in any specified numbers. e.g No_of_thumbs=10 means grab 10 thumbnails from video.
  • Grab multiple thumbnails in any specified size or in default size.
  • Both automatic and manual calculation of time in seconds between two thumbs are supported.

Media Handler Pro Version 3.0 or later (C# only)

Grab thumbnail from video using Media Handler Pro version 3.0. Note for using old version of Media Handler Pro check examples below.

Grab thumbnail from video using asp.net media handler pro. sample code below

// e.g 00:01:20 is duration of video.

MediaHandler _mhandler = new MediaHandler();

string mid_duration = UtilityBLL.Calculate_Mid_Duration(duration);

_mhandler.FFMPEGPath = HttpContext.Current.Server.MapPath("~\\ffmpeg\\ffmpeg.exe");
_mhandler.InputPath = RootPath + "\\contents\\video";
_mhandler.OutputPath = RootPath + "\\contents\\thumbnails";

_mhandler.FileName = "sample.avi";

// Multiple thumbs without automatic transition time

_mhandler.ImageName = "sample_";
_mhandler.Multiple_Thumbs = true;
_mhandler.No_Of_Thumbs = 15;
_mhandler.Thumb_Transition_Time = 1;
_mhandler.Thumb_Start_Position = 5;
_mhandler.Width = 320;
_mhandler.Height = 240;

// Multiple thumbs with automatic transition time

_mhandler.ImageName = "sample_";
_mhandler.Auto_Transition_Time = true;
_mhandler.Multiple_Thumbs = true;
_mhandler.No_Of_Thumbs = 15;
_mhandler.Thumb_Start_Position = 5;
_mhandler.Width = 320;
_mhandler.Height = 240;

// Grab single thumb from video

_mhandler.Image_Format = "jpg";
_mhandler.ImageName = "sample.jpg";
_mhandler.Frame_Time = mid_duration;
_mhandler.Width = 150;
_mhandler.Height = 150;

// Call function to start capturing thumbs from video.
output = _mhandler.Grab_Thumb();

Sample Codes and examples. (C# only)

Grab thumbnail from middle of video

// e.g 00:01:20 is duration of video.

string mid_duration = UtilityBLL.Calculate_Mid_Duration(duration);
string image_name = _mhandler.Grab_Image(outfile, _ffmpegpath, OutputPath, ThumbPath, mid_duration, "jpg", 130, 98);

// utility function for calculating mid duration from full duration e.g "00:01:20"

 

public static string Calculate_Mid_Duration(string Duration)
{
double seconds = Math.Ceiling(double.Parse(Duration.Remove(0, Duration.LastIndexOf(":") + 1)));
string _minutes = Duration.Remove(0, Duration.IndexOf(":") + 1);
double minutes = Math.Ceiling(double.Parse(_minutes.Remove(_minutes.LastIndexOf(":"))));
double hours = Math.Ceiling(double.Parse(Duration.Remove(Duration.IndexOf(":"))));
string str = "";
if (hours > 0)
{
// divide hours by 2
int mid_hours = (int)hours / 2;
if (mid_hours < 10)
str = str + "0" + mid_hours + ":";
else
str = str + "" + mid_hours + ":";
}
else
{
str = str + "00:";
}
if (minutes > 0)
{
// divide minutes by 2
int mid_minutes = (int)minutes / 2;
if(mid_minutes<10)
str = str + "0" + mid_minutes + ":";
else
str = str + "" + mid_minutes + ":";
}
else
{
str = str + "00:";
}
if (seconds > 0)
{
// divide seconds by 2
int mid_seconds = (int)seconds / 2;
if(mid_seconds<10)
str = str + "0" + mid_seconds + ":";
else
str = str + "" + mid_seconds + ":";
}
else
{
str = str + "00";
}
return str;
}

Grab 20 thumbnails from video starting from duration 00:01:00 and after every 15 seconds.

 

string outfile = m_handler.Grab_Multiple_Image(filename, _ffmpegpath, InputPath, OutputPath, 20, "00:01:00", "00:00:15", "jpg");

// This will generate 20 thumbnails starting from position 00:01:00.

©2007 - 2009, MediaSoft Pro Inc  | Site Map