Home > Media Handler Pro > Publish FLV Video

FLV Video Encoding Using ASP.NET

ASP.NET Media Handler Pro act as ASP.NET FLV Converter and Encoder to encode any format video including wmv, avi, mp4, 3gp, mpg, mov, mpe, divx and others into FLV format, prepare it for web streaming and retrieve useful information from it.

This topic will provide information, sample code that can help you to publish any format videos to flv format using normal and libx264 codecs.

C# Sample Code

Sample code below will generate flv video using libx264 codec and libx264-baseline.ffpreset preset file.

Note: In case you are using free version of media handler pro, just comment properties like parameters if not supported.

.

MediaHandler _mhandler = new MediaHandler();
string RootPath = Server.MapPath(Request.ApplicationPath);
_mhandler.FFMPEGPath = HttpContext.Current.Server.MapPath("~\\ffmpeg\\ffmpeg.exe");
_mhandler.InputPath = RootPath + "\\contents\\original";
_mhandler.OutputPath = RootPath + "\\contents\\flv";
_mhandler.FileName = "Wildlife.wmv";
string presetpath = RootPath + "\\ffmpeg\\presets\\libx264-baseline.ffpreset";
_mhandler.OutputExtension = ".flv";
_mhandler.OutputFileName = "wildlife";
_mhandler.VCodec = "libx264";
_mhandler.Parameters = " -s 320x240 -fpre " + presetpath + "";
_mhandler.Video_Bitrate = 500;
_mhandler.Audio_SamplingRate = 44100;
_mhandler.Audio_Bitrate = 128;
_mhandler.FrameRate = 25;
VideoInfo info = _mhandler.Process();
Validation Check

This check will make sure whether video is successfully published or failed due to any reason returned through error code.

if (info.ErrorCode > 0)
{
Response.Write("Video processing failed, Error code " + info.ErrorCode + " generated");
Response.Write("<br />" + info.FFMPEGOutput + "");
return;
}

Add Meta Information to FLV Video

In order to stream flv video properly on the web, you must add meta information. ASP.NET Media Handler Pro uses FLVTool to setting meta information which is published through FFMPEG utility.

If flvtool path is set before video publishing, asp.net media handler pro will add meta information after video conversion automatically.

Sample code below

_mhandler.FLVTOOLPATH = HttpContext.Current.Server.MapPath("~\\flvtool\\flvtool2.exe");
or you can set meta information manually to any flv video using code shown below.
_mhandler.FLVToolPath = HttpContext.Current.Server.MapPath("~\\flvtool\\flvtool2.exe");
_mhandler.InputPath = RootPath + "\\contents\\flv";
_mhandler.FileName = "wildlife.flv";
_mhandler.Set_Buffering();

Publish FLV Video with normal codec.

Below sample code will publish flv video without using libx264 codec and preset file.

Sample code below

MediaHandler _mhandler = new MediaHandler();
string RootPath = Server.MapPath(Request.ApplicationPath);
_mhandler.FFMPEGPath = HttpContext.Current.Server.MapPath("~\\ffmpeg\\ffmpeg.exe");
_mhandler.InputPath = RootPath + "\\contents\\original";
_mhandler.OutputPath = RootPath + "\\contents\\flv";
_mhandler.FileName = "Wildlife.wmv";
_mhandler.OutputExtension = ".flv";
_mhandler.OutputFileName = "wildlife_normal";
_mhandler.Video_Bitrate = 500;
_mhandler.Audio_SamplingRate = 44100;
_mhandler.Audio_Bitrate = 128;
_mhandler.FrameRate = 25;
_mhandler.Force = "flv";
VideoInfo info = _mhandler.Process();

Retrieve Video Information

Once published asp.net media handler pro will returned source and published video information as VideoInfo object. Sample information shown below

StringBuilder str = new StringBuilder();
str.Append("File Name= " + info.FileName + "<br />");
str.Append("Video Duration= " + info.Duration + "<br />");
str.Append("Video Duration in Seconds= " + info.Duration_Sec + "<br />");
// Input values
str.Append("<strong>Input Values</strong><br />");
str.Append("Video Codec= " + info.Input_Vcodec + "<br />");
str.Append("Audio Codec= " + info.Input_Acodec + "<br />");
str.Append("Video Bitrate= " + info.Input_Video_Bitrate + "<br />");
str.Append("Audio Bitrate= " + info.Input_Audio_Bitrate + "<br />");
str.Append("Audio Sampling Rate= " + info.Input_SamplingRate + "<br />");
str.Append("Audio Channel= " + info.Input_Channel + "<br />");
str.Append("Width= " + info.Input_Width + "<br />");
str.Append("Height= " + info.Input_Height + "<br />");
str.Append("Video FrameRate= " + info.Input_FrameRate + "<br />");
// Output values
str.Append("<strong>Output Values</strong><br />");
str.Append("Video Codec= " + info.Vcodec + "<br />");
str.Append("Audio Codec= " + info.Acodec + "<br />");
str.Append("Video Bitrate= " + info.Video_Bitrate + "<br />");
str.Append("Audio Bitrate= " + info.Audio_Bitrate + "<br />");
str.Append("Audio Sampling Rate= " + info.SamplingRate + "<br />");
str.Append("Audio Channel= " + info.Channel + "<br />");
str.Append("Width= " + info.Width + "<br />");
str.Append("Height= " + info.Height + "<br />");
str.Append("Video FrameRate= " + info.FrameRate + "<br />");
str.Append(".................................<br />");
str.Append("FFMPEG Output:" + info.FFMPEGOutput + "");
str.Append("Error Code= " + info.ErrorCode + "<br />");
Response.Write(str.ToString());
© 2007 - 2012, mediasoftpro.com  | Site Map | Privacy Policy | Terms of Use