Search code examples
c#asp.netvideo-thumbnails

How to capture thumbnail for video while uploading it in ASP.NET?


I want to know how to capture thumbnail for video while uploading it in ASP.NET ?


Solution

  • Well first of all, you will also need to convert it to MP4 which will work on everywhere. For that you can use ffmpeg tool,

    To Create Thumbnail,

    //Create Thumbs
    string thumbpath, thumbname;
    string thumbargs;
    string thumbre;
    thumbpath = AppDomain.CurrentDomain.BaseDirectory + "Video\\Thumb\\";
    thumbname = thumbpath + withoutext + "%d" + ".jpg";
    thumbargs = "-i " + inputfile + " -vframes 1 -ss 00:00:07 -s 150x150 " + thumbname;
    Process thumbproc = new Process();
    thumbproc = new Process();
    thumbproc.StartInfo.FileName = spath + "\\ffmpeg\\ffmpeg.exe";
    thumbproc.StartInfo.Arguments = thumbargs;
    thumbproc.StartInfo.UseShellExecute = false;
    thumbproc.StartInfo.CreateNoWindow = false;
    thumbproc.StartInfo.RedirectStandardOutput = false;
    try
    {
    thumbproc.Start();
    }
    catch (Exception ex)
    {
    Response.Write(ex.Message);
    }
    thumbproc.WaitForExit();
    thumbproc.Close();
    

    However, for more details about the code, see this link.

    http://ramcrishna.blogspot.com/2008/09/playing-videos-like-youtube-and.html

    And you will need to change paths according to your web application's path.