How to Add a Watermark to a Video With FFmpeg (Sized to the Video, Proven With pytest)
To add a watermark to a video with FFmpeg, feed the logo as a second input, scale it relative to the video width, lower its alpha with colorchannelmixer , and place it with overlay using main_w / overlay_w expressions. Map the original audio with -map 0:a? and copy it so only the picture is re-encoded. Below is a ~60-line Python wrapper plus four pytest checks that sample real pixels to prove…
To embed a watermark in a video using FFmpeg, feed the logo as a second input and scale it relative to the video width. Lower the alpha channel of the logo and position it using overlay expressions. Preserve the original audio by mapping it with -map 0:a and copying it, so only the picture is re-encoded. The Python wrapper provided above probes the video dimensions and calculates the watermark size based on a specified width ratio, opacity, and margin ratio. It then generates the appropriate FFmpeg command line to produce the watermarked video file.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.