Skip to main content

Flash FLV Encoding

This page will help you publishing high quality flash flv videos and setting meta information to make it streamable on the web using media handler pro component in your .net, asp.net, c# and vb.net applications.

C# Sample Code

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

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();

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.

Example code below

_mhandler.FLVTOOLPATH = HttpContext.Current.Server.MapPath("~\\flvtool\\flvtool2.exe";

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();

Default FLV Publishing

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

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();

Click here for detail about retrieving information from video