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.

  1. Take a screenshot of a frame in your video where the logo is clearly visible against a relatively dark or simple background.
  2. Open the screenshot in an image editor (like Photoshop or GIMP).
  3. 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.
  4. Save the file in the Portable Graymap format (.pgm). If your editor does not support .pgm, save it as a .png and convert it using FFmpeg with the following command:
ffmpeg -i mask.png -pix_fmt gray mask.pgm

Step 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.mp4

Command Breakdown