ASP.NET MPG Encoding

This page provide media handler pro sample codes which will help you in publishing mpg videos from other formats in your asp.net, c# and vb.net applications.

For latest codes and discussion please visit media handler pro discussion forum section

C# Sample Code

Sample code for encoding video to .mpg video using Media Handler Pro version 3.0.

You can encode videos to mpg format either using special function Encode_MPG() or using general function Process(). We recommend using Process() function as it provide much more control and flexibility.

// Sample code for encoding any format video to mpg format.
MediaHandler _mhandler = new MediaHandler();
// required properties
string RootPath = Server.MapPath(Request.ApplicationPath);
_mhandler.FFMPEGPath = HttpContext.Current.Server.MapPath("~\\ffmpeg\\ffmpeg.exe");
_mhandler.InputPath = RootPath + "\\contents\\video";
_mhandler.OutputPath = RootPath + "\\contents\\mpg";
_mhandler.FileName = "sample.mp4";
// optional output filename
_mhandler.OutputFileName = "sample.mpg";
// loading automatic video and audio settings for avi video.
view detail about TargetFileType in documentation.
_mhandler.TargetFileType = "pal-vcd";
// optional video width and height settings
_mhandler.Width = 320;
_mhandler.Height = 240;
// posting watermark on mpg video, view detail in watermark
section
_mhandler.WaterMarkPath = RootPath + "\\contents\\watermark";
_mhandler.WaterMarkImage = "watermark.gif";
// Encode video to FLV format in Media Handler Pro version 3.0 
string output = _mhandler.Encode_MPG();
// Encode Video to MPG format in Media Handler Pro version 4.0 or later
VideoInfo info = _mhandler.Encode_MPG();
// Check for errors
if (info.ErrorCode > 0)
{
Response.Write("Video processing failed, Error code " + info.ErrorCode + " generated");
return;
}

Click here for detail about retrieving information from video