I need to generate a thumbnail from a video when uploading it to my application, I would like an explanation of how to use the MediaToolKit to do this, thank you in advance.
I need to generate a thumbnail from a video when uploading it to my application, I would like an explanation of how to use the MediaToolKit to do this, thank you in advance.
To install the package, I recommend downloading it through nuget, but this is a matter of preference.
PM > Install-Package MediaToolkit
After downloading and referencing the package in the project, you can generate a thumb using the GetThumbnail()
of class Engine
using MediaToolkit;
using MediaToolkit.Model;
using MediaToolkit.Options;
/* Resto do código */
private void SalvarThumb(string caminhoVideo)
{
var caminhoThumb = Path.Combine("C:\DestinoThumb", "nomeArquivo.jpg");
var inputFile = new MediaFile { Filename = caminhoVideo };
var outputFile = new MediaFile { Filename = thumbPath };
using (var engine = new Engine())
{
engine.GetMetadata(inputFile);
// A propriedade Seek define em qual momento do vídeo você pretende tirar o "snapshot"
var options = new ConversionOptions { Seek = TimeSpan.FromSeconds(05) };
engine.GetThumbnail(inputFile, outputFile, options);
}
}