The steps to add a transparent watermark to the center of a video using FFmpeg are as follows:
- Prepare the watermark image: First, prepare a PNG image with a transparent background to use as the watermark. Ensure it preserves transparency (e.g., save it as PNG format in Photoshop while maintaining transparency).
- Determine the watermark position: To position the watermark at the center of the video, obtain the video's resolution information. You can check the width and height using the FFmpeg command
ffmpeg -i video.mp4. - Use FFmpeg to add the watermark: Using the
overlayfilter in FFmpeg, you can overlay the watermark image onto the video. To calculate the position, subtract half the width and height of the watermark from half the video's width and height. The specific command is as follows:
bashffmpeg -i input_video.mp4 -i watermark.png -filter_complex "overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2" -codec:a copy output_video.mp4
Here, input_video.mp4 is the original video file, watermark.png is your watermark file. The expression overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2 calculates the watermark position to ensure it is centered on the video. -codec:a copy indicates that the audio is not re-encoded.
Example:
Suppose you have a video file named example.mp4 with a width of 1920px and height of 1080px, and a transparent watermark logo.png that is 200px wide and 100px high. Use the following command:
bashffmpeg -i example.mp4 -i logo.png -filter_complex "overlay=(1920-200)/2:(1080-100)/2" -codec:a copy output.mp4
This command will add logo.png as a transparent watermark to the center of example.mp4, generating the output file output.mp4 with the audio unchanged.
By following these steps and examples, you can flexibly add transparent watermarks to any position and any video file by adjusting the relevant parameters.