Add Watermark on the Video in AEM using FFmpeg

Abhigyan Swaroop
5 min readMar 18, 2021

What is Watermarking?

Watermarking is a technique with similarities to steganography. It is typically used to identify ownership of the copyright of such audio, videos or images. Digital watermark is the process to add such identifiable digital signature on the assets.

What is Common use cases?

In this world of digital marketing, companies spend a lot on increasing the digital presence and register themselves in every way possible to its prospective customers. Images and video production and use in advertisement is common practice. This not only attract customers but also established the brand presence among them. Adding watermark to these assets further adds on this and adds a recall of a brand whenever one see these content. Common industries making use of watermark are Consumer goods, Online retailers and content creators, Sponsors for event/celebrity etc.

AEM is a very powerful tool to manage content and cater to the customers.
During various implementation, I learnt client want to protect their videos and images

In this article, I will try to walk you through the process to add watermark image on any video via FFmpeg and then how to do it in AEM.

Prerequisite

  1. You should have FFmpeg installed on your local.
    (For windows : go to https://github.com/BtbN/FFmpeg-Builds​. You need to download the FFmpeg zip file ending in “win64-gpl-4.3.zip” and add the path to bin folder of the installation in the environment variables.) there are plenty of video online which explains it in details.
  2. Once you have FFmpeg installed on your system, verify the installations.

You are good to go now.

How to add image watermark on the video in AEM

You would need to create a video profile in AEM with the filters options defined.
There are different ways we can add watermark on the videos, some of them are as follows, but this will need to be run in the command prompt/terminal directly. Using these you will get a feel of how your video will appear post-processing in AEM, however this is not exactly we will do in AEM. We will touch the topic to tackle it in AEM in following sections soon!

Adding watermark on the centre of the video.

ffmpeg -i yourVideoName.mp4 -i yourWaterMarkImage.png -filter_complex "overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2" -codec:a copy yourDesiredOutputVideName.mp4

2. Similarly, the overlay of the watermark can be adjusted anywhere on the video
a. Top right with 10 pixel padding
overlay=main_w-overlay_w-10:10
b. Bottom right with 10 pixel padding
overlay=main_w-overlay_w-10:main_h-overlay_h-10
c. Bottom left with 10 pixel padding
overlay=10:main_h-overlay_h
there are many options which can also be explored to adjust the opacity of the watermark image as well such as
ffmpeg -i yourVideoName.mp4 -i yourWaterMarkImage.png -filter_complex "[1]format=rgba,colorchannelmixer=aa=0.5[logo];[0][logo]overlay=(W-w)/2:(H-h)/2:format=auto,format=yuv420p" -c:a copy yourDesiredOutputVideName.mp4

Animation to the watermark image can also be done

1. For Watermark to animate on diagonal line:ffmpeg -i demoVideo.mp4 -loop 1 -i myWatermark.png -filter_complex “[1]format=rgba,colorchannelmixer=aa=0.3[logo];[0][logo]overlay=x=’if(gte(t,0), ((W+w)\/5)\*mod(t\,5)-w, NAN)’:y=’if(gte(t,0), ((H+h)\/5)\*mod(t\,5)-h, NAN)’:shortest=1” -c:a copy yourDesiredOutputVideoName.mp42. For Watermark to animate along y-axis:ffmpeg -i demoVideo.mp4 -loop 1 -i myWatermark.png -filter_complex overlay=x=0:y='((H+h)\/5)\*mod(t\,5)-h':shortest=1 yourDesiredOutputVideoName.mp4

Video will appear as below (along diagonal line) :

Now let’s discuss how to get it working in AEM

Create a video profile with the desired custom filter argument. Here I will show how to add a thumbnail in the centre of the video with adjusted opacity of 10% (0.1).

  1. Create a custom video filter with below parameter inside

“/conf//settings/dam/video/myCustomProfile”

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="cq:Page">
<jcr:content
cq:template="/libs/dam/templates/videoprofile"
jcr:description="A video profile with high quality output to create watermarked videos"
jcr:primaryType="nt:unstructured"
jcr:title="Watermark FullHD (H.264 - HP - Lvl4.0)"
sling:resourceType="dam/components/video/profile"
customArgs="-i C:/Users/myuser/myfolder/watermark.png -filter_complex &quot;[1][0]scale2ref=w=oh*mdar:h=ih*0.1[logo][video];[video][logo]overlay=5:H-h-5&quot; -c:a copy"
extension="mp4"
htmlType="video/mp4; codecs=&quot;avc1.640028, mp4a.40.2&quot;"
mimeType="video/x-m4v"
renditionSelector="myIdentifiableID"/>
</jcr:root>

please look closely, I have added watermark image path as input (-i ) as

C:/Users/myuser/myfolder/watermark.png

This should be the address of the image which can be accessed via FFmpeg while processing i.e. the image should be local to the AEM server.

2. Now that we have a video profile created, we can design a workflow to add this filter to be picked up during the workflow process.
We would need to add a Process step in the workflow

Workflow Process step configuration in AEM.

a. Select Process step from the available options to design the workflow.

b. go to the process tab and from dropdown select Transcode video process.

c. Add arguments as profile:myCustomProfile (name of the video profile you created above.)

3. Now we are ready, lets trigger the workflow and an additional rendition will be available under encode when you visit your video.

Video with added watermark

If you want animation of the watermark image on video here you go with the filter

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="cq:Page">
<jcr:content
cq:template="/libs/dam/templates/videoprofile"
jcr:description="A video profile with high quality output to create watermarked videos"
jcr:primaryType="nt:unstructured"
jcr:title="Watermark FullHD (H.264 - HP - Lvl4.0)"
sling:resourceType="dam/components/video/profile"
customArgs="-loop 1 -i yourImagePAthFromServer/myWatermark.png -filter_complex overlay=x=0:y='((H+h)\/5)\*mod(t\,5)-h':shortest=1"
extension="mp4"
htmlType="video/mp4; codecs=&quot;avc1.640028, mp4a.40.2&quot;"
mimeType="video/x-m4v"
renditionSelector="myIdentifiableID"/>
</jcr:root>

* You can play with x=0 to move the watermark image anywhere in the video.

Some disadvantages of processing video like this :

  1. Video thumbnail processing is heavy operation, and therefore it can result in performance issues.
  2. Long videos may take a lot of time to process as this thumbnail process step adds a watermark on each frame of the video.
  3. Maintenance of the watermark image can be a challenge as it won’t be hosted in AEM DAM.

--

--