
Background video processing in ASP.NET
Example code provided here will help you implement background encoding, publishing, and processing of mp4 videos in your asp.net application. You can extend the following code for any other type of media processing.
Example Code
string RootPath = HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath);
_mhandler.FFMPEGPath = HttpContext.Current.Server.MapPath("~\\ffmpeg\\ffmpeg.exe");
_mhandler.InputPath = RootPath + "\\contents\\original";
_mhandler.OutputPath = RootPath + "\\contents\\mp4";
_mhandler.BackgroundProcessing = true;
_mhandler.FileName = "Primos.avi";
_mhandler.OutputFileName = "primos";
var presetpath = RootPath + "\\ffmpeg\\presets\\libx264-ipod640.ffpreset";
_mhandler.Parameters = " -fpre \"" + presetpath + "\"";
_mhandler.OutputExtension = ".mp4";
_mhandler.VCodec = "libx264";
//****************************** // 360p mp4 encoding //******************************
_mhandler.Width = 640;
_mhandler.Height = 380;
_mhandler.Video_Bitrate = 500;
_mhandler.Audio_SamplingRate = 44100;
_mhandler.Audio_Bitrate = 128;
_mhandler.ProcessMedia();
You can get the progress of video conversion any time via code
var percent_completed = Math.Round(_mhandler.vinfo.ProcessingCompleted, 2).ToString();
When progress completed, you can check the status of video and complete ffmpeg status via code
if (_mhandler.vinfo.ErrorCode > 0)
{
// error occurs in processing
str.Append("<tr><td>Error Code</td><td>" + _mhandler.vinfo.ErrorCode + "</td></tr>\n");
str.Append("<tr><td>Error Message</td><td>" + _mhandler.vinfo.ErrorMessage + "</td></tr>\n");
str.Append("<tr><td>FFMPEG Output</td><td>" + _mhandler.vinfo.FFMPEGOutput + "</td></tr>\n");
}
You can get video information like width / height of video
var width = _mhandler.vinfo.Width;
var height = _mhandler.vinfo.Height;