Here you can learn how to get single or multiple thumbnails from any video format using ASP.NET Media Handler Pro.
Grab thumbnail from video using Media Handler Pro version 3.0. Note for using old version of Media Handler Pro check examples 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();
// 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;
}
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.