Post Reply

Post Watermark On Video using ASP.NET, C#, VB.NET

3 7, 2012 1:0 PM #1

mediasoftpro

mediasoftpro

Posts:281
Points:2,245
Joined November 2011
Previously we provide examples on posting watermark on videos using -vhook option which was available in older version of ffmpeg revisions which has been replace with -vf (video filters) libavfilter in recent versions.\r\n\r\nIn this post we will use latest -vf libavfilter [movie] to post watermark on videos.

You can use asp.net media handler pro to post watermark on any part of video using asp.net, c# or vb.net application.

Examples For Posting Watermark On Video
Posting watermark on top left section of video

_encode.Parameters = "-vf \\"movie=" + WatermarkPath + " [watermark]; [in][watermark] overlay=10:10 [out]\\"";

Posting watermark on top right section of video

_encode.Parameters = "-vf \\"movie=" + WatermarkPath + " [watermark]; [in][watermark] overlay=main_w-overlay_w-10:10 [out]\\"";

Posting watermark on bottom left section of video.

_encode.Parameters = "-vf \\"movie=" + WatermarkPath + " [watermark]; [in][watermark] overlay=10:main_h-overlay_h-10 [out]\\"";

Posting watermark on bottom right section of video

 _encode.Parameters = "-vf \\"movie=" + WatermarkPath + " [watermark]; [in][watermark] overlay=main_w-overlay_w-10:main_h-overlay_h-10 [out]\\"";

Detail of Expression Variables
The following expression variables represent the size properties of the Main and overlay videos.\r\nmain_w (main video width)\r\nmain_h (main video height)\r\noverlay_w (overlay video width)\r\noverlay_h (overlay video hieght)\r\nFor example if the; main video is 640×360 and the overlay video is 120×60 then\r\nmain_w = 640\r\nmain_h = 360\r\noverlay_w = 120\r\noverlay_h = 60

Complete Example For Encoding Mp4 Video and Posting Watermark On Bottom Right Section
MediaHandler _encode = new MediaHandler();
string RootPath = Server.MapPath(Request.ApplicationPath);
string WatermarkPath = "..\\images\\logo.png";
_encode.FFMPEGPath = HttpContext.Current.Server.MapPath("~\\\\ffmpeg_march_2012\\\\bin\\\\ffmpeg.exe");
_encode.InputPath = RootPath + "\\\\contents\\\\original";
_encode.OutputPath = RootPath + "\\\\contents\\\\mp4";
_encode.FileName = "6e8fce2c8a5c.mp4";
_encode.OutputExtension = ".mp4";
_encode.OutputFileName = "watermarkvideo";
_encode.VCodec = "libx264";
_encode.ACodec = "libvo_aacenc";
_encode.Channel = 2;
_encode.Audio_SamplingRate = 44100;
_encode.Audio_Bitrate = 96;
_encode.Video_Bitrate = 500;
_encode.FrameRate = 29.97;
_encode.Width = 640;
_encode.Height = 480;
//Post Watermark on Top Left of Video
_encode.Parameters = "-vf \\"movie=" + WatermarkPath + " [watermark]; [in][watermark] overlay=10:10 [out]\\"";
// Post Watermark on Top Right of Video
//_encode.Parameters = "-vf \\"movie=" + WatermarkPath + " [watermark]; [in][watermark] overlay=main_w-overlay_w-10:10 [out]\\"";
// Post Watermark on Bottom Left of Video
//_encode.Parameters = "-vf \\"movie=" + WatermarkPath + " [watermark]; [in][watermark] overlay=10:main_h-overlay_h-10 [out]\\"";
// Post Watermark on Bottom Right of Video
_encode.Parameters = "-vf \\"movie=" + WatermarkPath + " [watermark]; [in][watermark] overlay=main_w-overlay_w-10:main_h-overlay_h-10 [out]\\"";
VideoInfo info = _encode.Process();
3 7, 2012 1:1 PM #2

mediasoftpro

mediasoftpro

Posts:281
Points:2,245
Joined November 2011
We used the following latest ffmpeg build in example shown above

We recommend updating your ffmpeg from http://ffmpeg.zeranoe.com/
3 8, 2012 0:52 AM #3

mediasoftpro

mediasoftpro

Posts:281
Points:2,245
Joined November 2011
Just one additional note,

Place logo.png (watermark logo) within ffmpeg directory and instead of calling via absolute path, just call image directly as shown in example.

_encode.Parameters = "-vf \\"movie=logo.png [watermark]; [in][watermark] overlay=10:10 [out]\\"";
3 8, 2012 0:28 AM #4

mediasoftpro

mediasoftpro

Posts:281
Points:2,245
Joined November 2011
Posting watermark on photo using asp.net

Sample code will help you to grab photos from video and post watermark on image using asp.net media handler pro
component.

string thumb_start_index = "sample_";
_mhandler.FileName = "sample.mp4";
_mhandler.Image_Format = "jpg";
_mhandler.VCodec = "image2";
_mhandler.ImageName = thumb_start_index;
_mhandler.Multiple_Thumbs = true;
_mhandler.ThumbMode = 0;
_mhandler.No_Of_Thumbs = 15;
_mhandler.Thumb_Start_Position = 10;
// start grabbing thumbs from 5th second
//_mhandler.Width = 160;
//_mhandler.Height = 120;
_mhandler.Width = 640;
_mhandler.Height = 480;
_mhandler.Parameters = "-vf movie=logo.png [watermark]; [in][watermark] overlay=main_w-overlay_w-10:main_h-overlay_h-10 [out]";
VideoInfo info = _mhandler.Grab_Thumb();
if (info.ErrorCode > 0)
{
      Response.Write("Error occured while grabbing thumbs from video");
}

You can directly post watermark on photo without grabbing from video using _mhandler.Process() method and passing photo file name via _mhandler.FileName property.
5 29, 2012 0:18 AM #5

klauzser

klauzser

Posts:13
Points:65
Joined May 2012
Can you also adjust how big will the watermark be displayed?

1 13, 2013 9:46 PM #6

yoav.rios

yoav.rios

Posts:1
Points:5
Joined January 2013
Hi I bought the ASP.NET Media Handler Pro 5.5 and when i tried to make the water mark not work, I tested the ffmpeg_march_2012, ffmpeg_july_2012 and the lasted... :(

Can you help me?
1 14, 2013 0:49 AM #7

mediasoftpro

mediasoftpro

Posts:281
Points:2,245
Joined November 2011
We recommend using latest ffmpeg build from

http://ffmpeg.zeranoe.com/builds/

Posting Watermark Issue Fixed in Media Handler Pro version 5.7

if someone uses older version then request for latest build via our support mail.
1 19, 2013 0:45 AM #8

gavind

gavind

Posts:54
Points:450
Joined December 2012
Hi. Does this also apply in the current version? I mean 7.1?

1 25, 2013 0:8 AM #9

mediasoftpro

mediasoftpro

Posts:281
Points:2,245
Joined November 2011
It apply only on using latest version of Media Handler Pro 5.5.
1 28, 2013 0:21 AM #10

erikdilen

erikdilen

Posts:1
Points:5
Joined January 2013
Is it possible to put the image in the bottom right corner using the solution with WatermarkPath and WatermarkImagePath?