You can use .NET Media Handler Pro component to grab single or multiple thumbs from video in real time using asp.net or other .net applications.
Media Handler Pro ver 5.0 provide more flexible and fast way to grab specified number of thumbs from video starting from any specified time interval to end of video.
For best output we recommend that
Sample code in c# shows a ways to use Media Handler Pro 5.0 to grab single or multiple thumbs.
// required properties.
MediaHandler _mhandler = new MediaHandler();
string RootPath = Server.MapPath(Request.ApplicationPath);
_mhandler.FFMPEGPath = HttpContext.Current.Server.MapPath("~\\ffmpeg\\ffmpeg.exe");
_mhandler.InputPath = RootPath + "\\contents\\source";
_mhandler.OutputPath = RootPath + "\\contents\\output";
// grab single thumbnail.
_mhandler.FileName = "Sample.avi";
_mhandler.Frame_Time = "10";
//OR
_mhandler.Thumb_Start_Position = 10;
_mhandler.Image_Format = "jpg";
_mhandler.VCodec = "image2"; // optional
_mhandler.ImageName = "sample.jpg";
_mhandler.Width = 160;
_mhandler.Height = 120;
VideoInfo info = _mhandler.Grab_Thumb();
if (info.ErrorCode > 0)
{
Response.Write("Error occured while grabbing thumbs from video");
}
// grab multiple thumbs using "normal mode" recommended approach.
string thumb_start_index = "sample_";
_mhandler.FileName = "sample.avi";
_mhandler.Image_Format = "jpg";
_mhandler.VCodec = "image2";
_mhandler.ImageName = thumb_start_index;
_mhandler.Multiple_Thumbs = true;
_mhandler.ThumbMode = 0;
_mhandler.No_Of_Thumbs = 15;
_mhandler.Thumb_Start_Position = 10; // start grabbing thumbs from 10th second
_mhandler.Width = 160;
_mhandler.Height = 120;
VideoInfo info = _mhandler.Grab_Thumb();
if (info.ErrorCode > 0)
{
Response.Write("Error occured while grabbing thumbs from video");
}
// grab multiple thumbs using "fast mode" work in small clips.
string thumb_start_index = "Sample_";
_mhandler.FileName = "sample.avi";
_mhandler.Image_Format = "jpg";
_mhandler.VCodec = "image2";
_mhandler.ImageName = thumb_start_index;
_mhandler.Multiple_Thumbs = true;
_mhandler.ThumbMode = 1; // fast mode
_mhandler.No_Of_Thumbs = 15;
_mhandler.Thumb_Start_Position = 10; // start grabbing thumbs from 10th second
_mhandler.Auto_Transition_Time = true;
_mhandler.Width = 160;
_mhandler.Height = 120;
VideoInfo info = _mhandler.Grab_Thumb();
if (info.ErrorCode > 0)
{
Response.Write("Error occured while grabbing thumbs from video");
}
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.