FFmpeg Complex Filtergraph: Scale, Crop, and Watermark

Processing video files often requires multiple adjustments like resizing, cropping, and adding branding elements. Performing these operations sequentially wastes time and degrades video quality through multiple re-encodings. This guide demonstrates how to combine scaling, cropping, and watermarking into a single, highly efficient FFmpeg complex filtergraph command, saving processing power and maintaining optimal video quality.

To perform these actions simultaneously, FFmpeg uses the -filter_complex flag. This allows you to chain multiple filters together in a single pass.

The Unified FFmpeg Command

Below is the complete command to crop a video, scale it to 720p (1280x720), and overlay a watermark logo in the top-right corner.

ffmpeg -i input.mp4 -i watermark.png -filter_complex \
"[0:v]crop=in_w-200:in_h-200:100:100,scale=1280:720[processed_bg]; \
 [processed_bg][1:v]overlay=main_w-overlay_w-20:20[outv]" \
-map "[outv]" -map 0:a? -c:v libx264 -crf 23 -c:a copy output.mp4

How the Filtergraph Works

The core of this command is the -filter_complex string, which is broken down into distinct steps separated by commas (for continuous streaming) and semicolons (for defining new paths).

  1. Selecting the Input Video [0:v]: This identifies the video stream of the first input (input.mp4).
  2. Cropping crop=in_w-200:in_h-200:100:100: This cuts 100 pixels off the top, bottom, left, and right of the video.
    • in_w-200 and in_h-200 define the width and height of the output crop area.
    • 100:100 defines the X and Y coordinates where the crop begins.
  3. Scaling scale=1280:720: Chained directly after the crop with a comma, this resizes the newly cropped video to 1280x720 pixels.
  4. Naming the Temporary Stream [processed_bg]: The output of the crop and scale steps is saved to a temporary label called [processed_bg].
  5. Overlaying the Watermark [processed_bg][1:v]overlay=...: This takes the processed video and overlays the second input ([1:v], which is watermark.png).
    • main_w-overlay_w-20: Positions the watermark horizontally. It subtracts the watermark width (overlay_w) and a 20-pixel margin from the video width (main_w), pushing it to the right edge.
    • 20: Positions the watermark vertically, placing it 20 pixels down from the top edge.
  6. Output Label [outv]: The final combined video stream is labeled [outv].

Mapping and Encoding Settings