Watermarking Videos: Add Text, Logos, and Dynamic Timestamps
Wed Aug 28 2024
Overlay text, images, and logos on videos with precise positioning, transparency, and dynamic elements like timestamps.
Watermarks protect your content and add branding. FFmpeg's overlay filters let you add text, logos, and even dynamic timestamps to videos without needing a GUI editor. This guide covers common watermarking scenarios with clean, reusable examples.
Why Watermark with FFmpeg?
Batch processing, automation, and consistent branding. Unlike GUI tools, FFmpeg lets you script watermarking for hundreds of files with identical positioning and styling. You can also add dynamic elements like frame numbers or real-time timestamps that update throughout the video.
Image Watermarks (Logo Overlays)
# Bottom-right corner with 20px padding ffmpeg -i video.mp4 -i logo.png -filter_complex "[0:v][1:v]overlay=W-w-20:H-h-20" output.mp4 # Top-left corner ffmpeg -i video.mp4 -i logo.png -filter_complex "[0:v][1:v]overlay=20:20" output.mp4 # Centered ffmpeg -i video.mp4 -i logo.png -filter_complex "[0:v][1:v]overlay=(W-w)/2:(H-h)/2" output.mp4
The overlay expression uses:
WandH= main video width and heightwandh= overlay (logo) width and height
Transparent Watermarks
# 50% opacity logo ffmpeg -i video.mp4 -i logo.png \ -filter_complex "[1:v]format=rgba,colorchannelmixer=aa=0.5[logo];[0:v][logo]overlay=W-w-20:H-h-20" \ output.mp4 # Fade in watermark over first 2 seconds ffmpeg -i video.mp4 -i logo.png \ -filter_complex "[1:v]fade=in:0:48:alpha=1[logo];[0:v][logo]overlay=W-w-20:20" \ output.mp4
Text Watermarks
Text requires the drawtext filter. You'll need a font file path or font name.
# Simple text watermark (bottom-right) ffmpeg -i input.mp4 -vf "drawtext=text='© 2024 My Company':fontsize=24:fontcolor=white:x=w-text_w-20:y=h-text_h-20" output.mp4 # With background box for readability ffmpeg -i input.mp4 -vf "drawtext=text='© 2024 My Company':fontsize=24:fontcolor=white:box=1:boxcolor=black@0.5:boxborderw=5:x=w-text_w-30:y=h-text_h-30" output.mp4 # Top-left with custom font ffmpeg -i input.mp4 -vf "drawtext=text='WATERMARK':fontfile=/path/to/font.ttf:fontsize=32:fontcolor=white@0.7:x=20:y=20" output.mp4
Dynamic Text: Timestamps and Timecodes
# Show current timecode (HH:MM:SS) ffmpeg -i input.mp4 -vf "drawtext=text='%{pts\:hms}':fontsize=20:fontcolor=white:x=10:y=10" output.mp4 # Frame number ffmpeg -i input.mp4 -vf "drawtext=text='Frame\: %{n}':fontsize=18:fontcolor=yellow:x=10:y=h-th-10" output.mp4 # Current date and time (requires localtime) ffmpeg -i input.mp4 -vf "drawtext=text='%{localtime\:%Y-%m-%d %H\\\:%M\\\:%S}':fontsize=18:fontcolor=white:x=w-text_w-10:y=10" output.mp4
Combine Logo and Text
# Logo top-right, text bottom-left ffmpeg -i video.mp4 -i logo.png \ -filter_complex "[0:v][1:v]overlay=W-w-20:20[v];[v]drawtext=text='© 2024':fontsize=24:fontcolor=white:x=20:y=H-th-20" \ output.mp4 # Logo with 50% opacity + text with shadow ffmpeg -i video.mp4 -i logo.png \ -filter_complex "[1:v]format=rgba,colorchannelmixer=aa=0.5[logo];[0:v][logo]overlay=W-w-30:30[v];[v]drawtext=text='Sample Video':fontsize=28:fontcolor=white:shadowcolor=black:shadowx=2:shadowy=2:x=30:y=H-th-30" \ output.mp4
Conditional and Moving Watermarks
# Watermark only visible after 5 seconds ffmpeg -i input.mp4 -i logo.png \ -filter_complex "[1:v]format=rgba[logo];[0:v][logo]overlay=W-w-20:H-h-20:enable='gte(t,5)'" \ output.mp4 # Moving watermark (left to right over 10 seconds) ffmpeg -i input.mp4 -i logo.png \ -filter_complex "[0:v][1:v]overlay='if(lt(t,10), (t/10)*(W-w), W-w)':H-h-20" \ output.mp4 # Bouncing text (up and down) ffmpeg -i input.mp4 -vf "drawtext=text='BOUNCE':fontsize=48:fontcolor=white:x=(w-text_w)/2:y='h/2 + 100*sin(2*PI*t/5)'" output.mp4
Multiple Watermarks
# Four corner logo placement ffmpeg -i video.mp4 -i logo.png \ -filter_complex "[0:v][1:v]overlay=20:20[v1];[v1][1:v]overlay=W-w-20:20[v2];[v2][1:v]overlay=20:H-h-20[v3];[v3][1:v]overlay=W-w-20:H-h-20" \ output.mp4
Batch Watermarking
Shell script to watermark all MP4 files in a directory:
#!/bin/bash for f in *.mp4; do ffmpeg -i "$f" -i logo.png \ -filter_complex "[0:v][1:v]overlay=W-w-20:H-h-20" \ -c:v libx264 -crf 23 -c:a copy "watermarked_$f" done
For large batches, consider parallel processing with GNU parallel or run multiple FFmpeg instances.
Pitfalls
- Missing font files will cause drawtext to fail; test with a known font path first.
- Complex filter expressions can be slow; test on a short clip before processing hours of video.
- Using
-c:a copypreserves audio without re-encoding; if adding filters, audio stays untouched anyway. - Positioning with
overlay=10:10is simpler than expressions for static placement. - Alpha channel handling: ensure your logo PNG has transparency if you want it; otherwise, you'll see a solid rectangle.
Recommended Practices
- Test positioning on a 5-second clip before processing the full video.
- Use transparent PNGs with alpha channels for professional-looking overlays.
- Match resolution: scale your logo to appropriate size before overlaying (e.g., 10-15% of video width).
- Consider readability: add semi-transparent boxes behind text for better contrast.
- Encode with care: use CRF 20-23 for high quality when re-encoding, or copy codecs when possible.
With these techniques, you can protect, brand, and enhance your videos programmatically, saving hours compared to manual editing. Whether you need simple copyright notices or complex dynamic overlays, FFmpeg's filter system provides the flexibility to implement any watermarking strategy.