Post Watermark

Post Watermark on Videos using ASP.NET

Example code for posting watermark on video using ASP.NET


var _mhandler = new MediaHandler();
var RootPath = Server.MapPath(Request.ApplicationPath);
_mhandler.FFMPEGPath = HttpContext.Current.Server.MapPath("~\\ffmpeg\\ffmpeg.exe");
// setup input directory path where source video exist
_mhandler.InputPath = RootPath + "\\source";
// setup output directory path where published video will save
_mhandler.OutputPath = RootPath + "\\published";
_mhandler.FileName = "sample.avi";
_mhandler.OutputFileName = "sample";
_mhandler.OutputExtension = ".mp4";
// watermark settings
/* this will target ffmpeg bin directory as default root directory. 
If you place here you have not needed to set up an absolute path or relative path
that creates a problem in some conditions */
var WatermarkPath = "logo.png";
//Post Watermark on Top Left of Video
var watermark_script = "-vf \\"movie=" + WatermarkPath + " [watermark]; [in][watermark] overlay=10:10 [out]\\"";
// Post Watermark on Top Right of Video
//watermark_script = "-vf \\"movie=" + WatermarkPath + " [watermark]; [in][watermark] overlay=main_w-overlay_w-10:10 [out]\\"";
// Post Watermark on Bottom Left of Video
//watermark_script = "-vf \\"movie=" + WatermarkPath + " [watermark]; [in][watermark] overlay=10:main_h-overlay_h-10 [out]\\"";
// Post Watermark on Bottom Right of Video
//watermark_script = "-vf \\"movie=" + WatermarkPath + " [watermark]; [in][watermark] overlay=main_w-overlay_w-10:main_h-overlay_h-10 [out]\\"";
// setup encoding preset. recommended to update with your required settings
_mhandler.Parameters = watermark_script + " -s 640x380 -c:v libx264 -preset medium 
-crf 22 -b:v 500k -b:a 128k -profile:v baseline -level 3.1";
VideoInfo info = _mhandler.Process(); 
if(info.ErrorCode > 0) {
Response.Write("Video processing failed, Error code " + info.ErrorCode + " generated");
Response.Write(info.FFMPEGOutput);
return;
} else {
Response.Write("Processing Successful");
}

Post watermark on image using ASP.NET

Example code for posting watermark on image using ASP.NET


var _mhandler = new MediaHandler();
var RootPath = Server.MapPath(Request.ApplicationPath);
_mhandler.FFMPEGPath = HttpContext.Current.Server.MapPath("~\\ffmpeg\\ffmpeg.exe");
// setup input directory path where source video exist
_mhandler.InputPath = RootPath + "\\source";
// setup output directory path where published video will save
_mhandler.OutputPath = RootPath + "\\published";
// source media to capture thumbnail from
_mhandler.FileName = "sample.mp4";
// start image position e.g 45 in seconds or "00:00:45" format
_mhandler.InitialCommands = "-ss 45";
// watermark settings, logo.png assume its located in /ffmpeg/bin directory 
var watermark_script = "-vf movie=logo.png [watermark]; [in][watermark] overlay=main_w-overlay_w-10:main_h-overlay_h-10 [out]";
_mhandler.Parameters = watermark_script + " -s 400x300 -qscale:v 2 -frames:v 1 -f image2 -c:v mjpeg"
VideoInfo tinfo = med.Process();
if (tinfo.ErrorCode > 0) {
// Error occured in grabbing thumbs
return info;
} else {
// thumbnail captured
}