Skip to content
Tech News
← Back to articles

Drawvg Filter for FFmpeg

read original get DrawVG Filter for FFmpeg → more articles
Why This Matters

The drawvg filter for FFmpeg introduces a powerful way to overlay vector graphics onto videos using a specialized scripting language, VGS. This enhances creative possibilities for dynamic graphics, annotations, and visual effects directly within video processing workflows. Its integration with FFmpeg's existing capabilities makes it a valuable tool for both developers and content creators seeking precise, customizable overlays.

Key Takeaways

drawvg filter for FFmpeg

drawvg is a FFmpeg filter, available since 8.1, to render vector graphics on top of video frames. The render is done by executing a script written in its own language, called VGS (Vector Graphics Script). The script consists of a series of commands to describe 2D graphics, which are rasterized using the Cairo library. VGS is not intended to be used as a general-purpose language. Since its scope is limited, it prioritizes being concise and easy to use. The syntax is heavily inspired by languages like Magick Vector Graphics, or SVG's <path> . Some features of the syntax (like using whitespaces to separate arguments) are also present in languages like TCL or shell scripts. Many command names are taken from PostScript. VGS is fully documented in the language reference. Scripts can use FFmpeg expressions to describe graphics dynamically, so they can compute coordinates based on frame dimensions, frame metadata, generate random values, read pixel colors, etc.

Examples

This is a short list of examples to showcase how to integrate the drawvg filter with other filters in FFmpeg.

The Playground has a gallery with more examples, focused on the capabilities of the VGS language.

Progress Indicator

The variable t can be used to compute one of the angles of the arcn command. Then, we can create an animation like this:

The script can be rendered directly on top of a video:

Output progress.vgs setvar 3 setvar (h / 6) translate (w - R - 5) (R + 5) moveto 0 0 arcn 0 0 R (3 * PI / 2 - (PI * 2 * mod(t - ts, T) / T)) (-PI / 2) setcolor [email protected] fill Shell ffmpeg \ -an \ -ss 12 -t 3 -i bigbuckbunny.mov \ -vf 'crop=iw-1, drawvg=file=progress.vgs, format=yuv420p' \ -c:v libvpx-vp9 \ output.webm

This example uses clips from the Big Buck Bunny movie, available under CC BY 3.0 license.

... continue reading