0

When creating a frame count burnin using the drawtext filter, the varying height of the characters makes the text jitter vertically as they count. It is possible to stop this by applying the ‘ascent' value to the y coordinate.

However when this drawtext filter also contains a box around the frame count, this element also jitters vertically and there doesn’t appear to be a way to apply the same method of using the ‘ascent’ value to stabilise it.

Example command (font is relevant to macOS):

ffmpeg -f lavfi -i "color=red:size=1280x720:rate=24" -y -t 12 -c:v mjpeg -qscale:v 4 -huffman default -pix_fmt yuvj422p -vf "drawtext=fontfile=/System/Library/Fonts/Geneva.dfont: fontcolor=white: fontsize=150: box=1: boxcolor=black: boxborderw=5: x=640: y=500-ascent: text=%{n}: start_number=0" output.mov

Is anyone aware of a way to stop this from happening with the box? Many thanks.

Full uncut command:

ffmpeg version N-93020-g3224d6691c-tessus https://evermeet.cx/ffmpeg/ Copyright (c) 2000-2019 the FFmpeg developers built with Apple LLVM version 10.0.0 (clang-1000.11.45.5) 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-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --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. 26.100 / 56. 26.100 libavcodec 58. 44.100 / 58. 44.100 libavformat 58. 26.100 / 58. 26.100 libavdevice 58. 6.101 / 58. 6.101 libavfilter 7. 48.100 / 7. 48.100 libswscale 5. 4.100 / 5. 4.100 libswresample 3. 4.100 / 3. 4.100 libpostproc 55. 4.100 / 55. 4.100 Input #0, lavfi, from 'color=red:size=1280x720:rate=24': Duration: N/A, start: 0.000000, bitrate: N/A Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 24 tbr, 24 tbn, 24 tbc Stream mapping: Stream #0:0 -> #0:0 (rawvideo (native) -> mjpeg (native)) Press [q] to stop, [?] for help [swscaler @ 0x7fce5b00d800] deprecated pixel format used, make sure you did set range correctly Output #0, mov, to 'output.mov': Metadata: encoder : Lavf58.26.100 Stream #0:0: Video: mjpeg (jpeg / 0x6765706A), yuvj422p(pc), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 24 fps, 12288 tbn, 24 tbc Metadata: encoder : Lavc58.44.100 mjpeg Side data: cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1 frame= 288 fps=0.0 q=4.0 Lsize= 7103kB time=00:00:11.95 bitrate=4865.5kbits/s speed=19.7x video:7101kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.027039%

  • You should add a drawbox filter before drawtext and skip box in drawtext. – Gyan Feb 6 at 15:18
  • Yes, that is my backup, but its annoying as you have to allow for the frame counters potential maximum size (7 characters) and create a box thats this size from the start. Its ugly and not as good as having the box grow naturally with the counter which will always start as 4 characters. – mwjb Feb 6 at 20:26
  • The drawtext box size is text size + border. Since the filter can't know in advance how large the height will get, it can't draw a constant sized box from the beginning. – Gyan Feb 7 at 4:53
  • Thanks, that makes sense. Its more that I was seeing if there was a way this had been compensated for. It sounds very much like its something which needs a patch so ascent can be incorporated into the border width calc. – mwjb Feb 8 at 11:52
  • How will that help? The result will still be jittery. What your y expr does is fix the glyphs' baseline alignment. The extent of the glyphs above and below still vary. And those are what the box size depends on. – Gyan Feb 8 at 12:13
0

Using a fixed-height monospaced font for the drawtext filter works around this issue.

Referencing the fixed-height font information here, plus making sure its also a monospaced font. https://graphicdesign.stackexchange.com/questions/111439/is-there-a-font-that-has-the-same-height-for-every-character

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.