How to create a thumbnail for video in Asp.net


string thumbpath, thumbname;
string thumbargs;
string thumbre;
thumbpath = AppDomain.CurrentDomain.BaseDirectory + “Video\\Thumb\\”;
string dbthumbname = thumbpath + vid_id +”1.jpg”;
Session[“dbthumbname”] = dbthumbname.ToString();
thumbname = thumbpath + vid_id + “%d” + “.jpg”;
Session[“thumbname”] = vid_id + “1” + “.jpg”;
thumbargs = “-i ” + inputfile + ” -vframes 1 -ss 00:00:07 -s 150×150 ” + 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();
File.Delete(inputfile);
Savedetails(duration);
RegularExpressionValidator2.Visible = false;
lblmsg.Text = “Video Uploaded Successfully”;
lblmsg.Visible = true;
//hyp.NavigateUrl = “Play.aspx”;
}
}
private void Savedetails(string duration)
{
DateTime dt = new DateTime();
dt = DateTime.Now;
string filename, imgname;
filename = Session[“outputfile”].ToString();
imgname = Session[“thumbname”].ToString();
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[“TestConnectionString”].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand(“insert into videos values(‘” + Convert.ToString(Session[“vidid”]) + “‘,'” + Convert.ToString(Session[“outputfile1”]) + “‘,'” + Convert.ToString(Session[“dbthumbname”]) + “‘,'” + txttitle.Text + “‘,'” + Convert.ToString(Session[“uname”]) + “‘,'” + dt + “‘,'” + txtkeywords.Text.Trim() + “‘,'” + DropDownList1.SelectedItem.Text + “‘,'” + duration + “‘)”, con);
cmd.ExecuteNonQuery();
cmd.Dispose();
con.Close();
}

string thumbpath, thumbname;

string thumbargs;

string thumbre;

thumbpath = AppDomain.CurrentDomain.BaseDirectory + “Video\\Thumb\\”;

string dbthumbname = thumbpath + vid_id +”1.jpg”;

Session[“dbthumbname”] = dbthumbname.ToString();

thumbname = thumbpath + vid_id + “%d” + “.jpg”;

Session[“thumbname”] = vid_id + “1” + “.jpg”;

thumbargs = “-i ” + inputfile + ” -vframes 1 -ss 00:00:07 -s 150×150 ” + 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();

File.Delete(inputfile);

Savedetails(duration);

RegularExpressionValidator2.Visible = false;

lblmsg.Text = “Video Uploaded Successfully”;

lblmsg.Visible = true;

//hyp.NavigateUrl = “Play.aspx”;

}

}

private void Savedetails(string duration)

{

DateTime dt = new DateTime();

dt = DateTime.Now;

string filename, imgname;

filename = Session[“outputfile”].ToString();

imgname = Session[“thumbname”].ToString();

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[“TestConnectionString”].ConnectionString);

con.Open();

SqlCommand cmd = new SqlCommand(“insert into videos values(‘” + Convert.ToString(Session[“vidid”]) + “‘,'” + Convert.ToString(Session[“outputfile1”]) + “‘,'” + Convert.ToString(Session[“dbthumbname”]) + “‘,'” + txttitle.Text + “‘,'” + Convert.ToString(Session[“uname”]) + “‘,'” + dt + “‘,'” + txtkeywords.Text.Trim() + “‘,'” + DropDownList1.SelectedItem.Text + “‘,'” + duration + “‘)”, con);

cmd.ExecuteNonQuery();

cmd.Dispose();

con.Close();

}

Advertisements

Thanks a lot for visiting this site .. Please leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s