Sam Saffron
Sam Saffron

Reputation: 131112

How do I get a Video Thumbnail in .Net?

I'm looking to implement a function that retrieves a single frame from an input video, so I can use it as a thumbnail.

Something along these lines should work:

// filename examples: "test.avi", "test.dvr-ms"
// position is from 0 to 100 percent (0.0 to 1.0)
// returns a bitmap
byte[] GetVideoThumbnail(string filename, float position)
{
}

Does anyone know how to do this in .Net 3.0?

The correct solution will be the "best" implementation of this function. Bonus points for avoiding selection of blank frames.

Upvotes: 30

Views: 39038

Answers (5)

Maciej
Maciej

Reputation: 10805

This is also worth to see:

http://www.codeproject.com/Articles/13237/Extract-Frames-from-Video-Files

Upvotes: 0

Sam Saffron
Sam Saffron

Reputation: 131112

I ended up rolling my own stand alone class (with the single method I described), the source can be viewed here. Media browser is GPL but I am happy for the code I wrote for that file to be Public Domain. Keep in mind it uses interop from the directshow.net project so you will have to clear that portion of the code with them.

This class will not work for DVR-MS files, you need to inject a direct show filter for those.

Upvotes: 10

Ahmad Behjati
Ahmad Behjati

Reputation: 556

1- Get latest version of ffmpeg.exe from : http://ffmpeg.arrozcru.org/builds/

2- Extract the file and copy ffmpeg.exe to your website

3- Use this Code:

Process ffmpeg;

string video;
string thumb;

video = Server.MapPath("first.avi");
thumb = Server.MapPath("frame.jpg");

ffmpeg = new Process();

ffmpeg.StartInfo.Arguments = " -i "+video+" -ss 00:00:07 -vframes 1 -f image2 -vcodec mjpeg "+thumb;
ffmpeg.StartInfo.FileName = Server.MapPath("ffmpeg.exe");
ffmpeg.Start();

Upvotes: 5

GuyWithDogs
GuyWithDogs

Reputation: 683

There are some libraries at www.mitov.com that may help. It's a generic wrapper for Directshow functionality, and I think one of the demos shows how to take a frame from a video file.

Upvotes: 0

Joel Martinez
Joel Martinez

Reputation: 47751

This project will do the trick for AVIs: http://www.codeproject.com/KB/audio-video/avifilewrapper.aspx

Anything other formats, you might look into directshow. There are a few projects that might help:
http://sourceforge.net/projects/directshownet/
http://code.google.com/p/slimdx/

Upvotes: 7

Related Questions