One of the typical tasks where Media Processor Add-on can be useful is creating video thumbnails. For example, if you want to create a collection of your video files, for each of them you can store a small preview image along with other descriptive data. Later these screenshots can be displayed while you browse the collection.
The function that will create thumbnails should perform the following operations:
The following code snippets show how this can be done.
Public Sub CreateVideoThumbnail(ByVal inputFilename As String, ByVal _
outputBaseFilename As String)
Try
'Create the reader
Dim reader As IFormatReader = MediaFormatManager.CreateFormatReader _
(inputFilename)
'Get the frame
If reader.FrameCount < 1 Then
Console.WriteLine("File contains no frames.")
Return
End If
Dim index As Int32 = reader.FrameCount / 2
Dim frame As IFrame = reader.LoadFrame(index)
'Save the frame using GetThumbnail()
Dim image1 As Aurigma.GraphicsMill.Bitmap = New _
Aurigma.GraphicsMill.Bitmap
frame.GetThumbnail(image1, 160, 120)
image1.Save(outputBaseFilename + "1.gif")
image1.Dispose()
'Save the frame using GetBitmap() and Resize
Dim image2 As Aurigma.GraphicsMill.Bitmap = New _
Aurigma.GraphicsMill.Bitmap
frame.GetBitmap(image2)
Dim transformation As Resize = New Resize(160, 120)
transformation.ApplyTransform(image2)
image2.Save(outputBaseFilename + "2.gif")
image2.Dispose()
reader.Dispose()
Catch ex As Exception
Console.WriteLine(ex)
End Try
End Sub
public static void CreateVideoThumbnail(string inputFilename,
string outputBaseFilename)
{
try
{
//Create the reader
IFormatReader reader = MediaFormatManager.CreateFormatReader(inputFilename);
//Get the frame
if (reader.FrameCount < 1)
{
Console.WriteLine("File contains no frames.");
return;
}
Int32 index = reader.FrameCount / 2;
IFrame frame = reader.LoadFrame(index);
//Save the frame using GetThumbnail()
Aurigma.GraphicsMill.Bitmap image1 = new Aurigma.GraphicsMill.Bitmap();
frame.GetThumbnail(image1, 160, 120);
image1.Save(outputBaseFilename + @"1.gif");
image1.Dispose();
//Save the frame using GetBitmap() and Resize
Aurigma.GraphicsMill.Bitmap image2 = new Aurigma.GraphicsMill.Bitmap();
frame.GetBitmap(image2);
Resize transformation = new Resize(160, 120);
transformation.ApplyTransform(image2);
image2.Save(outputBaseFilename + @"2.gif");
image2.Dispose();
reader.Dispose();
}
catch (System.Exception ex)
{
Console.WriteLine(ex);
}
}