diff --git a/Dockerfile b/Dockerfile index 02e7653..683fd7a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,7 +35,9 @@ FROM python:3.11-slim WORKDIR /app -# Install FFmpeg, OpenCV deps, Node.js + npm + git (for yt-dlp JS + bgutil build) +# Install FFmpeg, OpenCV deps, Node.js + npm + git (for yt-dlp JS + bgutil build). +# fontconfig + fonts-liberation back the subtitle font choices: without real +# fonts libass falls back to DejaVu for every UI option (issue #57). RUN apt-get update && apt-get install -y --no-install-recommends \ ffmpeg \ libgl1 \ @@ -46,6 +48,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ nodejs \ npm \ git \ + fontconfig \ + fonts-liberation \ && rm -rf /var/lib/apt/lists/* # Deno JS runtime — required by yt-dlp for some extractor challenges. @@ -77,6 +81,13 @@ RUN pip install --upgrade --pre --no-cache-dir "yt-dlp[default]" bgutil-ytdlp-po # Copy application code COPY . . +# Register the bundled fonts (Anton for Impact) and the UI-name -> real-font +# aliases with fontconfig so libass resolves what the subtitle modal offers. +RUN mkdir -p /usr/local/share/fonts/openshorts \ + && cp fonts/*.ttf /usr/local/share/fonts/openshorts/ \ + && cp fonts/openshorts-fontmap.conf /etc/fonts/conf.d/60-openshorts.conf \ + && fc-cache -f + # Create a non-root user (Moved up) RUN groupadd -r appuser && useradd -r -g appuser -d /app -s /sbin/nologin appuser diff --git a/fonts/Anton-Regular.ttf b/fonts/Anton-Regular.ttf new file mode 100644 index 0000000..4d65707 Binary files /dev/null and b/fonts/Anton-Regular.ttf differ diff --git a/fonts/openshorts-fontmap.conf b/fonts/openshorts-fontmap.conf new file mode 100644 index 0000000..17b63d3 --- /dev/null +++ b/fonts/openshorts-fontmap.conf @@ -0,0 +1,16 @@ + + + + + VerdanaLiberation Sans + ArialLiberation Sans + HelveticaLiberation Sans + GeorgiaLiberation Serif + ImpactAnton + diff --git a/subtitles.py b/subtitles.py index 6447e0d..08d2d14 100644 --- a/subtitles.py +++ b/subtitles.py @@ -478,12 +478,18 @@ def burn_subtitles(video_path, srt_path, output_path, alignment=2, fontsize=16, f"Bold=1" ) + # Let libass see the fonts bundled with the app (e.g. Anton for Impact) + # even when the system fontconfig has no cache for them. + fonts_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "fonts") + safe_fonts_dir = _escape_ffmpeg_filter_value(fonts_dir) + if str(srt_path).lower().endswith('.ass'): # ASS files (karaoke style) carry their own styles; force_style would # override the per-word color tags. - vf = f"ass='{safe_srt_path}'" + vf = f"ass='{safe_srt_path}':fontsdir='{safe_fonts_dir}'" else: - vf = f"subtitles='{safe_srt_path}':charenc=UTF-8:force_style='{style_string}'" + vf = (f"subtitles='{safe_srt_path}':fontsdir='{safe_fonts_dir}'" + f":charenc=UTF-8:force_style='{style_string}'") cmd = [ 'ffmpeg', '-y', diff --git a/tests/test_subtitles.py b/tests/test_subtitles.py index bc3a4f8..de63b2b 100644 --- a/tests/test_subtitles.py +++ b/tests/test_subtitles.py @@ -205,3 +205,37 @@ class TestGenerateAss: font_color="#FFFFFF", base_opacity=1.0) is True content = out.read_text(encoding="utf-8-sig") assert "&H00FFFFFF" in content # pure white, no dimming + + +class TestBurnFilterFonts: + """The ffmpeg filter must point libass at the bundled fonts dir — without + it every UI font choice silently falls back to DejaVu (issue #57).""" + + def _captured_cmd(self, monkeypatch, tmp_path, srt_name): + import subtitles as m + captured = {} + + class _Ok: + returncode = 0 + stderr = b"" + + def fake_run(cmd, **kwargs): + captured["cmd"] = cmd + return _Ok() + + monkeypatch.setattr(m.subprocess, "run", fake_run) + srt = tmp_path / srt_name + srt.write_text("stub", encoding="utf-8") + m.burn_subtitles("in.mp4", str(srt), "out.mp4", font_name="Impact") + return " ".join(str(c) for c in captured["cmd"]) + + def test_srt_filter_includes_fontsdir(self, monkeypatch, tmp_path): + cmd = self._captured_cmd(monkeypatch, tmp_path, "subs.srt") + assert "fontsdir=" in cmd + assert "force_style=" in cmd + + def test_ass_filter_includes_fontsdir(self, monkeypatch, tmp_path): + cmd = self._captured_cmd(monkeypatch, tmp_path, "subs.ass") + assert "fontsdir=" in cmd + # ASS carries its own styles; force_style must NOT override them + assert "force_style" not in cmd