ASP.NET Media Handler Pro can be use to encode any format video to mp4, m4v and m4a audio formats in order to play on variety of hardwares including ipod, iphone, web, desktop computers, playstation, xbox 360 and others.
View detail about encoding videos to mp4, m4v and m4a format below with examples both in c# and vb.net.
All examples shown below is related with ASP.NET Media Handler Pro 3.0 or later. For more information contact us.
// Sample code for encoding any format video to mp4 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\\mp4";
_mhandler.FileName = "sample.mpg";
// optional output filename
_mhandler.OutputFileName = "sample.mp4";
// setting video related properties, required in case of mp4 video otherwise may result in failure of video encoding.
_mhandler.FrameRate = 29.97;
_mhandler.Video_Bitrate = 786;
_mhandler.Audio_Bitrate = 64;
_mhandler.Audio_SamplingRate = 24000;
// generate highest quality mp4 video, note by making this option true, video bitrate will no longer work.
_mhandler.MaxQuality = true;
// optional video width and height settings
_mhandler.Width = 320;
_mhandler.Height = 240;
// optional video and audio codec settings, make sure it is compatible with mp4 video otherwise result in failure of video encoding.
_mhandler.ACodec = "libfaac";
_mhandler.VCodec = "mpeg4";
// posting watermark on mp4 video, view detail in watermark section
_mhandler.WaterMarkPath = RootPath + "\\contents\\watermark";
_mhandler.WaterMarkImage = "watermark.gif";
// view more options in component documentation.
// Encode MP4 Video using Media Handler Pro version 3.0
string output = _mhandler.Encode_MP4();
// Encode MP4 Video using Media Handler Pro version 4.0 or later
VideoInfo info = _mhandler.Encode_MP4();
// 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
// Sample code for encoding any format video to m4v 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\\mp4";
_mhandler.FileName = "sample.mpg";
// optional output filename
_mhandler.OutputFileName = "sample.m4v";
// setting video related properties, required in case of mp4, m4v, m4a video otherwise may result in failure of video encoding.
_mhandler.FrameRate = 29.97;
_mhandler.Video_Bitrate = 786;
_mhandler.Audio_Bitrate = 64;
_mhandler.Audio_SamplingRate = 24000;
// generate highest quality mp4 video, note by making this option true, video bitrate will no longer work.
_mhandler.MaxQuality = true;
// optional video width and height settings
_mhandler.Width = 320;
_mhandler.Height = 240;
// optional video and audio codec settings, make sure it is compatible with mp4 video otherwise result in failure of video encoding.
_mhandler.ACodec = "libfaac";
_mhandler.VCodec = "mpeg4";
// posting watermark on m4v video, view detail in watermark section
_mhandler.WaterMarkPath = RootPath + "\\contents\\watermark";
_mhandler.WaterMarkImage = "watermark.gif";
// view more options in component documentation.
// Encode M4V Video using Media Handler Pro version 3.0
string output = _mhandler.Encode_M4V();
// Encode M4V Video using Media Handler Pro version 4.0 or later
VideoInfo info = _mhandler.Encode_M4V();
// 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
// Sample code for encoding any format video to m4a 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\\mpa";
_mhandler.FileName = "sample.mpg";
// optional output filename
_mhandler.OutputFileName = "sample.mpa";
// setting audio related properties, required in case of mp4, m4v, m4a video otherwise may result in failure of video encoding.
_mhandler.Audio_Bitrate = 64;
_mhandler.Audio_SamplingRate = 24000;
// optional audio codec settings, make sure it is compatible with mp4 video otherwise result in failure of video encoding.
_mhandler.ACodec = "libfaac";
// view more options in component documentation.
// Encode M4A Audio using Media Handler Pro version 3.0
string output = _mhandler.Encode_M4A();
// Encode M4A Audio using Media Handler Pro version 4.0 or later
VideoInfo info = _mhandler.Encode_M4A();
// 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