Live Chat with Operator

Media Handler Pro: Grab single or multiple thumbnails from video

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

  • output thumbnail image format must be .jpg file.
  • width and height specified for thumbnail must be multiple of two.

Capture thumbnails feature in Media Handler Pro.

The following feature provided by Media Handler Pro component for grabbing single or multiple thumbnails or images from video.
Grab single thumbnail or image
  • Grab single thumbnail from any video format.
  • Grab single thumbnail in any image format. Recommend output is .jpg, .png.
  • Grab single thumbnail from any part 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 from in any specified numbers starting from any specified time duration till end of video. e.g grab 15 thumbs from video starting from 10th second of video and capture till at the end of video.
  • Grab multiple thumbnails in any specified size or in default size.
  • Media Handler Pro 5.0 or later support two modes for grabbing multiple thumbs.
  • i: ThumbMode : 0 , represent normal mode. (recommended for long length videos)
  • ii: ThumbMode : 1, represent fast mode. (work only in short video clips)

Sample Code: Media Handler Pro 5.0 or later (C# only)

Sample code in c# shows a ways to use Media Handler Pro 5.0 to grab single or multiple thumbs.

Grab thumbnails from video using .net media handler pro.

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

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 - 2012, mediasoftpro.com  | Site Map | Privacy Policy | Terms of Use