lavfi: add drawvg video filter.

The drawvg filter can draw vector graphics on top of a video, using libcairo. It
is enabled if FFmpeg is configured with `--enable-cairo`.

The language for drawvg scripts is documented in `doc/drawvg-reference.texi`.

There are two new tests:

- `fate-filter-drawvg-interpreter` launch a script with most commands, and
  verify which libcairo functions are executed.
- `fate-filter-drawvg-video` render a very simple image, just to verify that
  libcairo is working as expected.

Signed-off-by: Ayose <ayosec@gmail.com>
This commit is contained in:
Ayose
2025-10-18 17:34:36 +00:00
committed by michaelni
parent d77f917621
commit 016d767c8e
16 changed files with 6170 additions and 0 deletions

View File

@@ -28,6 +28,7 @@ HTMLPAGES = $(AVPROGS-yes:%=doc/%.html) $(AVPROGS-yes:%=doc/%-all.html) $(COMP
doc/mailing-list-faq.html \
doc/nut.html \
doc/platform.html \
doc/drawvg-reference.html \
$(SRC_PATH)/doc/bootstrap.min.css \
$(SRC_PATH)/doc/style.min.css \
$(SRC_PATH)/doc/default.css \

2772
doc/drawvg-reference.texi Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -13049,6 +13049,78 @@ For more information about libfribidi, check:
For more information about libharfbuzz, check:
@url{https://github.com/harfbuzz/harfbuzz}.
@anchor{drawvg}
@section drawvg
Draw vector graphics on top of video frames, by executing a script written in
a custom language called VGS (@emph{Vector Graphics Script}).
The documentation for the language can be found in
@ref{,,drawvg - Language Reference,drawvg-reference}.
Graphics are rendered using the @uref{https://cairographics.org/,cario 2D
graphics library}.
To enable compilation of this filter, you need to configure FFmpeg with
@code{--enable-cairo}.
@subsection Parameters
Either @code{script} or @code{file} must be set.
@table @option
@item s, script
Script source to draw the graphics.
@item file
Path of the file to load the script source.
@end table
@subsection Pixel Formats
Since Cairo only supports RGB images, if the input video is something else (like
YUV 4:2:0), before executing the script the video is converted to a format
compatible with Cairo. Then, you have to use use either the @ref{format} filter,
or the @code{-pix_fmt} option, to convert it to the expected format in the
output.
@subsection Examples
@itemize
@item
Draw the outline of an ellipse.
@example
ffmpeg -i input.webm \
-vf 'drawvg=ellipse (w/2) (h/2) (w/3) (h/3) stroke' \
-pix_fmt yuv420p \
output.webm
@end example
@item
Draw a square rotating in the middle of the frame.
The script for drawvg is in a file @code{draw.vgs}:
@example
translate (w/2) (h/2)
rotate t
rect -100 -100 200 200
setcolor red@@0.5
fill
@end example
Then:
@example
ffmpeg -i input.webm -vf 'drawvg=file=draw.vgs,format=yuv420p' output.webm
@end example
@end itemize
@section edgedetect
Detect and draw edges. The filter uses the Canny Edge Detection algorithm.