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.
You can customize FLV video output by setting different properties of Media Handler Pro component. View component documentation for detail about properties related with flv encoding.
View examples below for generating flv files in c# and vb.net.
// Sample code for encoding any format video to flv format.
MediaHandler _mhandler = new MediaHandler();
string RootPath = Server.MapPath(Request.ApplicationPath);
// set required parameters
_mhandler.FFMPEGPath = HttpContext.Current.Server.MapPath("~\\ffmpeg\\ffmpeg.exe");
_mhandler.InputPath = RootPath + "\\contents\\videos";
_mhandler.OutputPath = RootPath + "\\contents\\flv";
_mhandler.FileName = "sample.mp4";
// set width and height of video
_mhandler.Width = 320;
_mhandler.Height = 240;
// set output filename of video
_mhandler.OutputFileName = "newtest";
// generate highest quality flv video, in this case video bitrate will no longer work.
_mhandler.MaxQuality = true;
// video and audio settings for flv video
_mhandler.Video_Bitrate = 360;
_mhandler.Audio_Bitrate = 64;
_mhandler.Audio_SamplingRate = 22050;
_mhandler.Channel = 1;
_mhandler.FrameRate = 24.2;
_mhandler.AspectRatio = 1.7777;
_mhandler.Deinterlace = true;
// restrict video to 10 seconds
_mhandler.Duration = "10";
// disable audio
_mhandler.DisableAudio = true;
// disable video
_mhandler.DisableVideo = true;
// post watermark on flv video
_mhandler.WaterMarkPath = RootPath + "\\contents\\watermark";
_mhandler.WaterMarkImage = "watermark.gif";
// view more options in component documentation.
// Encode FLV Video using Media Handler Pro version 3.0
string output = _mhandler.Encode_FLV();
// Encode FLV Video using Media Handler Pro version 4.0 or later
VideoInfo info = _mhandler.Encode_FLV();
// Check for errors
if (info.ErrorCode > 0)
{
Response.Write("Video processing failed, Error code " + info.ErrorCode + " generated");
return;
}
// Retrieve output information from VideoInfo Object. View Detail
// string output = _mediahandler.Convert_Media(filename, _ffmpegpath, InputPath, OutputPath, 320, 240, 360, 25, 64, 44100, "0", true);
The above function generate FLV video with the following characteristics
Note: Greater the video bitrate greater will be the quality and at same time greater will be the size of video and take more overhead at time of streaming.
// string output= _mediahandler.Convert_Media(filename, _ffmpegpath, InputPath, OutputPath, "320x240", 360, 25, 64, 44100, "0", true);
The following function generate FLV video with same characteristics as above one but it takes parameter differenetely. Instead of taking width and height of video separately, it takes as one parameter like "320x240".
Importan Note: Width and Height of video must be multiple of two otherwise encoding will not take place. e.g 321 is wrong as it is not multiple of two.
// string output = _mediahandler.Convert_Media(filename, _ffmpegpath, InputPath, OutputPath, "320x240", 64, 44100, "0", true);
This function generate FLV Video with highest quality by setting highest bitrate possible automatically. Although it creat video with highest quality but at the same time it increase the size of video almost double or more of original video. It takes the following parameters.
// string output = _mediahandler.Convert_Media(filename, _ffmpegpath, InputPath, OutputPath, 64, 44100, "0", true);
'
This function generate FLV video with default video size and with highest video quality. But also it generate video with almost double and more in size than original video.
// string output = _mediahandler.Convert_Media(filename, _ffmpegpath, InputPath, OutputPath, 360, 32, 22050, "0", true);
This function generate FLV Video with default video size as original video. Rest is same as describe above.
// Generate two minutes video from 6 minute video
Use the follwing function to generate two minutes video from 6 minute source video.
// string output= _mediahandler.Convert_Media(filename, _ffmpegpath, InputPath, OutputPath, "320x240", 360, 25, 64, 44100, "120", true);
where "120" represent 120 seconds means 2 minutes
or
// string output= _mediahandler.Convert_Media(filename, _ffmpegpath, InputPath, OutputPath, "320x240", 360, 25, 64, 44100, "00:02:00", true);
where "00:02:00 represents two minutes as hh:mm:ss
If you feel that the above functions does't meet with your requirement and also you have lots of experience in ffmpeg commands. then their is another approach for generating FLV video using ffmpeg custom commands.
e.g the following function generate FLV video from any video format using Execute_FFMPEG(--param--) command.
string outfile = m_handler.Execute_FFMPEG(_ffmpegpath, "-i \"C:\\my videos\\sample.avi\" -f flv -y \"C:\\my videos\\sample.flv\"");
Access ffmpeg documentation for more help about using ffmpeg commands or contact us for more help and support.