How to Generate Thumbnail from a Video in C# Dotnet Core.

We have been generating thumbnails from image and we all know how easy is this in todays world with some awesome libraries available to us .

But when coming to generate a thumbnail from a video in C# we are left with very limited option.

But to our rescue is a beautiful library Xabe.FFmpeg by tomaszzmuda

This Library does more of what you can expect.

To understand more. This Library is a Cross-platform wrapper for FFmpeg.

FFmpeg – A complete, cross-platform solution to record, convert and stream audio and video. To read more about it click here

Please Note: ffmpeg is required to be present in your machine to use this package.

Downloading FFmpeg

We can Download it directly from the website

OR

You can use a beautiful Download Package and download it in runtime when required.

Using Xabe.FFmpeg.DOWNLOADER

using Xabe.FFmpeg.Downloader;

await FFmpegDownloader.GetLatestVersion(FFmpegVersion.Official, @"c:\ffmpeg");

This will download the two files required to work with the above package. to the path you mentioned. In out case its c:\ffmpeg

USING Xabe.FFmpeg

Now you can just start using the library.

Set the Path for the package to find the executeables.

using Xabe.FFmpeg;

FFmpeg.SetExecutablesPath(@"c:\ffmpeg");

Now you can provide the video for with the thumbnail is to be generated.

using Xabe.FFmpeg;

var conversion = await FFmpeg.Conversions.FromSnippet.Snapshot(originPath, outputPath,TimeSpan.FromSeconds(0));
IConversionResult result = await conversion.Start();

And you are Done. You can now find the Thumbnail in the outputPath you mentioned. In case you want the image generated you can read as stream from the above path.

Thanks

Happy coding.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website with WordPress.com
Get started
%d bloggers like this: