1

The path of video(extension.wmv,.avi) is stored in SQL Server. And I have to create thumbnail and dispaly it on ASPX page.

Please share its code, if any body know this.

Thanks in Advance

George Johnston
  • 31,652
  • 27
  • 127
  • 172
SUJEET
  • 121
  • 5
  • 15

2 Answers2

0

I have some bit of code for generating thumbnail video.

for that you need to have third party exe named "ffmpeg.exe" which is available for free. you can download from here

Now i have create function below which generate thumbnail video from original video. you can change variable according to your requirement.

private bool SaveVideo(FileUpload fupload)
{

    string VideoResolutionWidth = "400" ; //define video res. width
    string VideoResolutionHeight = "280";  //define video res. height
    string VideoThumbWidth = "100";//define jpg res. width
    string VideoThumbHeight = "100"; //define jpg res. height

    string VideoLocation = HttpContext.Current.Server.MapPath("~/ConverterFolder/Video/");
    string ConverterPath = HttpContext.Current.Server.MapPath("~/ConverterFolder/");
    String LargeFileName = "TestVideo.wmv"; // Thumb Video file name
    string ThumbFileName= "Testvideo.jpg";

    // Save Original video file first

    if (fupload.PostedFile.FileName != "")
    {
        fupload.PostedFile.SaveAs(ConverterPath + "\\" + System.IO.Path.GetFileName(fupload.PostedFile.FileName.Replace(" ", "_")));
    }

    if (System.IO.File.Exists(ConverterPath + "\\" + System.IO.Path.GetFileName(fupload.PostedFile.FileName.Replace(" ", "_"))))
    {
        string inipath = ConverterPath;
        string flvCMD, flvArg;
        string a_res_width, a_res_height, a_audioRate, a_frameRate, i_res_width, i_res_height;

        a_res_width = VideoResolutionWidth;
        a_res_height = VideoResolutionHeight;
          i_res_width = VideoThumbWidth;
        i_res_height = VideoThumbHeight;

        a_audioRate = "22050";
        a_frameRate = "15";

        string VideoThumbResolution = i_res_width + "x" + i_res_height;
        string VideoResolution = a_res_width + "x" + a_res_height;           
        String videoPATH = VideoLocation +  "\\" + LargeFileName.Replace(" ", "_");

        flvCMD = ConverterPath + "ffmpeg.exe";
        flvArg = "-i " + ConverterPath + "\\" + System.IO.Path.GetFileName(fupload.PostedFile.FileName.Replace(" ", "_")) + " -s " + VideoResolution + " -r " + a_frameRate + " -b 7500000 -ar " + a_audioRate + "  -ab 48 " + videoPATH;


        try
        {
            Process process = new Process();
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError = true;
            process.StartInfo.CreateNoWindow = true;
            process.StartInfo.FileName = flvCMD;
            process.StartInfo.Arguments = flvArg;
            process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

            process.Start();
            string output = process.StandardOutput.ReadToEnd();
            process.Close();
            process.Dispose();

            if (System.IO.File.Exists(videoPATH))
            {

                Process process1 = new Process();
                process1.StartInfo.UseShellExecute = false;
                process1.StartInfo.RedirectStandardOutput = true;
                process1.StartInfo.RedirectStandardError = true;
                process1.StartInfo.CreateNoWindow = true;
                process1.StartInfo.FileName = flvCMD;
                process1.StartInfo.Arguments = "-i " + ConverterPath + "\\" + System.IO.Path.GetFileName(fupload.PostedFile.FileName.Replace(" ", "_")) + " -an -ss 00:00:01 -r 1 -vframes 1 -s " + VideoThumbResolution + " -f mjpeg -y " + VideoLocation "\\" + ThumbFileName;
                process1.Start();
                string outputMeta1 = process1.StandardOutput.ReadToEnd();
                process1.Close();
                process1.Dispose();
            }
            else
            {
                return false;
            }
        }
        catch (Exception)
        {

        }


    }
    return true;
}

Hope this will help you. happy coding....

Prakash Patani
  • 547
  • 4
  • 8