FLV - Flash streaming in ASP.NET

Streaming is based upon a new video file format FLV which is introduced in Flash 6, 7 which separates the streamable content and the Flash movie. The results are a very compact Flash movie acting as a multimedia player and a container for streamable content, from which the Flash movie loads a stream.

Media Handler Pro act as ASP.NET FLV Convert and Encoder to encode any format video including wmv, avi, mp4, 3gp, mpg, mov, mpe, divx and others into FLV format in order to stream on the web. You can generate different outputs of FLV Video by providing different parameters to Media Handler Pro Convert_Media() function. It means you can control FLV video by size, quality and bandwidth easily.

You can find more information about FLV parameters by clicking here.

Here you can find complete information about how to use Media Handler Pro Convert_Media() and Execute_FFMPEG() functions to encode any format video to FLV format with different types of outputs concerning FLV video size, quality and bandwidth.

FLV Encoding with Media Handler Pro version 3.0 .

Sample code for encoding video to flv using Media Handler Pro version 3.0. For older version please view sample codes below.
Using Encode_FLV() function

// 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";

// Call Encode_FLV() to start encoding flv video

string output = _mhandler.Encode_FLV();

// display output and extract useful information from it.

// in case or error code see error code section for more detail.

FLV - Flash streaming through Media Handler Pro.

There are two types of approaches or features provided by Media Handler Pro to encode videos to FLV Format. One is direct approach means you can use Convert_Media() function to encode videos to FLV format by providing different types of parameters. You can easily control encoded FLV video by quality, size and bandwidth. Another approach is to use Execute_FFMPEG() function to pass ffmpeg command according to your own requirement to encode any format video to FLV video. You can use this approach to execute any type of ffmpeg command to control the behaviour of FLV video but this approach requires strong knowlege of FFMPEG commands and their usage.
Direct Approach - Using Convert_Media() function

// 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

  • width : 320px
  • heigh : 240px
  • video bitrate : 360k
  • video frame rate : 25 fps
  • audio bitrate : 64k
  • audio sampling rate : 44100
  • duration : "0" means no limit otherwise put duration e.g "00:02:00" or in seconds "120". both represent two minutes.
  • deinterlace : true

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.

  • Video Size : "widthxheight" must be multiple of 2
  • Audio Bitrate : 64 k
  • Audio Sampling Rate : 44100
  • Duration : "0" - nolimit
  • Deinterlace : true

 

// 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

 


Indirect Approach - Using Execute_FFMPEG() function

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.


©2007 - 2008, MediaSoft Pro Inc  | Site Map