Opened 10 years ago
Closed 10 years ago
#3758 closed enhancement (fixed)
Right-to-left option for drawtext filter
Reported by: | Andrey Utkin | Owned by: | |
---|---|---|---|
Priority: | wish | Component: | avfilter |
Version: | git-master | Keywords: | drawtext |
Cc: | nfxjfg@googlemail.com | Blocked By: | |
Blocking: | Reproduced by developer: | yes | |
Analyzed by developer: | no |
Description
Summary of the bug:
Arabic text is displayed backwards comparing to supplied parameter.
How to reproduce:
This test requires some font supporting Arabic. Below i use a font supplied by third party, and i didn't get their agreement yet for publishing it here for bug investigation. I don't know which widespread free fonts support Arabic (comments are appreciated).
The issue is reproduced with following command line (i hope non-ASCII Arabic letters won't get garbled at transmission).
I'm not an expert on Arabic, but you can see that there's character like "i" on the right, and on rendered picture it goes on the left. I suppose that's some smartness of libfreetype. Does anybody know how this behaviour could get fixed? Maybe some flag to pass to libfreetype?
$ ffplay -loglevel debug -f lavfi -i "color=color=white,drawtext=fontfile=./samples/editor/projects/stc/fonts/stc-regular-webfont.ttf:text=أحمد" ffplay version N-64175-gb0f3b6d Copyright (c) 2003-2014 the FFmpeg developers built on Jul 3 2014 16:24:25 with gcc 4.7.3 (Gentoo 4.7.3-r1 p1.4, pie-0.5.5) configuration: --enable-libfreetype --enable-gpl --enable-libx264 libavutil 52. 90.100 / 52. 90.100 libavcodec 55. 68.100 / 55. 68.100 libavformat 55. 44.100 / 55. 44.100 libavdevice 55. 13.101 / 55. 13.101 libavfilter 4. 9.100 / 4. 9.100 libswscale 2. 6.100 / 2. 6.100 libswresample 0. 19.100 / 0. 19.100 libpostproc 52. 3.100 / 52. 3.100 detected 4 logical cores 0 aq= 0KB vq= 0KB sq= 0B f=0/0 [Parsed_color_0 @ 0x7fb5dc002060] Setting 'color' to value 'white' [Parsed_color_0 @ 0x7fb5dc002060] size:320x240 rate:25/1 duration:-1.000000 sar:1/1 [Parsed_drawtext_1 @ 0x7fb5dc002b00] Setting 'fontfile' to value './samples/editor/projects/stc/fonts/stc-regular-webfont.ttf' [Parsed_drawtext_1 @ 0x7fb5dc002b00] Setting 'text' to value 'أحمد' [AVFilterGraph @ 0x7fb5dc001580] query_formats: 3 queried, 2 merged, 0 already done, 0 delayed [Parsed_drawtext_1 @ 0x7fb5dc002b00] Copying data in avfilter. [Parsed_drawtext_1 @ 0x7fb5dc002b00] n:0 t:0.000000 text_w:30 text_h:18 x:0 y:0 [lavfi @ 0x7fb5dc000920] All info found Input #0, lavfi, from 'color=color=white,drawtext=fontfile=./samples/editor/projects/stc/fonts/stc-regular-webfont.ttf:text=أحمد': Duration: N/A, start: 0.000000, bitrate: N/A Stream #0:0, 1, 1/25: Video: rawvideo (I420 / 0x30323449), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 1/25, 25 tbr, 25 tbn, 25 tbc [Parsed_drawtext_1 @ 0x7fb5dc002b00] Copying data in avfilter. Video frame changed from size:0x0 format:none serial:-1 to size:320x240 format:yuv420p serial:1 [Parsed_drawtext_1 @ 0x7fb5dc002b00] n:1 t:0.040000 text_w:30 text_h:18 x:0 y:0 [Parsed_drawtext_1 @ 0x7fb5dc002b00] Copying data in avfilter. [ffplay_buffer @ 0x7fb5d4001620] Setting 'video_size' to value '320x240' [Parsed_drawtext_1 @ 0x7fb5dc002b00] n:2 t:0.080000 text_w:30 text_h:18 x:0 y:0 [ffplay_buffer @ 0x7fb5d4001620] Setting 'pix_fmt' to value '0' [ffplay_buffer @ 0x7fb5d4001620] Setting 'time_base' to value '1/25' [ffplay_buffer @ 0x7fb5d4001620] Setting 'pixel_aspect' to value '1/1' [Parsed_drawtext_1 @ 0x7fb5dc002b00] Copying data in avfilter. [ffplay_buffer @ 0x7fb5d4001620] Setting 'frame_rate' to value '25/1' [Parsed_drawtext_1 @ 0x7fb5dc002b00] n:3 t:0.120000 text_w:30 text_h:18 x:0 y:0 [ffplay_buffer @ 0x7fb5d4001620] w:320 h:240 pixfmt:yuv420p tb:1/25 fr:25/1 sar:1/1 sws_param: [ffplay_crop @ 0x7fb5d4002840] Setting 'out_w' to value 'floor(in_w/2)*2' [ffplay_crop @ 0x7fb5d4002840] Setting 'out_h' to value 'floor(in_h/2)*2' [Parsed_drawtext_1 @ 0x7fb5dc002b00] Copying data in avfilter. [Parsed_drawtext_1 @ 0x7fb5dc002b00] n:4 t:0.160000 text_w:30 text_h:18 x:0 y:0 [AVFilterGraph @ 0x7fb5d4000d40] query_formats: 3 queried, 2 merged, 0 already done, 0 delayed [ffplay_crop @ 0x7fb5d4002840] w:320 h:240 sar:1/1 -> w:320 h:240 sar:1/1 [Parsed_drawtext_1 @ 0x7fb5dc002b00] Copying data in avfilter. [Parsed_drawtext_1 @ 0x7fb5dc002b00] n:5 t:0.200000 text_w:30 text_h:18 x:0 y:0 [Parsed_drawtext_1 @ 0x7fb5dc002b00] Copying data in avfilter. [Parsed_drawtext_1 @ 0x7fb5dc002b00] n:6 t:0.240000 text_w:30 text_h:18 x:0 y:0 [Parsed_drawtext_1 @ 0x7fb5dc002b00] Copying data in avfilter. [Parsed_drawtext_1 @ 0x7fb5dc002b00] n:7 t:0.280000 text_w:30 text_h:18 x:0 y:0 [Parsed_drawtext_1 @ 0x7fb5dc002b00] Copying data in avfilter. [Parsed_drawtext_1 @ 0x7fb5dc002b00] n:8 t:0.320000 text_w:30 text_h:18 x:0 y:0 [Parsed_drawtext_1 @ 0x7fb5dc002b00] Copying data in avfilter.
Change History (8)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
Cc: | added |
---|
libfreetype does not do text layout. For correct Arabic display, one would have to involve the libfribidi and harfbuzz libraries. Or use libass.
comment:3 by , 10 years ago
Keywords: | libfreetype removed |
---|---|
Priority: | normal → wish |
Reproduced by developer: | set |
Status: | new → open |
Type: | defect → enhancement |
A right-to-left option for the drawtext filter appears useful to me.
comment:4 by , 10 years ago
I still don't understand why some explicit actions must be taken for correct displaying of any correct supplied UTF-8 string (i think Arabic text is nothing more than UTF-8 string).
comment:5 by , 10 years ago
i think Arabic text is nothing more than UTF-8 string
It's not as simple, because Arabic text needs to be rendered in the opposite direction of western text. Freetype is quite low level and doesn't render text, it merely renders glyphs. Additionally to that, Arabic text has complex layout rules, which requires handling combining glyphs and such. libfribidi and Harfbuzz were created to handle these issues. A naive option to render text RTL might work in simple scenarios, but will surely fail in more complex cases, and thus would be a bad hack at best.
comment:6 by , 10 years ago
Summary: | drawtext filter reverses Arabic text → Right-to-left option for drawtext filter |
---|
comment:8 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | open → closed |
Fixed by Marc Jeffreys in a0b71e9f3e95d22b098e4d81c26d3bfe1f53249f
Found a free Arabic-enabled font: DejaVuSans, in Gentoo it is available in media-fonts/dejavu package.