How to generate Thumbnail using Mediatoolkit

Asked

Viewed 85 times

3

I need to generate a thumbnail from a video when climbing it to my application, I would like an explanation of how to use the package Mediatoolkit to do this, I thank you already.

1 answer

2


To install the package, I recommend downloading it by nuget, but this is matter of preference.

PM> Install-Package Mediatoolkit

After downloading and referencing the package in the project, it is possible to generate a Thumb using the method GetThumbnail() 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);
    }
}
  • Thank you very much for your attention, very simple code to understand. I’ll test it but I’m sure it will work, I’ll select it as the correct answer, thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.