I'm developing a video download website. We strore videos in FLV format. We convert them to 3GP,MP4 or AVI on user request.

But the problem is people re-distribute those videos without our copyright. So we thought to add a watermark to videos.

We want to add a our banner image at the start of the videos or add our logo in a corner of videos. We use ffmpeg to convert videos and think we will can do this job using ffmpeg. Our ffmpeg version details below.

ffmpeg-php version - 0.6.0-svn
ffmpeg-php built on - Jul 28 2011 19:47:40
ffmpeg-php gd support - enabled
ffmpeg libavcodec version - Lavc52.108.0
ffmpeg libavformat version - Lavf52.93.0
ffmpeg swscaler version - SwS0.12.0

Please help me for this job.
Thank you.

haven't done that in awhile but if you have it running on linux
here's a example i have saved always helps me out

ffmpeg –i myvideo.avi -vf "movie=mylogo.png [watermark]; [in][watermark] overlay=main_w-overlay_w-10:main_h-overlay_h-10 [out]" userdownload.flv

it doesn work. is there any other solution.
thankz for reply.

did you get a error or where you running it inside a php webscript if this is true try using passthru(); instead of system();
and also make sure its in a directory where apache can read/write too

hope this will help. thanx to the original author

The Overlay Filter overlay=x:y
This filter is used to overlay one video on top of another. It accepts the parameters x:y. Where x and y is the top left position of overlayed video on the main video. In this case, the top left position of the watermark graphic on the main video.

To position the watermark 10 pixels to the right and 10 pixels down from the top left corner of the main video, we would use “overlay=10:10”

The following expression variables represent the size properties of the Main and overlay videos.

main_w (main video width)
main_h (main video height)
overlay_w (overlay video width)
overlay_h (overlay video hieght)
For example if the; main video is 640×360 and the overlay video is 120×60 then

main_w = 640
main_h = 360
overlay_w = 120
overlay_h = 60
We can get the actual size (width and height in pixels) of both the watermark and the video file, and use this information to calculate the desired positioning of things. These properties are extremely handy for building expressions to programmatically set the x:y position of the overlay on top of the main video. (see examples below)

Watermark Overlay Examples

The following 4 video filter (-vf) examples embed an image named “watermarklogo.png” into one of the four corners of the video file, the image is placed 10 pixels away from the sides (offset for desired padding/margin).

Top left corner
ffmpeg –i inputvideo.avi -vf "movie=watermarklogo.png [watermark]; [in][watermark] overlay=10:10 [out]" outputvideo.flv

Top right corner
ffmpeg –i inputvideo.avi -vf "movie=watermarklogo.png [watermark]; [in][watermark] overlay=main_w-overlay_w-10:10 [out]" outputvideo.flv

Bottom left corner
ffmpeg –i inputvideo.avi -vf "movie=watermarklogo.png [watermark]; [in][watermark] overlay=10:main_h-overlay_h-10 [out]" outputvideo.flv

Bottom right corner
ffmpeg –i inputvideo.avi -vf "movie=watermarklogo.png [watermark]; [in][watermark] overlay=main_w-overlay_w-10:main_h-overlay_h-10 [out]" outputvideo.flv

These examples use something known as Filter Chains. The pad names for streams used in the filter chain are contained in square brackets [watermark],[in] and [out]. The ones labeled [in] and [out] are specific to video input and output. The one labeled [watermark] is a custom name given to the stream for the video overlay. You can change [watermark] to another name if you like. We are taking the output of the [watermark] and merging it into the input [in] stream for final output [out].

Padding Filter vs. Offset
A padding filter is available to add padding to a video overlay (watermark), however it’s a little complicated and confusing to work with. In the examples above I used an offset value of 10 pixels in the expressions for x and y.

For instance, when calculating the x position for placing the watermark overlay to right side of the video, 10 pixels away from the edge.

x=main_w-overlay_x-10
or rather
x=((main video width)-(watermark width)-(offset))
Another Watermark positioning Technique
Is to create a .png with same size as the converted video (ie. 640×360). Set it’s background to being transparent and place your watermark/logo where you desire it to appear over top of the video. This what’s known as a “full overlay”. You can actually get rather creative with your watermark design and branding using this technique.

ffmpeg –i inputvideo.avi -vf "movie=watermarklogo.png [watermark]; [in][watermark] overlay=0:0 [out]" outputvideo.flv

Full command line example
This is a more realistic example of what a a full FFmpeg command line looks like with various switches enabled. The examples in this article are extremely minified so you could get the basic idea.

ffmpeg -i test.mts -vcodec flv -f flv -r 29.97 -aspect 16:9 -b 300k -g 160 -cmp dct -subcmp dct -mbd 2 -flags +aic+cbp+mv0+mv4 -trellis 1 -ac 1 -ar 22050 -ab 56k -s 640x360 -vf "movie=dv_sml.png [wm]; [in][wm] overlay=main_w-overlay_w-10:main_h-overlay_h-10 [out]" test.flv

Windows users – Please Note
On the Windows OS the file paths used in video filters, such as “C:\graphics\watermarklogo.png” should be modified to be “/graphics/watermarklogo.png”. I myself experienced errors being thrown while using the Windows Builds of FFmpeg. This behavior may or may not change in the future. Please keep in mind that FFmeg is a Linux based project that has been ported over to work on Windows.

Watermarks and Branding in General
You can get some really great ideas for watermarking and branding by simply watching TV or videos online. One thing that many people tend to over look is including their website address in the watermark. Simply displaying it at the end or start of the video is not as effective. So some important elements would be a Logo, perhaps even a phone number or email address. The goal is to give people some piece of useful information for contacting or follow you. If you display it as part of your watermark, they have plenty of time to make note of your website URL, phone number or email address. A well designed logo is effective as well. The more professional looking your logo is, the more professional you come off as being to your audience.

If you are running a video portal service, and wish to brand the videos in conjunction/addition to watermark branding being done by your users. It’s wise to pick a corner such as the top right or top left to display your watermark. Perhaps go for far to give them an option of specifying which corner to display your watermark in, so it does not conflict with their own branding. I thought this was worth wild to mention since FFmpeg is used in web applications such as PHPmotion.

If you’re working with “full overlays” you can get pretty creative. You can get some really amazing ideas from watching the Major News networks on TV. Even the Home shopping networks such as QVC. These are just a few ideas for creative sources to watch and pull ideas from.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.