Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#3253 closed defect (invalid)

drawtext filter: problems with text expansions

Reported by: Andrey Utkin Owned by:
Priority: normal Component: avfilter
Version: unspecified Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no

Description

Summary of the bug:

Text expansion seem to be not working.

How to reproduce:

$ ffmpeg -re -f lavfi -i testsrc -filter:v 'drawtext=text=%{expr:t}:fontfile=/usr/share/fonts/corefonts/verdana.ttf:fontsize=50:fontcolor=red' -y ~/netdisk/tmp/tmp.ts
ffmpeg version N-59414-g8a0d446 Copyright (c) 2000-2013 the FFmpeg developers
  built on Dec 29 2013 16:17:21 with gcc 4.6.3 (Gentoo 4.6.3 p1.13, pie-0.5.2)
  configuration: --enable-gpl --enable-libx264 --enable-encoder=libx264 --disable-stripping --enable-debug --extra-cflags='-O0 -g -ggdb' --enable-libopus --enable-libvpx --enable-x11grab --enable-libfreetype --enable-filter=drawtext
  libavutil      52. 59.100 / 52. 59.100
  libavcodec     55. 47.100 / 55. 47.100
  libavformat    55. 22.100 / 55. 22.100
  libavdevice    55.  5.102 / 55.  5.102
  libavfilter     4.  0.103 /  4.  0.103
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Input #0, lavfi, from 'testsrc':
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 320x240 [SAR 1:1 DAR 4:3], 25 tbr, 25 tbn, 25 tbc
Output #0, mpegts, to '/home/krieger/netdisk/tmp/tmp.ts':
  Metadata:
    encoder         : Lavf55.22.100
    Stream #0:0: Video: mpeg2video, yuv420p, 320x240 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 90k tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo -> mpeg2video)
Press [q] to stop, [?] for help
frame=   35 fps= 26 q=2.0 Lsize=      75kB time=00:00:01.36 bitrate= 451.2kbits/s    
video:65kB audio:0kB subtitle:0 global headers:0kB muxing overhead 15.131411%
Received signal 2: terminating.

The desired effect is printing of timestamp in seconds (see t variable in drawtext doc section). This way we have printed text "t}", which is nonsense.

If we swap the order of filter params "text" and "fontfile", it fails to start. Tried both escaping and not escaping semicolon in expansion block.

 $ ffmpeg -re -f lavfi -i testsrc -filter:v 'drawtext=fontfile=/usr/share/fonts/corefonts/verdana.ttf:text=%{e: t}:fontsize=50:fontcolor=red' -y ~/netdisk/tmp/tmp.ts
ffmpeg version N-59414-g8a0d446 Copyright (c) 2000-2013 the FFmpeg developers
  built on Dec 29 2013 16:17:21 with gcc 4.6.3 (Gentoo 4.6.3 p1.13, pie-0.5.2)
  configuration: --enable-gpl --enable-libx264 --enable-encoder=libx264 --disable-stripping --enable-debug --extra-cflags='-O0 -g -ggdb' --enable-libopus --enable-libvpx --enable-x11grab --enable-libfreetype --enable-filter=drawtext
  libavutil      52. 59.100 / 52. 59.100
  libavcodec     55. 47.100 / 55. 47.100
  libavformat    55. 22.100 / 55. 22.100
  libavdevice    55.  5.102 / 55.  5.102
  libavfilter     4.  0.103 /  4.  0.103
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Input #0, lavfi, from 'testsrc':
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 320x240 [SAR 1:1 DAR 4:3], 25 tbr, 25 tbn, 25 tbc
[Parsed_drawtext_0 @ 0x24cd8a0] Could not load font "t}": cannot open resource
[AVFilterGraph @ 0x24d47e0] Error initializing filter 'drawtext' with args 'fontfile=/usr/share/fonts/corefonts/verdana.ttf:text=%{e: t}:fontsize=50:fontcolor=red'
Error opening filters!
[ERR]
16:56:12krieger@zver /usr/local/src/ffmpeg
 $ ffmpeg -re -f lavfi -i testsrc -filter:v 'drawtext=fontfile=/usr/share/fonts/corefonts/verdana.ttf:text=%{e\: t}:fontsize=50:fontcolor=red' -y ~/netdisk/tmp/tmp.ts
