7

Is it possible to create a thumbnail image of a video in C# (like the first frame)?

Little update: I'll need a thumbnail image of an FLV video in C# since I'm using Flex to show video's. And yes, links to some libraries would be useful.

Lieven Cardoen
  • 25,140
  • 52
  • 153
  • 244

3 Answers3

7

I can think of two options off the top of my head:

  1. Use an external tool, like ffmpeg, to generate thumbnails. This is probably the most commonly implemented solution to this problem.
  2. Parse the FLV file and only send the file only to the end of the first I Frame. (You can find the parsing logic in code that allows you to seek into the middle of an FLV by time mark.
Stu Thompson
  • 38,370
  • 19
  • 110
  • 156
  • FFMPEG is the only solution I could find. There are some .NET libraries out there that provide a managed wrapper around FFMPEG, but I couldn't find any documentation on how to use them. I'm interested to hear what solution you come up with! – Kevin Babcock Nov 12 '09 at 15:57
  • I just shell out to ffmpeg and parse the output. It works fine for me and is not as complex or hacky as it might sound. I've read about the C API to ffmpeg, but that seems like too much effort. – Stu Thompson Nov 12 '09 at 16:50
4

There are Open Source libraries you can use to do this. Check out OpenCVDotNet, a managed .NET wrapper for OpenCV, a "computer vision" library. Here's a link to a tutorial you may find useful.

Kevin Babcock
  • 10,187
  • 19
  • 69
  • 89
  • My first impression is that it only supports avi... and I'll need flv's to be supported. But I'll have to check this to be sure. – Lieven Cardoen Nov 04 '09 at 17:03
1

This works:

ShellFile thumbNail = ShellFile.FromFilePath(<fullpath and filename>);
Bitmap thumbSmall = thumbNail.Thumbnail.MediumBitmap;
Bitmap thumbLarge = thumbNail.Thumbnail.LargeBitmap;
videoThumb_Small.Images.Add(thumbSmall);
videoThumb_Large.Images.Add(thumbLarge);

where 'videoThumb_?????' = ImageList (where to control size of the image to display again). Slow as hell when searching different MIME formats, but fast enough with same types. Needs:

using Microsoft.WindowsAPICodePack.Shell;
using Microsoft.WindowsAPICodePack;

and you can get Microsoft.WindowsAPICodePack from nuget package with same name. As for FFMpeg, Vlc.Dotnet or aXMediaPlayer(WMP) they all suck as far I've tested(Vlc doesn't even work as it should, FFmpeg again needs 500 million lines before you get same result and aXMediaPlayer well, heh) them beside that's Windows native.

Example, if you're using ListView with something like subitems even:

for(int mememe = 0; mememe < stuff_counter; mememe++)
{
listview1.Items.Add("strings", mememe).SubItems.Add("strings" + mememe.ToString());
}

Would then read the correct index number from ImageList

ITK
  • 163
  • 9