Quantcast
Channel: CodeSection,代码区,Linux操作系统:Ubuntu_Centos_Debian - CodeSec
Viewing all articles
Browse latest Browse all 11063

Easy ways to add watermarks to images and videos in Linux

$
0
0

Mostly notes to myself :-)

Here is a quick way to add watermarks to photos and videos. All linux command line based - so perfect if you've got a lot of images you want to manipulate.

Here is a delightful photo I've taken of a bee covered in pollen. I want to add a little copyright notice to it in order to discourage people using it without permission.


Easy ways to add watermarks to images and videos in Linux

This command uses imagemagick 's " annotate " option.

convert bee.jpg -gravity SouthEast -pointsize 16 -font TinyUnicode-Medium -fill "#fffdc3" -annotate +10+10 "(C) @edent" bee1.jpg

It produces this:


Easy ways to add watermarks to images and videos in Linux

As you can see, a small watermark in the bottom right - specified using -gravity SouthEast . I've chosen a yellow colour for the font - in homage to the EURion anti-counterfeiting symbols .

The -annotate command contains the distance in pixels from the edges

For small text, I favour a Pixel Font like TinyUnicode - but feel free to choose one which suits your needs.

In this example, I position the message in the top left, with a larger font size, in pale blue, closer to the horizontal edge and further from the vertical edge.

convert bee.jpg -gravity NorthWest -pointsize 32 -font Helvetica -fill "#cee3f8" -annotate +1+50 "(C) @edent" bee2.jpg
Easy ways to add watermarks to images and videos in Linux
Video

Adding a watermark to a video is more complex. This will require either ffmpeg - which isn't always installed by default on Linux - or avconv (I don't pretend to understand why ffmpeg and avconv split - but there we are).

I am going to overlay a transparent image on top of the video.

I've created this watermark image with a transparent background.


Easy ways to add watermarks to images and videos in Linux

To overlay it, I use:

ffmpeg -i input.mp4 -i watermark.png -filter_complex "overlay=1500:1000" output.mp4

or for avconv's overlay :

avconv -i input.mp4 -i watermark.png -filter_complex 'overlay=x=main_w-overlay_w-10:y=main_h-overlay_h-10' output.mp4

https://shkspr.mobi/blog/wp-content/uploads/2016/07/small.mp4

ffmpeg's overlay= option allows me to specify where the top left of the image will appear on the video. So adjust those number based on the resolution of your watermark and of your video.

avconv has a more complex syntax. It's possible to specify the absolute position using overlay=x=1500:y=1000 or to use relative positions with overlay=x=main_w-overlay_w-10:y=main_h-overlay_h-10 .

So, there you have it - hopefully simple ways to watermark your media files.


Viewing all articles
Browse latest Browse all 11063

Trending Articles