Extract Video Outlines Using FFmpeg Edgedetect

This article provides a step-by-step guide on how to use the FFmpeg edgedetect filter to extract outlines and edge-detected visual effects from video files. You will learn the basic command syntax, how to adjust parameters like high and low thresholds to fine-tune the edge detection, and how to utilize different modes to achieve custom artistic styles.

The edgedetect filter in FFmpeg utilizes the Canny edge detection algorithm to find and isolate the edges of objects within a video. By default, it outputs a monochrome video showing white outlines on a black background.

Basic Syntax

To apply the default edge detection filter to a video, use the following basic command:

ffmpeg -i input.mp4 -vf "edgedetect" output.mp4

In this command, -vf flags the video filter graph, and "edgedetect" applies the filter using its default settings.

Adjusting Threshold Parameters

You can control which edges are detected by adjusting the low and high threshold parameters. These values are defined as float numbers between 0 and 1.

To increase or decrease the sensitivity of the edge detection, define these parameters in the filter argument:

ffmpeg -i input.mp4 -vf "edgedetect=low=0.1:high=0.3" output.mp4

Lowering the values will detect fainter, more subtle outlines, while raising them will restrict the detection to only the most prominent, high-contrast edges.

Changing the Output Mode

The edgedetect filter offers three distinct modes of operation using the mode parameter:

  1. wires: The default mode. It draws white outlines on a solid black background.
  2. colormix: Mixes the original colors of the video into the detected edges, creating a stylized, hand-drawn color pencil effect on a black background.
  3. canny: Outputs standard Canny edge-detected outlines.

To use the colormix mode, use the following command:

ffmpeg -i input.mp4 -vf "edgedetect=mode=colormix" output.mp4

Creating Black Outlines on a White Background

By default, the output is white lines on a black background. If you want a traditional “sketch” look with black outlines on a white background, you can chain the negate filter after the edgedetect filter:

ffmpeg -i input.mp4 -vf "edgedetect,negate" output.mp4

The comma separates the filters, applying the edge detection first and then inverting the colors of the final video.