ffmpeg version N-59414-g8a0d446 Copyright (c) 2000-2013 the FFmpeg developers
  built on Dec 29 2013 16:17:21 with gcc 4.6.3 (Gentoo 4.6.3 p1.13, pie-0.5.2)
  configuration: --enable-gpl --enable-libx264 --enable-encoder=libx264 --disable-stripping --enable-debug --extra-cflags='-O0 -g -ggdb' --enable-libopus --enable-libvpx --enable-x11grab --enable-libfreetype --enable-filter=drawtext
  libavutil      52. 59.100 / 52. 59.100
  libavcodec     55. 47.100 / 55. 47.100
  libavformat    55. 22.100 / 55. 22.100
  libavdevice    55.  5.102 / 55.  5.102
  libavfilter     4.  0.103 /  4.  0.103
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Input #0, lavfi, from 'testsrc':
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 320x240 [SAR 1:1 DAR 4:3], 25 tbr, 25 tbn, 25 tbc
[Parsed_drawtext_0 @ 0x1dc28a0] Could not load font "t}": cannot open resource
[AVFilterGraph @ 0x1dc97e0] Error initializing filter 'drawtext' with args 'fontfile=/usr/share/fonts/corefonts/verdana.ttf:text=%{e: t}:fontsize=50:fontcolor=red'
Error opening filters!
[ERR]

Change History (9)

comment:1 by Andrey Utkin, 11 years ago

The example from documentation does not work, too:

text=%{localtime:%a %b %d %Y}

comment:2 by Cigaes, 11 years ago

You probably need to escape the : used in the expansion, to prevent it from delimiting options. Not getting an error is strange though.

in reply to:  2 ; comment:3 by Andrey Utkin, 11 years ago

Replying to Cigaes:

You probably need to escape the : used in the expansion, to prevent it from delimiting options. Not getting an error is strange though.

text=%{expr\:t} works same way and prints "t}".

in reply to:  3 ; comment:4 by Alexander Strasser, 11 years ago

Reproduced by developer: set

Replying to Krieger:

Replying to Cigaes:

You probably need to escape the : used in the expansion, to prevent it from delimiting options. Not getting an error is strange though.

text=%{expr\:t} works same way and prints "t}".

I cannot exactly explain how all this works together, but it seems that you need to deal with another layer of escaping or in other words add another \ . Then it works as expected here.

in reply to:  4 ; comment:5 by Andrey Utkin, 11 years ago

Replying to beastd:

I cannot exactly explain how all this works together, but it seems that you need to deal with another layer of escaping or in other words add another \ . Then it works as expected here.

Share the full working command line, please.

in reply to:  5 comment:6 by Alexander Strasser, 11 years ago

Replying to Krieger:

Replying to beastd:

I cannot exactly explain how all this works together, but it seems that you need to deal with another layer of escaping or in other words add another \ . Then it works as expected here.

Share the full working command line, please.

./ffmpeg -re -f lavfi -i testsrc -filter:v 'drawtext=text=%{expr\\:t}:fontfile=/usr/share/fonts/TTF/DejaVuSans.ttf:fontsize=50:fontcolor=red' -y tmp.ts

in reply to:  4 ; comment:7 by Cigaes, 11 years ago

Replying to beastd:

I cannot exactly explain how all this works together, but it seems that you need to deal with another layer of escaping or in other words add another \ . Then it works as expected here.

You escape once for the drawtext=... option and the parsing until the comma, and a second time for the text=... value and the parsing until the colon before fontfile.

in reply to:  7 comment:8 by Alexander Strasser, 11 years ago

Status: newclosed

Replying to Cigaes:

Replying to beastd:

I cannot exactly explain how all this works together, but it seems that you need to deal with another layer of escaping or in other words add another \ . Then it works as expected here.

You escape once for the drawtext=... option and the parsing until the comma, and a second time for the text=... value and the parsing until the colon before fontfile.

Yes, that should be correct.

So it can be concluded that drawtext function evaluation has nothing to do with this.

To examine this exact example:
The single quotes take the shell out of the game (assuming you use a POSIX-ish shell; I do).
So I will omit them and the additional parameters below.
Now we have this:

drawtext=text=%{expr:t},

It won't work because the drawtext filter's arguments are parsed and the colon will
be seen as delimiter.

drawtext=text=%{expr\:t},

This looks like it would do the trick and escape the colon, but it fails because the
backslash is removed on the first pass. The second pass again interprets the colon as
a delimiter and things go wrong.

drawtext=text=%{expr\\:t},

works because at the first pass the double backslash is substituted with a single
backslash and that single backslash escapes the colon on the second pass which parses
the drawtext filter's arguments.

Therefore I close this ticket now. Please re-open if suggested solution does not work
for you.

comment:9 by Carl Eugen Hoyos, 11 years ago

Resolution: invalid
Note: See TracTickets for help on using tickets.