How to Use FFmpeg removelogo with a Bitmap Mask
This article provides a step-by-step guide on how to use FFmpeg’s
removelogo filter to eliminate unwanted watermarks or logos
from a video using a grayscale bitmap mask. You will learn how to create
the compatible mask file, understand the syntax, and run the correct
FFmpeg command to achieve a clean output.
Step 1: Create the Grayscale Bitmap Mask
The removelogo filter works by analyzing a separate
image file called a mask. This mask must be the exact same resolution as
your video.
- Take a screenshot of a frame in your video where the logo is clearly visible against a relatively dark or simple background.
- Open the screenshot in an image editor (like Photoshop or GIMP).
- Create the mask:
- Paint the entire background solid black (RGB: 0, 0, 0). Black areas tell FFmpeg to leave the video pixels untouched.
- Paint the exact area of the logo solid white (RGB: 255, 255, 255). White areas tell FFmpeg to remove the pixels and interpolate them using surrounding data.
- Use gray (values between 1 and 254) on the edges of the logo to create a transition zone, which helps blend the correction smoothly.
- Save the file in the Portable Graymap format
(
.pgm). If your editor does not support.pgm, save it as a.pngand convert it using FFmpeg with the following command:
ffmpeg -i mask.png -pix_fmt gray mask.pgmStep 2: Apply the removelogo Filter
Once you have your mask.pgm file in the same directory
as your video, you can run the FFmpeg command. The filter will analyze
the white pixels in the mask and fill them in by interpolating the
neighboring black-masked pixels from the video.
Run the following command in your terminal:
ffmpeg -i input.mp4 -vf "removelogo=mask.pgm" -c:a copy output.mp4Command Breakdown
-i input.mp4: Specifies your source video file.-vf "removelogo=mask.pgm": Applies the video filter (-vf). Theremovelogofilter is pointed directly to your grayscale.pgmmask file.-c:a copy: Copies the audio stream without re-encoding it, saving processing time and preserving audio quality.output.mp4: The final output file with the logo removed.