Media Handler Pro - 2 Pass Encoding

Today we just enhanced ASP.NET Media Handler Pro script to support 2 pass video encoding.


Media Handler Pro supported version 5.9 or later.


The following two commands (pass 1, pass 2) as shown below can be executed via asp.net media handler pro component


$ ffmpeg -i input.avi -pass 1 -an output.mp4
$ ffmpeg -i input.avi -pass 2 -ab 128k -y output.mp4

Example code to execute above command to publish mp4 video


 MediaHandler _mhandler = new MediaHandler();
string RootPath = HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath).Replace("\\", "/");
_mhandler.FFMPEGPath = HttpContext.Current.Server.MapPath("~\\ffmpeg\\bin\\ffmpeg.exe");
_mhandler.InputPath = RootPath + "\\contents\\original";
_mhandler.OutputPath = RootPath + "\\contents\\mp4";
_mhandler.FileName = "Wildlife.wmv";
_mhandler.OutputFileName = "Wildlife";
// Enable 2 pass encoding
_mhandler.Pass = 2;
// if pass 1 have different parameters from pass 2 as shown example then use this line
// Note: don't add -pass 1 or -pass 2 in commands. its automatically added by media handler pro script
_mhandler.Pass1Parameters = "-an";
_mhandler.Parameters = "-ab 128k";
_mhandler.OutputExtension = ".mp4";
VideoInfo info = _mhandler.Process();
if (info.ErrorCode > 0)
{
Response.Write("Video processing failed, Error code " + info.ErrorCode + " generated<br />" + info.ErrorMessage);
return;
}

Above one is just example, recommended to use latest ffmpeg commands and ffmpeg build to get more proper results


Example 2:


Example to publish mp4 video using 2 pass encoding with latest ffmpeg build release (Aug 2014)


// Enable 2 pass encoding
_mhandler.Pass = 2;
// if pass 1 have different parameters from pass 2 as shown example then use this line
// Note: don't add -pass 1 or -pass 2 in commands. its automatically added by media handler pro script
// pass 1 parameters
_mhandler.Pass1Parameters = "-c:v libx264 -preset medium -b:v 650k -c:a libvo_aacenc -b:a 96k";
// pass 2 parameters
_mhandler.Parameters = "-c:v libx264 -preset medium -b:v 650k -c:a libvo_aacenc -b:a 96k";
_mhandler.OutputExtension = ".mp4";
VideoInfo info = _mhandler.Process();

New examples and codes to be attached time to time here.

comments powered by Disqus