Use FFmpeg Maskedmin to Output Minimum Pixel Values
The FFmpeg maskedmin filter allows you to compare pixel
values across video frames and output the lowest value for each pixel
coordinate based on a mask. This guide explains how the filter works,
how to satisfy its input requirements when comparing two videos, and how
to execute the command to obtain the minimum pixel values across your
media.
Understanding the Filter Requirements
The maskedmin filter takes three video streams as
inputs:
- First source video: The primary video stream to compare.
- Second source video: The reference video stream to compare against the first.
- Mask stream: A grayscale video stream that controls the operation. When a mask pixel is at maximum luminance (white), the filter outputs the minimum value between the first and second video. Where the mask pixel is at minimum luminance (black), the filter preserves the first video's original pixel value.
Both input videos and the mask must have identical dimensions, frame rates, and pixel formats to be processed correctly.
Comparing Two Videos Across All Pixels
To output the minimum pixel values across the entire area of two
videos, you need to provide a mask where every pixel is fully activated
(white). You can generate this synthetic mask directly in your FFmpeg
command using the color filter, eliminating the need to
create an external mask file.
Run the following command:
ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex \
"[0:v]format=pix_fmts=yuv420p[v0]; \
[1:v]format=pix_fmts=yuv420p[v1]; \
color=c=white:s=1920x1080:r=30[mask]; \
[v0][v1][mask]maskedmin=planes=15[out]" \
-map "[out]" -c:v libx264 -crf 18 output_min.mp4In this command:
[0:v]and[1:v]load the two video inputs and ensure matching pixel formats viaformat=pix_fmts=yuv420p.color=c=white:s=1920x1080:r=30generates a solid white video stream matching the resolution (s) and frame rate (r) of the input videos.[v0][v1][mask]maskedmin=planes=15applies the filter across the three streams.-map "[out]"maps the processed stream to the final output file.
Filter Options
The maskedmin filter supports the planes
parameter:
planes: Sets which color planes to process. It accepts a bitmask integer from0to15:1: Process only the first plane (Luma / Y).7: Process the first three planes (Y, U, V).15: Process all planes, including Alpha if present (default).
To restrict the minimum value comparison exclusively to brightness
(Luma) while preserving the original chroma of the first video, set
planes=1:
ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex \
"[0:v][1:v]color=c=white:s=1920x1080:r=30[mask]; \
[0:v][1:v][mask]maskedmin=planes=1[out]" \
-map "[out]" -c:v libx264 output_luma_min.mp4Using an External Mask
If you only want to extract the minimum pixel values in specific regions (such as a bounding box or moving subject), supply a pre-rendered grayscale video as the third input instead of the synthetic color source:
ffmpeg -i input1.mp4 -i input2.mp4 -i mask.mp4 -filter_complex \
"[0:v][1:v][2:v]maskedmin=planes=15[out]" \
-map "[out]" -c:v libx264 output_masked.mp4