Hi, I didn't try it with ASP yet, but MediaDetector should be the right way for you. If you don't won't to use
a 3rd library, you'll almost have no other options than using DShow or DirectX.
Something like this in a BackgroundWorker:
FileInfo finfo = new FileInfo(@"PATH TO TESTFILE");
if(string.Compare(finfo.Extension, ".avi", true) == 0 || string.Compare(finfo.Extension, ".mpg", true) == 0 || string.Compare(finfo.Extension, ".wmv", true) == 0)
{
string thumb_path = finfo.FullName + ".jpg";
if (File.Exists(thumb_path) != true)
{
MediaDetector capture_thumb = new MediaDetector();
capture_thumb.LoadMedia(finfo.FullName);
int width = 128;
int height = width;
int stride = width / 8;
byte[] pixels = new byte[height * width];
BitmapPalette myPalette = BitmapPalettes.Halftone256;
BitmapSource image =
BitmapSource.Create(
width,
height,
96,
96,
PixelFormats.Indexed1,
myPalette,
pixels,
stride);
Stream stream = new FileStream(finfo.FullName + ".jpg", FileMode.Create);
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.FlipHorizontal = false;
encoder.FlipVertical = false;
encoder.QualityLevel = 80;
encoder.Frames.Add(BitmapFrame.Create(capture_thumb.GetImage(new TimeSpan(0, 0, 30))));
encoder.Save(stream);
}
}
Cheers,
Bjoern