Document drawtext overlay settings for easy customization

Adds a quick-edit cheatsheet covering font, color, size, position, and
shadow/border for the sunrise-time overlay so the layout can be tweaked
without grokking ffmpeg's drawtext syntax.
This commit is contained in:
Claude
2026-04-29 18:20:20 +00:00
parent 119d58ad4c
commit cba5b5b1e8
+93
View File
@@ -140,6 +140,20 @@ if $TEST_MODE; then
fi
# ── Font detection ────────────────────────────────────────────────────────────
# Picks a TrueType font file for ffmpeg's drawtext filter. drawtext needs an
# absolute path to a .ttf/.otf file — it cannot use a font *name* like Arial.
#
# To use a different font:
# 1. Find the .ttf path on this machine, e.g.:
# fc-match "Liberation Mono" --format='%{file}\n'
# find /usr/share/fonts -name '*.ttf' | grep -i mono
# 2. Either (a) hard-code it below by replacing the fc-match line with:
# FONT="/usr/share/fonts/truetype/liberation/LiberationMono-Bold.ttf"
# or (b) change the fc-match query string ("DejaVu Sans:style=Regular")
# to your preferred face, e.g. "Liberation Mono:style=Bold".
# 3. Add the chosen path to the fallback list below so the script still works
# if fc-match is missing.
# Bold faces (e.g. DejaVuSans-Bold.ttf) read better at small sizes against sky.
FONT=""
if command -v fc-match &>/dev/null; then
FONT=$(fc-match "DejaVu Sans:style=Regular" --format="%{file}" 2>/dev/null || true)
@@ -198,20 +212,99 @@ $TEST_MODE || echo "Speed-adjusted: ${sped_dur}s (saved — overlay still pendi
$TEST_MODE && echo "Speed-adjusted: ${sped_dur}s"
# ── Build overlay filter ──────────────────────────────────────────────────────
# Burns the sunrise time onto the video using ffmpeg's drawtext filter.
# Layout is VERTICAL — each character of "HH:MM" is on its own line, stacked
# top-to-bottom in the lower-right corner. This is achieved by writing each
# char to a separate line of $temp_text, then drawtext renders that file
# verbatim (newlines = line breaks).
#
# To switch to a HORIZONTAL "HH:MM" overlay, replace the printf below with:
# printf '%s' "$SR_TIME" > "$temp_text"
# and bump fontsize (e.g. h/18) since horizontal text needs less vertical room.
#
# ── Quick-edit cheatsheet for every drawtext parameter ──────────────────────
#
# FONT FILE (set above in the "Font detection" block, not here).
# drawtext requires a .ttf path, not a font name.
#
# fontcolor Text color. Accepts named colors (yellow, white, red, cyan,
# orange, lime, magenta, gray) or hex (0xFFCC00, 0xFF8800).
# The "@N" suffix is opacity 0.01.0; comes from
# SUNRISE_OVERLAY_OPACITY in sky-cam.conf. Examples:
# fontcolor=white@0.7 # softer white, 70% opaque
# fontcolor=0xFF8800@0.9 # warm orange, 90% opaque
#
# fontsize Pixel height of glyphs. "h/22" = video-height / 22, so it
# scales with resolution (1080p → ~49px, 720p → ~33px). Use a
# smaller divisor for BIGGER text:
# fontsize=h/30 → small fontsize=h/22 → current
# fontsize=h/18 → medium fontsize=h/14 → large
# Or set an absolute pixel size: fontsize=48
#
# line_spacing Pixels of gap between the stacked characters. Increase for
# a more spaced look (e.g. 8 or 12); 0 packs them tight.
#
# x , y Position of the text box. ffmpeg exposes:
# w = video width h = video height
# tw = text width th = text height
# Current values place the box in the BOTTOM-RIGHT with an
# 18px right margin and a bottom margin of 18px + 5% of height.
# Recipes for the other corners (keep ~18px breathing room):
# Top-left: x=18 y=18
# Top-right: x=w-tw-18 y=18
# Bottom-left: x=18 y=h-th-18-h*0.05
# Bottom-right: x=w-tw-18 y=h-th-18-h*0.05 (current)
# Centered: x=(w-tw)/2 y=(h-th)/2
# Centered top: x=(w-tw)/2 y=24
# To nudge the current spot, change the "18" margins or the
# "h*0.05" lift (5% above the bottom edge — raise to 0.08 to
# clear a status bar, lower to 0.0 to sit flush at the bottom).
#
# shadowcolor / shadowx / shadowy
# A 1-pixel black drop-shadow @55% opacity for legibility against
# bright sky. Set shadowx=shadowy=0 to disable. For a thicker
# outline, swap the shadow* lines for:
# :borderw=2:bordercolor=black@0.7
# (borderw = outline thickness in pixels.)
#
# Other useful drawtext options you can append with ":name=value":
# box=1:boxcolor=black@0.4:boxborderw=6 # solid background pill
# alpha='if(lt(t,1),t,1)' # 1-second fade-in
# enable='between(t,2,8)' # only show 2s8s
#
# Full reference: https://ffmpeg.org/ffmpeg-filters.html#drawtext
DT=""
if [ "${SUNRISE_OVERLAY_ENABLED:-true}" = "true" ]; then
# Vertical layout: write each char of "HH:MM" on its own line.
# SR_TIME is exactly 5 chars (e.g. "06:42"); indices 0..4 below.
# Switch to horizontal by replacing this printf with: printf '%s' "$SR_TIME" > "$temp_text"
temp_text=$(mktemp --suffix=.txt)
printf '%s\n%s\n%s\n%s\n%s' \
"${SR_TIME:0:1}" "${SR_TIME:1:1}" "${SR_TIME:2:1}" "${SR_TIME:3:1}" "${SR_TIME:4:1}" \
> "$temp_text"
# Source the glyph file + the text. fontfile is omitted if FONT detection
# failed above, in which case ffmpeg falls back to its built-in font.
if [ -n "$FONT" ]; then
DT="drawtext=fontfile='${FONT}':textfile='${temp_text}'"
else
DT="drawtext=textfile='${temp_text}'"
fi
# Color + opacity. Change "yellow" to any color name or 0xRRGGBB.
# Opacity comes from SUNRISE_OVERLAY_OPACITY in sky-cam.conf.
DT="${DT}:fontcolor=yellow@${SUNRISE_OVERLAY_OPACITY}"
# Size + spacing. fontsize is relative to video height (h/22).
DT="${DT}:fontsize=h/22:line_spacing=4"
# Position — bottom-right corner. See the corner recipes in the comment
# block above. The "18" values are pixel margins; "h*0.05" lifts the box
# 5% of the height off the bottom so it doesn't kiss the frame edge.
DT="${DT}:x=w-tw-18:y=h-th-18-h*0.05"
# Drop-shadow for legibility. Set shadowx=shadowy=0 to disable, or swap
# for :borderw=2:bordercolor=black@0.7 for a thicker outline.
DT="${DT}:shadowcolor=black@0.55:shadowx=1:shadowy=1"
fi