FFmpeg Crop Video to Shape Using Alpha Mask

This article explains how to crop a video into a custom shape using a static alpha mask image with FFmpeg. You will learn the exact FFmpeg command structure, the key filters required for the process, and how to output the final video with transparency preserved.

To crop a video using an alpha mask, you need two assets: your source video and a black-and-white mask image of the exact same dimensions. In the mask image, white areas represent the parts of the video you want to keep, while black areas represent the parts that will become transparent.

The FFmpeg Command for WebM (Web Friendly)

If you need a lightweight format for web use, use the VP9 codec in a WebM container, as it supports alpha transparency.

ffmpeg -i input.mp4 -i mask.png -filter_complex "[0:v][1:v]alphamerge" -c:v libvpx-vp9 -pix_fmt yuva420p output.webm

The FFmpeg Command for QuickTime (Editing Friendly)

If you plan to import the cropped video into video editing software like Apple Motion, Premiere Pro, or DaVinci Resolve, use the ProRes codec in a MOV container.

ffmpeg -i input.mp4 -i mask.png -filter_complex "[0:v][1:v]alphamerge" -c:v prores_ks -pix_fmt yuva444p10le output.mov

Command Breakdown

Handling Aspect Ratio Mismatches

If your mask image is a different size than your video, the command will fail or stretch the mask. You can scale the mask on the fly to match the video’s dimensions by adding the scale2ref filter:

ffmpeg -i input.mp4 -i mask.png -filter_complex "[1:v][0:v]scale2ref[mask][video];[video][mask]alphamerge" -c:v libvpx-vp9 -pix_fmt yuva420p output.webm