Escape a value for use inside a drawtext text= option.
Unlike escapeFilterValue, %{...} expansions (e.g. %{pts_hms},
%{eif:t\:b}) are passed through untouched. Escaping a colon inside one
turns %{eif:t%b} into %{eif\\:t%b}, which ffmpeg no longer evaluates as an
expression - so the surrounding text is escaped and the expressions are not.
Scanned with indexOf rather than /%\{[^}]*\}/g. That regex is quadratic:
with no closing brace in the input, each of the many %{ positions rescans the
rest of the string looking for }, so a 192 KB value took 36.8 seconds
(CodeQL js/polynomial-redos). A single forward pass with indexOf is linear.
An unterminated %{ is treated as ordinary text, since ffmpeg would not expand
it either.
Escape a value for use inside a drawtext
text=option.Unlike escapeFilterValue,
%{...}expansions (e.g.%{pts_hms},%{eif:t\:b}) are passed through untouched. Escaping a colon inside one turns%{eif:t%b}into%{eif\\:t%b}, which ffmpeg no longer evaluates as an expression - so the surrounding text is escaped and the expressions are not.Scanned with
indexOfrather than/%\{[^}]*\}/g. That regex is quadratic: with no closing brace in the input, each of the many%{positions rescans the rest of the string looking for}, so a 192 KB value took 36.8 seconds (CodeQL js/polynomial-redos). A single forward pass withindexOfis linear.An unterminated
%{is treated as ordinary text, since ffmpeg would not expand it either.