[FFmpeg-user] How to properly escape a literal comma ", " in drawtext filter text?

Steven Kan steven at kan.org
Tue Dec 29 03:20:15 EET 2020


> On Dec 28, 2020, at 1:02 PM, Carl Zwanzig <cpz at tuunq.com> wrote:
> 
> On 12/27/2020 11:01 AM, Steven Kan wrote:
>> If I use that exact string, the comma renders as a white box. According
>> to the drawtext documentation, I should escape the comma, but depending
>> on the context I may have to escape the escape character before the
>> comma, etc.
> 
> I'm not on a mac, but it could be the shell mutating the comma or it could be the drawtext filter, don't know. You might try assembling the filter string into a shell variable and dropping that into the command line. Also, try echo-ing the command like into a file to see if the commas are correct.
> 
> You might also try the 'textfile' option instead of 'text' to avoid any munging the shell might do.

Hmmm. I just tried:

./ffmpeg -i /Users/steven/Documents/Baking/4Up.mp4 -t 00:00:02 -vf drawtext="fontfile=/System/Library/Fonts/Keyboard.ttf: fontcolor=white: textfile=/Users/steven/Documents/Baking/UpperLeft.txt'" -c:v libx264 /Users/steven/Documents/Baking/TextwOverlayTest.mp4

where the file UpperLeft.txt contains "Room Temp Water, No Heat Mat,,,,,,,,,” and all the commas renders as boxes.

Text encoding for UpperLeft.txt is UTF-8.

Does this indicate that this is happening within drawtext itself? I’m using the latest snapshot:

./ffmpeg -i /Users/steven/Documents/Baking/4Up.mp4 -t 00:00:02 -vf drawtext="fontfile=/System/Library/Fonts/Keyboard.ttf: fontcolor=white: textfile=/Users/steven/Documents/Baking/UpperLeft.txt'" -c:v libx264 /Users/steven/Documents/Baking/TextwOverlayTest.mp4
ffmpeg version N-100466-g29cef1bcd6-tessus  https://evermeet.cx/ffmpeg/  Copyright (c) 2000-2020 the FFmpeg developers
  built with Apple clang version 11.0.0 (clang-1100.0.33.17)
  configuration: --cc=/usr/bin/clang --prefix=/opt/ffmpeg --extra-version=tessus --enable-avisynth --enable-fontconfig --enable-gpl --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libmysofa --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvmaf --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-version3 --pkg-config-flags=--static --disable-ffplay
  libavutil      56. 62.100 / 56. 62.100
  libavcodec     58.115.102 / 58.115.102
  libavformat    58. 65.100 / 58. 65.100
  libavdevice    58. 11.103 / 58. 11.103
  libavfilter     7. 94.100 /  7. 94.100
  libswscale      5.  8.100 /  5.  8.100
  libswresample   3.  8.100 /  3.  8.100
  libpostproc    55.  8.100 / 55.  8.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/steven/Documents/Baking/4Up.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.62.100
  Duration: 00:00:11.00, start: 0.000000, bitrate: 4114 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 4111 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 0x7f8e5e005000] using SAR=1/1
[libx264 @ 0x7f8e5e005000] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x7f8e5e005000] profile High, level 4.0, 4:2:0, 8-bit
[libx264 @ 0x7f8e5e005000] 264 - core 161 r3027 4121277 - H.264/MPEG-4 AVC codec - Copyleft 2003-2020 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to '/Users/steven/Documents/Baking/TextwOverlayTest.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.65.100
    Stream #0:0(und): Video: h264 (avc1 / 0x31637661), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 25 fps, 12800 tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
      encoder         : Lavc58.115.102 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
frame=   50 fps= 37 q=-1.0 Lsize=     847kB time=00:00:01.88 bitrate=3692.4kbits/s speed=1.41x    
video:846kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.169691%
[libx264 @ 0x7f8e5e005000] frame I:1     Avg QP:25.95  size:153219
[libx264 @ 0x7f8e5e005000] frame P:13    Avg QP:21.47  size: 41041
[libx264 @ 0x7f8e5e005000] frame B:36    Avg QP:23.96  size:  4968
[libx264 @ 0x7f8e5e005000] consecutive B-frames:  2.0%  4.0%  6.0% 88.0%
[libx264 @ 0x7f8e5e005000] mb I  I16..4: 11.5% 56.6% 32.0%
[libx264 @ 0x7f8e5e005000] mb P  I16..4:  2.4%  6.0%  1.8%  P16..4: 41.4%  9.3%  7.4%  0.0%  0.0%    skip:31.7%
[libx264 @ 0x7f8e5e005000] mb B  I16..4:  0.4%  0.7%  0.1%  B16..8: 21.4%  0.6%  0.1%  direct: 2.8%  skip:73.9%  L0:32.7% L1:66.1% BI: 1.2%
[libx264 @ 0x7f8e5e005000] 8x8 transform intra:57.5% inter:76.3%
[libx264 @ 0x7f8e5e005000] coded y,uvDC,uvAC intra: 54.3% 59.3% 19.5% inter: 8.1% 18.1% 0.2%
[libx264 @ 0x7f8e5e005000] i16 v,h,dc,p: 26% 34% 11% 29%
[libx264 @ 0x7f8e5e005000] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 30% 24% 20%  4%  3%  5%  4%  5%  6%
[libx264 @ 0x7f8e5e005000] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 30% 26% 10%  5%  5%  6%  6%  6%  6%
[libx264 @ 0x7f8e5e005000] i8c dc,h,v,p: 44% 29% 23%  4%
[libx264 @ 0x7f8e5e005000] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x7f8e5e005000] ref P L0: 65.6% 11.9% 17.4%  5.2%
[libx264 @ 0x7f8e5e005000] ref B L0: 78.9% 16.9%  4.2%
[libx264 @ 0x7f8e5e005000] ref B L1: 95.5%  4.5%
[libx264 @ 0x7f8e5e005000] kb/s:3462.36



More information about the ffmpeg-user mailing list