How to Create Cartoon Effect in FFmpeg

This article demonstrates how to transform standard video footage into an animated cartoon style using FFmpeg. By combining edge detection and blurring filters through FFmpeg’s filtergraph, you can smooth out video details while drawing bold outlines to achieve a classic cel-shaded cartoon aesthetic.

The Cartoon Effect Logic

To achieve a cartoon or cel-shaded look, the video processing is split into two parallel paths that are merged at the end: 1. The Color Path: Uses a blurring filter to smooth out gradients, remove noise, and create flat areas of color. 2. The Outline Path: Uses an edge detection filter to find boundaries, which are then inverted to create black outlines on a white background.

These two paths are combined using a multiplication blend, which overlays the black outlines onto the smoothed color video.

The FFmpeg Command

Run the following command in your terminal to apply the cartoon effect:

ffmpeg -i input.mp4 -vf "split=2 [color_in][edge_in]; [color_in] smartblur=lr=5:ls=-1.0:cr=3:cs=-1.0 [color_out]; [edge_in] edgedetect=low=0.05:high=0.1, negate [edge_out]; [color_out][edge_out] blend=all_mode=multiply" -c:a copy output.mp4

Command Breakdown

Fine-Tuning the Results

You can customize the intensity and style of the cartoon effect by adjusting the filter parameters: