[FFmpeg-devel] Escaping from the escaping madness

Michael Niedermayer michaelni at gmx.at
Thu Nov 15 20:36:14 CET 2012

On Thu, Nov 15, 2012 at 07:43:10PM +0100, Nicolas George wrote:
> Le quintidi 25 brumaire, an CCXXI, Michael Niedermayer a écrit :
> > Maybe we should make a list of typical cases where escaping is needed
> > and then look at how they would look with alternatives.
> If I take the example of the drawtext filter and the new expansion options I
> am adding, which is probably one of the worst, that would look like that:
> Format string:           %H:%M
> Expansion function call: %{localtime:%H\:%M} or %{localtime:'%H:%M'}
> drawtext argument:       text=%{lt\:%H\\\:%M} or text=%{lt\:\'%H\:%M}
> filter graph:            dt=t=%{lt\\:%H\\\\\\:%M} or dt=t=%{lt\\:\\\'%H\\:%M}
> command-line (shell):    'dt=t=%{lt\\:%H\\\\\\:%M}' or
>                          "dt=t=%{lt\\\\:\\\\\\'%H\\\\:%M}"
> Trying with balanced quotes:
> Format string:           %H:%M
> Expansion function call: %{localtime:“%H:%M”}
> drawtext argument:       text=“%{localtime:“%H:%M”}”
> filter graph:            drawtext=“text=“%{localtime:“%H:%M”}””
> command-line (shell):    'drawtext=“text=“%{localtime:“%H:%M”}””'
> Same with only ASCII, $[...] used for quoting:
> Format string:           %H:%M
> Expansion function call: %{localtime:$[%H:%M]}
> drawtext argument:       text=$[%{localtime:$[%H:%M]}]
> filter graph:            drawtext=$[text=$[%{localtime:$[%H:%M]}]]
> command-line (shell):    'drawtext=$[text=$[%{localtime:$[%H:%M]}]]'

Hmm, we have the following parts
1. Filter names
2. Filter option keys
3. Filter option values

We can easily enforce 1 and 2 to be pure lower case alpha nummeric if
we want, and they probably are already. The problem remaining is thus
only escaping of filter option values.
This shouldnt result in such a mess ...

trying something random, the following might work:


it does not use true escaping, but rather replaces the '=' char as
the start charter before a "Filter option value" with a '('.
At that point only a unpaired ) terminates the option value and nothing
else would need escaping.
As a sideeffect this suggestion would also eliminate the double '='
which may make it easier to understand.

Using the same syntax, a more devilish usecase would be a nested
filtergraph, that is having a full filter graph as a parameter to a


or with some whitespace

'scale = 123 : 456,
 subgraph = graph(
    crop = 456 : 789,
    drawtext = text(localtime:%H:%M) : fontcolor(blue)


Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The bravest are surely those who have the clearest vision
of what is before them, glory and danger alike, and yet
notwithstanding go out to meet it. -- Thucydides
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20121115/0471472b/attachment.asc>

More information about the ffmpeg-devel mailing list