This post will provide additional uploader option specially designed for two pass video publishing implementation. Instead of single process, this uploader example uses single video encoding with two processes one after another in background.


You can view demonstration via video



Sample Code:


Uploader uses normal encoding example for publishing mp4 video with pass 1 and pass 2, you can use your own ffmpeg commands. We strongly recommend to test your ffmpeg command directly before implementing in vUploader script in order to avoid failure in video publishing.


You can set encoding settings throug 2pass/encode.ashx file



private static string EncodeVideo(string Source, string Published, int Pass)
{
MediaHandler _mhandler = new MediaHandler();
string RootPath = HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath);
_mhandler.FFMPEGPath = HttpContext.Current.Server.MapPath("~\\ffmpeg\\bin\\ffmpeg.exe");
_mhandler.InputPath = RootPath + "\\" + SourcePath;
_mhandler.OutputPath = RootPath + "\\" + PublishedPath;
_mhandler.BackgroundProcessing = true;
_mhandler.FileName = Source;
_mhandler.OutputFileName = Published;
if(Pass == 1)
{
// set parameters compatible to pass 1
_mhandler.Parameters = "-pass 1 -c:v libx264 -preset medium -b:v 650k -c:a libvo_aacenc -b:a 96k";
}
else if(Pass == 2)
{
_mhandler.Parameters = "-pass 2 -c:v libx264 -preset medium -b:v 650k -c:a libvo_aacenc -b:a 96k";
}
_mhandler.OutputExtension = ".mp4";
_mhandler.ProcessMedia();
if (_mhandler.vinfo.ErrorCode > 0)
{
// remove file if failed to publish properly
if (File.Exists(RootPath + "/" + _mhandler.InputPath))
File.Delete(RootPath + "/" + _mhandler.InputPath);


// validation error occured, don't proceed more
return "{\"encodeoutput\" : \"2.0\", \"ecode\" : \"" + _mhandler.vinfo.ErrorCode.ToString() + "\"}";
}
else
{
_mhandler.vinfo.ProcessID = Guid.NewGuid().ToString(); // unique guid to attach with each process to identify proper object on progress bar and get info request
_lst.Add(_mhandler);
return "{\"encodeoutput\" : \"2.0\", \"ecode\" : \"" + _mhandler.vinfo.ErrorCode + "\", \"procid\" : \"" + _mhandler.vinfo.ProcessID + "\"}";
}
}


Note: In 2 Pass Encoding, each progress bar along with percentage represent both processes (1 pass and 2 pass), 1 pass with red when progress reaches 50%, its almost completed, aftward 2 pass will started with pink progress bar.


You can check detail vUploader script by browsing this link


www.mediasoftpro.com/wiki/asp.net-vuploader-script-8.0.aspx


 

;