Your Ad Here

FFMPEG in Csharp

What is FFMPEG ?
This is a likely question one would ask . Well FFMPEG is an application which is used to
convert one video format to another from the code behind .In the following article , I will show
you how .

What must our application contain?
User can upload file ( here- .avi) which will be saved and converted to a .flv file with a thumbnail. This is pretty Useful . It will something like youtube .

Live Demo ?
The get the live demo please visit youtube or any video sharing website OR download the code and run on loacalhost.

Source Code : DOWNLOAD THE CODE

Default.aspx contains only 2 buttons . Thats all . the button click events are shown in the Csharp file below . Download the code to get the the file ffmpeg.exe

Default.aspx.cs Code :
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Diagnostics;
// by Dotnetsnppets.co.cc
//Author Vaibhav Maheshwari
//Do Not Copy , Plz
//Protected By CopyScape ....

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{ // preview frame

Process ffmpeg; // creating process
string video;
string thumb;
video = Page.MapPath("video.flv"); // setting video input name with path
thumb = Page.MapPath("") + "\\frame.jpg"; // thumb name with path !
ffmpeg = new Process();
ffmpeg.StartInfo.Arguments = " -i \"" + video + "\" -s 108*180 -vframes 1 -f image2 -vcodec mjpeg \"" + thumb + "\""; // arguments !
ffmpeg.StartInfo.FileName = Page.MapPath("ffmpeg.exe");
ffmpeg.Start(); // start !
}
protected void convert_Click(object sender, EventArgs e)
{
Process ffmpeg; // creating process
string video;
string mpg;
video = Page.MapPath("split.avi"); // setting video input name with path
mpg = Page.MapPath("") + "\\video.flv"; // thumb name with path !
ffmpeg = new Process();
ffmpeg.StartInfo.Arguments = " -i " + video + " -s 480*360 -deinterlace -ab 32 -r 15 -ar 22050 -ac 1 " + mpg; // arguments !
ffmpeg.StartInfo.FileName = Page.MapPath("ffmpeg.exe");

ffmpeg.Start(); // start !
ffmpeg.WaitForExit();
ffmpeg.Close();
}

}

0 comments:

Post a Comment