Extract Video Outlines Using FFmpeg edgedetect

FFmpeg's edgedetect filter uses the Canny edge detection algorithm to find and isolate boundaries within video frames, turning standard footage into distinct line art. This guide covers how to apply the filter, fine-tune sensitivity thresholds, and switch between display modes to extract clean black-and-white contours or overlay edges onto original colors.

Basic Edge Detection Command

To apply the default Canny edge detection to a video, use the -vf (video filter) flag with edgedetect:

ffmpeg -i input.mp4 -vf "edgedetect" -c:a copy output.mp4

By default, this command draws white outlines over a black background for all detected edges in the video stream, while keeping the audio unchanged.

Understanding Key Filter Parameters

The edgedetect filter relies on three primary parameters to control detection sensitivity and visual style:

  • low: The lower threshold for hysteresis edge tracking (range: 0.0 to 1.0, default: 19.75/255 ≈ 0.078). Lower values increase sensitivity to faint lines.
  • high: The upper threshold for hysteresis edge tracking (range: 0.0 to 1.0, default: 50/255 ≈ 0.196). Higher values reject weaker edges, reducing visual noise.
  • mode: The drawing method. Available options are wires (default), canny, and colormix.

Switching Visual Modes

1. Wires Mode (Default)

Draws white lines across a completely black background.

ffmpeg -i input.mp4 -vf "edgedetect=mode=wires" -c:a copy wires_output.mp4

2. Canny Mode

Keeps edges monochrome, but preserves semi-transparent gradients within the outlines, resulting in softer boundaries compared to wires.

ffmpeg -i input.mp4 -vf "edgedetect=mode=canny" -c:a copy canny_output.mp4

3. Colormix Mode

Superimposes the detected outlines on top of the original video, blending the detected edges directly into the source colors.

ffmpeg -i input.mp4 -vf "edgedetect=mode=colormix" -c:a copy colormix_output.mp4

Tuning Edge Sensitivity

To eliminate visual noise and isolate prominent shapes, increase the low and high thresholds:

ffmpeg -i input.mp4 -vf "edgedetect=low=0.2:high=0.5:mode=wires" -c:a copy high_contrast_edges.mp4

To capture subtle textures, wrinkles, and fine details, reduce both thresholds:

ffmpeg -i input.mp4 -vf "edgedetect=low=0.03:high=0.08:mode=wires" -c:a copy detailed_edges.mp4

Creating Black Lines on a White Background

To invert the default output into black outlines on a white canvas (pencil sketch effect), chain the negate filter after edgedetect:

ffmpeg -i input.mp4 -vf "edgedetect=low=0.1:high=0.3:mode=wires,negate" -c:a copy sketch_output.mp4