create thumbnail from video in asp.net

妖精的绣舞 提交于 2019-12-04 15:31:26
DigiOz Multimedia

I suggest using "DexterLib" library to do this. I have used this library to generate thumbnails of video clips in hosted environment, and it works like a charm.

Here is what you need.

  1. Add a reference to "DexterLib" library to your project.

  2. Add a reference to the following libraries:

    using System.Drawing.Imaging;
    using System.Runtime.InteropServices;
    using DexterLib;
    
  3. Use the following code to grab a frame and generate a thumbnail:

    try
    {
        MediaDetClass loMD = new MediaDetClass();
        loMD.Filename = lsServerPath;
        loMD.CurrentStream = 0;
        loMD.WriteBitmapBits(0, 150, 150, lsFBitmapName);
    
        System.Drawing.Image loImg = System.Drawing.Image.FromFile(lsFBitmapName);
        loImg.Save(lsFJpegName, ImageFormat.Jpeg);
        loImg.Dispose();
        System.IO.File.Delete(lsFBitmapName);
    }
    catch (Exception loEx)
    {
        // Means media not supported
    }
    

The "WriteBitmapBits" method takes in the "Stream Time, Width, Height and FileName" for your video in that order as input parameter which you then use to save the thumbnail as JPG. Let me know if you have any additional questions. If you want to see it in action you can take a look at an Open Source Portal Project I have here:

http://digioznetportal.svn.sourceforge.net/viewvc/digioznetportal/digioznetportal_1.1/DigiOz%20.NET%20Portal%201.1/trunk/

Click on "Download GNU Tarball" link to download the whole source code, then take a look at the "controls/VideoUpload.ascx.cs" and step through that code to see how it works.

I hope this helps.

Thanks, Pete

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!