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 in Media Handler Pro.

The following features provided by Media Handler Pro for getting single or multiple thumbnails or images from videos.
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 image format, recommended jpg, png.
  • Grab multiple thumbnails or images in any specified numbers. e.g No_of_thumbs=10 means grab 10 thumbnails from video.
  • Grab multiple thumbnails or images from any specified time interval. e.g Start_Time="00:00:10" means start grabbing or capturing thumbnails from 10th second of video.
  • Grab multiple thumbnails or images after every specified time interval e.g Thumb_Interval="00:00:15" grab thumbnail or image after every 15th second of video from start_time to end of video.
  • Grab multiple thumbnails in any specified size or in default size.

Media Handler Pro Version 3.0 Example (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.

Note new component can only grab one thumbnail at a time. Due to some bugs grabbing multiple thumbnail feature has been removed in new version.

Grab thumbnail from middle of video

// 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";

_mhandler.Image_Format = "jpg";
_mhandler.ImageName = "sample.jpg";
_mhandler.Frame_Time = mid_duration;
_mhandler.Width = 150;
_mhandler.Height = 150;
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 - 2008, MediaSoft Pro Inc  | Site Map