@auscera/cleoedits 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -2
- package/cli.mjs +149 -0
- package/lib/dependencies.mjs +384 -0
- package/lib/run.mjs +114 -0
- package/lib/workspace.mjs +167 -0
- package/package.json +240 -3
- package/workspace/.agents/skills/cleoedits/SKILL.md +29 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/audiogram.json +41 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/facebook.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/linkedin.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/podcast.json +23 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/reels.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/shorts.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/tiktok.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/x.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/youtube-shorts.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/youtube.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/assets/LICENSE-SimpleIcons +30 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/assets/logos.json +1 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Anton-Regular.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/ArchivoBlack-Regular.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/InstrumentSerif-Italic.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Inter.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/LICENSE-PermanentMarker.txt +202 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Montserrat.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-Anton.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-ArchivoBlack.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-InstrumentSerif.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-Inter.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-Montserrat.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-PlayfairDisplay.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-Poppins.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-SpaceMono.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/PermanentMarker-Regular.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/PlayfairDisplay-Italic.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/PlayfairDisplay.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Poppins-Black.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Poppins-Bold.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Poppins-ExtraBold.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/SpaceMono-Bold.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/models/LICENSE-MediaPipe +218 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/models/LICENSE-YuNet +21 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/models/NOTICE.md +4 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/models/selfie_segmenter.tflite +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/models/yunet.onnx +0 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/LICENSE +21 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/audio-app-ui/STYLE.md +65 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/blueprint/STYLE.md +53 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/blueprint/index.html +328 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/blueprint/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/data-story/STYLE.md +65 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/data-story/index.html +575 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/design-app-ui/STYLE.md +68 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/editor-ui/STYLE.md +73 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/editorial-paper/STYLE.md +54 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/editorial-paper/index.html +189 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/editorial-paper/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/explainer-diagram/STYLE.md +64 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/explainer-diagram/index.html +620 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/graphite-ui/STYLE.md +55 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/graphite-ui/index.html +238 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/graphite-ui/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/growing-city/STYLE.md +66 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/growing-city/index.html +602 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/ink-line/STYLE.md +66 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/ink-line/index.html +777 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/midnight-grid/STYLE.md +56 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/midnight-grid/index.html +186 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/midnight-grid/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/motion-app-ui/STYLE.md +68 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/paper-cut/STYLE.md +56 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/paper-cut/index.html +244 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/paper-cut/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/paper-world/STYLE.md +67 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/paper-world/index.html +663 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/particle-field/STYLE.md +59 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/particle-field/index.html +395 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/poster-pop/STYLE.md +52 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/poster-pop/index.html +194 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/poster-pop/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/risograph/STYLE.md +58 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/risograph/index.html +242 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/risograph/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/swiss-grid/STYLE.md +53 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/swiss-grid/index.html +138 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/swiss-grid/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/swiss-kinetic/STYLE.md +63 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/swiss-kinetic/index.html +599 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/time-travel/STYLE.md +65 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/time-travel/index.html +1297 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/weather-widget/STYLE.md +69 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/weather-widget/index.html +674 -0
- package/workspace/.agents/skills/cleoedits/references/audio-clearervoice-elevenlabs.md +11 -0
- package/workspace/.agents/skills/cleoedits/references/ffmpeg-and-reels.md +15 -0
- package/workspace/.agents/skills/cleoedits/references/hyperframes-workflows.md +13 -0
- package/workspace/.agents/skills/cleoedits/references/kdenlive-cli-and-mcp.md +12 -0
- package/workspace/.agents/skills/cleoedits/references/motion-design-pipeline.md +7 -0
- package/workspace/.agents/skills/cleoedits/references/motion-taste-emil.md +5 -0
- package/workspace/.agents/skills/cleoedits/references/playwright-demo-capture.md +9 -0
- package/workspace/.agents/skills/cleoedits/references/remotion-workflows.md +13 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/LICENSE +21 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_ass_overlay.py +399 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/__init__.py +235 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/alpha.py +560 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/asr.py +1237 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/color.py +540 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/decision.py +2452 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/drawtext.py +290 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/emit.py +1309 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/emoji.py +518 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/fonts.py +875 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/pacing.py +263 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/pacing_edit.py +432 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/probe.py +1613 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/runner.py +3994 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/text.py +73 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/timeline.py +721 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/wrap.py +981 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_contract.py +2454 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_platforms.py +258 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_review.html +754 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_review.py +258 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_smartcut.py +450 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/audio.py +867 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/background.py +136 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/batch.py +1409 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/broll.py +282 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/caption.py +2207 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/check.py +815 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/color.py +695 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/crop.py +91 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/cropdetect.py +214 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/cut.py +2076 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/deinterlace.py +90 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/denoise.py +94 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/export.py +1033 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/fit.py +729 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/freeze.py +197 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/graphics.py +920 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/grid.py +235 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/insert.py +142 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/join.py +1083 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/look.py +475 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/loop.py +395 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/loudness.py +397 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/metadata.py +416 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/multicam.py +414 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/overlay.py +766 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/pad.py +121 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/probe.py +145 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/proxy.py +93 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/redact.py +162 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/render.py +2424 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/report.py +354 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/reverse.py +114 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/scenes.py +439 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/sequence.py +285 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/silence.py +945 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/speedramp.py +193 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/sphere.py +137 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/stabilize.py +141 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/straighten.py +120 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/sync.py +500 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/verify.py +411 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/waveform.py +502 -0
- package/workspace/.agents/skills/cleoedits/scripts/kdenlive_builder.py +284 -0
- package/workspace/.agents/skills/cleoedits/scripts/motion/LICENSE-claude-motion +21 -0
- package/workspace/.agents/skills/cleoedits/scripts/motion/LICENSE-motion-design +21 -0
- package/workspace/.agents/skills/cleoedits/scripts/motion/_media.py +43 -0
- package/workspace/.agents/skills/cleoedits/scripts/motion/pacing_check.py +90 -0
- package/workspace/.agents/skills/cleoedits/scripts/motion/storyboard.py +77 -0
- package/workspace/.agents/skills/cleoedits/scripts/reel_effects/LICENSE +26 -0
- package/workspace/.agents/skills/cleoedits/scripts/reel_effects/fx.py +2717 -0
- package/workspace/.agents/skills/cleoedits/scripts/reel_effects/logos.py +194 -0
- package/workspace/.agents/skills/cleoedits/scripts/reel_effects/sfx.py +105 -0
- package/workspace/.agents/skills/cleoedits/scripts/reel_effects/trim.py +99 -0
- package/workspace/.agents/skills/cleoedits/scripts/reel_effects/words.py +60 -0
- package/workspace/.claude/commands/blender-3d.md +12 -0
- package/workspace/.claude/commands/business-short-form-reels.md +12 -0
- package/workspace/.claude/commands/color-grade.md +12 -0
- package/workspace/.claude/commands/cutout-grid-reel.md +12 -0
- package/workspace/.claude/commands/depth-ui-reel.md +12 -0
- package/workspace/.claude/commands/explainer-panel-reel.md +12 -0
- package/workspace/.claude/commands/freeze-frame.md +12 -0
- package/workspace/.claude/commands/glass-graph.md +12 -0
- package/workspace/.claude/commands/over-the-shoulder.md +12 -0
- package/workspace/.claude/commands/personal-short-form-reels.md +12 -0
- package/workspace/.claude/commands/ranking-format.md +12 -0
- package/workspace/.claude/commands/relight.md +12 -0
- package/workspace/.claude/commands/reverse-engineer.md +12 -0
- package/workspace/.claude/commands/text-behind.md +12 -0
- package/workspace/.claude/commands/tier-list.md +12 -0
- package/workspace/.claude-plugin/plugin.json +8 -0
- package/workspace/.npmignore +15 -0
- package/workspace/AGENTS.md +30 -0
- package/workspace/README.md +63 -0
- package/workspace/assets/fonts/TikTokSans-OFL.txt +93 -0
- package/workspace/assets/fonts/TikTokSans-Variable.ttf +0 -0
- package/workspace/assets/luts/clean_warm.cube +4917 -0
- package/workspace/assets/luts/golden_hour.cube +4917 -0
- package/workspace/assets/luts/moody_dark.cube +4917 -0
- package/workspace/assets/luts/teal_orange.cube +4917 -0
- package/workspace/assets/sfx/NOTICE.txt +1 -0
- package/workspace/assets/sfx/click.wav +0 -0
- package/workspace/assets/sfx/pop.wav +0 -0
- package/workspace/assets/sfx/riser.wav +0 -0
- package/workspace/assets/sfx/whoosh.wav +0 -0
- package/workspace/generators/hyperframes/index.html +39 -0
- package/workspace/generators/hyperframes/package.json +15 -0
- package/workspace/generators/hyperframes/pnpm-lock.yaml +1181 -0
- package/workspace/generators/hyperframes/pnpm-workspace.yaml +10 -0
- package/workspace/generators/remotion/eslint.config.mjs +3 -0
- package/workspace/generators/remotion/package.json +36 -0
- package/workspace/generators/remotion/pnpm-lock.yaml +4179 -0
- package/workspace/generators/remotion/pnpm-workspace.yaml +10 -0
- package/workspace/generators/remotion/remotion.config.ts +13 -0
- package/workspace/generators/remotion/src/Root.tsx +52 -0
- package/workspace/generators/remotion/src/index.css +1 -0
- package/workspace/generators/remotion/src/index.ts +4 -0
- package/workspace/generators/remotion/tsconfig.json +15 -0
- package/workspace/pipeline/scripts/_codec.py +28 -0
- package/workspace/pipeline/scripts/ai_media_api.py +109 -0
- package/workspace/pipeline/scripts/blender_render.py +166 -0
- package/workspace/pipeline/scripts/composite.py +49 -0
- package/workspace/pipeline/scripts/melt.sh +68 -0
- package/workspace/pipeline/scripts/normalize_audio.py +39 -0
- package/workspace/pipeline/scripts/person_matte.py +216 -0
- package/workspace/pipeline/scripts/record_demo.py +69 -0
- package/workspace/pipeline/scripts/whisper_cut.py +98 -0
- package/workspace-manifest.json +908 -0
|
@@ -0,0 +1,920 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Motion-graphics templates rendered with drawbox/drawtext expressions —
|
|
3
|
+
no After Effects, no image assets, brand colours from brand.json.
|
|
4
|
+
|
|
5
|
+
Templates:
|
|
6
|
+
lower-third name + title bar sliding in from the left (--name, --title)
|
|
7
|
+
title centred title card with optional subtitle, fade in/out (--title, --subtitle)
|
|
8
|
+
chapter small chip in a corner (--title), e.g. "Part 2 — Setup"
|
|
9
|
+
progress thin progress bar along the bottom that fills over the clip (or --start/--end)
|
|
10
|
+
countdown big numbers counting down from --from to 0 (--start/--end define the window)
|
|
11
|
+
bug persistent text bug (--title) in a corner, e.g. "@handle" or "LIVE"
|
|
12
|
+
sticker rounded filled chip of --text that pops in at --position (the social sticker)
|
|
13
|
+
hook full-width opening title card (--title) for --duration seconds with a thin
|
|
14
|
+
progress bar along the top -- the TikTok/Shorts opener
|
|
15
|
+
meme white upper-case --top / --bottom lines with a heavy black outline
|
|
16
|
+
|
|
17
|
+
Examples:
|
|
18
|
+
python3 graphics.py talk.mp4 --template lower-third --name "Ada Lovelace" --title "Analyst" --start 2 --end 8
|
|
19
|
+
python3 graphics.py talk.mp4 --template title --title "Episode 12" --subtitle "The math of video" --start 0 --end 4
|
|
20
|
+
python3 graphics.py talk.mp4 --template progress --brand brand.json
|
|
21
|
+
python3 graphics.py intro.mp4 --template countdown --from 5 --start 1 --end 6
|
|
22
|
+
python3 graphics.py talk.mp4 --template lower-third --name "김민준" --title "감독" --lang ko
|
|
23
|
+
python3 graphics.py clip.mp4 --template chapter --title "Part 2 — Setup" --position top-left --start 0 --end 5
|
|
24
|
+
python3 graphics.py reel.mp4 --template sticker --text "NEW" --position top-right --platform tiktok
|
|
25
|
+
python3 graphics.py reel.mp4 --template hook --title "How I cut this in one command" --duration 3
|
|
26
|
+
python3 graphics.py clip.mp4 --template meme --top "when the render" --bottom "finally finishes"
|
|
27
|
+
python3 background.py --transparent --duration 4 --width 1920 --height 1080 -o canvas.mov
|
|
28
|
+
python3 graphics.py canvas.mov --template lower-third --name "Ada Lovelace" --keep-alpha -o lower_third.mov
|
|
29
|
+
"""
|
|
30
|
+
import argparse
|
|
31
|
+
import os
|
|
32
|
+
import re
|
|
33
|
+
import sys
|
|
34
|
+
from typing import List, Optional, Tuple
|
|
35
|
+
|
|
36
|
+
from _platforms import PLATFORMS, PLATFORM_CHOICES, safe_margins_px, resolve as resolve_platform
|
|
37
|
+
from _common.emoji import emoji_missing_asset_note, emoji_mono_on_colour_note
|
|
38
|
+
from _common.drawtext import shaping_refusal
|
|
39
|
+
from _common import (guard_sidecar, refuse_output_is_input, require_filter, aac_args, add_common, brand_caption_style, script_font_for_text, apply_common, cfr_args, cfr_at_input, with_cfr,
|
|
40
|
+
color_hex, default_output, die, draws_chroma, drawn_chain, emit, escape_drawtext, escape_filter_path,
|
|
41
|
+
ffmpeg_base, info, layer_base_chain, load_brand, overlay_format, probe, rgb_chain_to_bt709, run_keeping_subtitles, video_args,
|
|
42
|
+
drawtext_boxborderw, drawtext_center_align, X264_PRESETS, time_arg, fmt_secs, STATE, drawtext_text_opts,
|
|
43
|
+
LANGUAGE_NAMES, needs_shaping, detect_script, BIDI_SCRIPTS, font_family_of_file, font_family_for_script, has_emoji,
|
|
44
|
+
emoji_clusters, emoji_codepoint_name, char_script, emoji_filter_chain, emoji_asset_for, emoji_support, resolve_emoji_assets,
|
|
45
|
+
EMOJI_ASSET_HINT, text_width_em, wrap_text, WRAP_MODES,
|
|
46
|
+
SAFE_WIDTH_FRACTION, drawtext_draws_newline_glyph, is_multiline, _DRAWTEXT_PENDING)
|
|
47
|
+
from _common.emit import note, warn
|
|
48
|
+
from _common.alpha import (add_alpha_args, audio_line, check_alpha_args, decoder_args_for, default_ext, finish_chain,
|
|
49
|
+
report as alpha_report, source_alpha, source_format, tag_args, video_line)
|
|
50
|
+
from _common.fonts import font_choice, record_font_choice, require_font_file
|
|
51
|
+
from _common.probe import display_size, square_pixels, square_pixels_note
|
|
52
|
+
from _ass_overlay import text_overlay_ass, EMOJI_SENTINEL
|
|
53
|
+
from _common import drawtext_fontfile # noqa: E402
|
|
54
|
+
from _common.decision import window_expr, windowed_overlay_x # noqa: E402
|
|
55
|
+
from _common.emit import input_length # noqa: E402
|
|
56
|
+
|
|
57
|
+
# where the template's text chain goes in a filter_complex it builds (graphics.main fills it in)
|
|
58
|
+
TEXT = "@TEXT@"
|
|
59
|
+
BOX = "@BOX@" # a box's place in the filter chain, followed by its index (graphics.main fill_box)
|
|
60
|
+
TEMPLATES = ["lower-third", "title", "chapter", "progress", "countdown", "bug", "sticker", "hook", "meme"]
|
|
61
|
+
# --dry-run on an input that does not exist yet, with no --end: how long after --start the planned
|
|
62
|
+
# graphic ends (its length is unknown; the plan says so in a note)
|
|
63
|
+
PENDING_PLACEHOLDER_SECONDS = 10.0
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def ff_color(hex_rgb: str, alpha: float = 1.0) -> str:
|
|
67
|
+
return f"0x{color_hex(hex_rgb)}@{alpha:g}"
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def font_opts(brand: dict, font: Optional[str], font_file: Optional[str], script_file: Optional[str] = None,
|
|
71
|
+
script_family: Optional[str] = None, renderer: str = "drawtext") -> "Tuple[str, dict]":
|
|
72
|
+
"""(the drawtext font option, the choice behind it -- the result's `font_used`): the caller's
|
|
73
|
+
file, a font picked by the script of the text itself (1.12), the asked family resolved to a
|
|
74
|
+
file, or the family by name when nothing resolves."""
|
|
75
|
+
choice = font_choice(font or brand.get("font", "DejaVu Sans"), font_file=font_file or brand.get("font_file"),
|
|
76
|
+
script_file=script_file, script_family=script_family, renderer=renderer)
|
|
77
|
+
if choice["file"]:
|
|
78
|
+
return drawtext_fontfile(choice['file']), choice
|
|
79
|
+
return f"font='{escape_drawtext(font or brand.get('font', 'DejaVu Sans'))}'", choice
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def main(force_route: Optional[str] = None) -> int:
|
|
83
|
+
"""`force_route` is the second pass of an auto run whose drawtext labels came out multi-line on a
|
|
84
|
+
build that draws a box at every line break (see the check after the templates)."""
|
|
85
|
+
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
86
|
+
ap.add_argument("input")
|
|
87
|
+
ap.add_argument("-o", "--output", help="output file (default: <name>_gfx.<ext>)")
|
|
88
|
+
ap.add_argument("--audio-stream", type=int, default=0,
|
|
89
|
+
help="which audio stream of the input to keep, 0-based in file order (probe.py lists them under "
|
|
90
|
+
"audio_streams) -- matters on a multi-track input (dubbed languages, M&E stems); default 0, "
|
|
91
|
+
"the first track, same as leaving it unset always did")
|
|
92
|
+
ap.add_argument("--template", choices=TEMPLATES, required=True, help="graphic to draw: " + ", ".join(TEMPLATES))
|
|
93
|
+
ap.add_argument("--brand", help="brand.json for colours, font, safe margin")
|
|
94
|
+
ap.add_argument("--name", help="lower-third: name line")
|
|
95
|
+
ap.add_argument("--title", help="title / chapter / bug / hook text, or lower-third second line")
|
|
96
|
+
ap.add_argument("--text", help="sticker: the chip's text")
|
|
97
|
+
ap.add_argument("--top", help="meme: upper line")
|
|
98
|
+
ap.add_argument("--bottom", help="meme: lower line")
|
|
99
|
+
ap.add_argument("--duration", type=float, default=3.0, help="hook: seconds the opening card stays up (default 3)")
|
|
100
|
+
ap.add_argument("--subtitle", help="title: smaller second line")
|
|
101
|
+
ap.add_argument("--from", dest="count_from", type=int, default=5, help="countdown start number, 0..600 (default 5)")
|
|
102
|
+
ap.add_argument("--start", help="show from (default 0)")
|
|
103
|
+
ap.add_argument("--end", help="hide after (default end of clip)")
|
|
104
|
+
ap.add_argument("--position", choices=["top-left", "top-right", "bottom-left", "bottom-right"], default=None, help="corner for chapter/bug/sticker (default bottom-left / top-right / top-right)")
|
|
105
|
+
ap.add_argument("--margin", type=int, default=None, help="distance from the frame edge in px (default: brand safe_margin, or the --platform safe zone)")
|
|
106
|
+
ap.add_argument("--platform", choices=PLATFORM_CHOICES, default=None,
|
|
107
|
+
help="keep the graphic out of this destination's UI: margins become the platform's safe zone "
|
|
108
|
+
"(TikTok's description bar and like column, the Reels/Shorts chrome). An explicit --margin wins")
|
|
109
|
+
ap.add_argument("--primary", help="override brand primary colour RRGGBB")
|
|
110
|
+
ap.add_argument("--text-color", help="override text colour RRGGBB")
|
|
111
|
+
ap.add_argument("--font", help="font family (fontconfig name; default DejaVu Sans, or the --brand file's font)")
|
|
112
|
+
ap.add_argument("--font-file", help="explicit .ttf/.otf/.ttc path (use this for CJK fonts)")
|
|
113
|
+
ap.add_argument("--lang", help="language code of the text (e.g. ja, zh, ko): the hint that says whether Han-only "
|
|
114
|
+
"text is Chinese, Japanese or Korean when a font is picked by script")
|
|
115
|
+
ap.add_argument("--scale", type=float, default=1.0, help="size multiplier (default 1)")
|
|
116
|
+
ap.add_argument("--wrap", choices=list(WRAP_MODES), default="phrase",
|
|
117
|
+
help="how a label too wide for the frame is broken into lines: 'phrase' (default, 1.16) never "
|
|
118
|
+
"breaks inside a word or a hyphen's wrong side, never leaves a lone digit, kana or "
|
|
119
|
+
"punctuation on its own line, prefers Japanese sentence ends and particles, and never ends "
|
|
120
|
+
"a line on an article or preposition; 'measured' is 1.15's width-only wrap. A label that "
|
|
121
|
+
"already fits one line is untouched either way")
|
|
122
|
+
ap.add_argument("--text-render", choices=["auto", "ass", "drawtext"], default="auto",
|
|
123
|
+
help="which renderer draws the template's text: 'auto' (default) uses libass for "
|
|
124
|
+
"scripts drawtext cannot shape (Devanagari, Bengali, Tamil, Thai, Lao ...) and for "
|
|
125
|
+
"emoji overlays, and for multi-line text on FFmpeg 8.0, 8.0.1 and 8.1.0 (their drawtext draws "
|
|
126
|
+
"a box at each line break), and drawtext for everything else -- Latin/CJK/Arabic frames are "
|
|
127
|
+
"pixel-identical to 1.14 (the drawtext command itself changed: the label is "
|
|
128
|
+
"passed as textfile=, not text=); 'ass' always uses libass; 'drawtext' forces the old renderer and is "
|
|
129
|
+
"refused for a script it cannot shape")
|
|
130
|
+
ap.add_argument("--write-ass", metavar="PATH",
|
|
131
|
+
help="where to save the generated ASS when the libass route is used (default: <output stem>_gfx.ass)")
|
|
132
|
+
emo = ap.add_argument_group("emoji (1.15)")
|
|
133
|
+
emo.add_argument("--emoji", choices=["auto", "color", "png", "mono", "none"], default="auto",
|
|
134
|
+
help="how emoji in the template text are drawn (see caption.py --emoji)")
|
|
135
|
+
emo.add_argument("--emoji-assets", metavar="DIR",
|
|
136
|
+
help="directory of emoji PNGs named by code point (1f389.png); nothing is ever downloaded")
|
|
137
|
+
emo.add_argument("--emoji-scale", type=float, default=1.0,
|
|
138
|
+
help="emoji box as a multiple of the line's font size (default 1.0)")
|
|
139
|
+
emo.add_argument("--emoji-max", type=int, default=60, help="most emoji overlays one run may build (default 60)")
|
|
140
|
+
ap.set_defaults(crf=18) # --quality's default (the --crf alias was removed in 2.0)
|
|
141
|
+
ap.add_argument("--preset", default="medium", choices=X264_PRESETS, help="x264 preset")
|
|
142
|
+
add_alpha_args(ap)
|
|
143
|
+
add_common(ap)
|
|
144
|
+
args = ap.parse_args()
|
|
145
|
+
apply_common(args)
|
|
146
|
+
# A176: --from -1 divided by zero (a traceback, no JSON); --from -3 built an empty filter
|
|
147
|
+
# graph and --scale 0 or below a 0-px or negative box, both refused by ffmpeg (kind ffmpeg)
|
|
148
|
+
if args.scale <= 0:
|
|
149
|
+
die(f"--scale must be more than 0 (a size multiplier; 1 is the template's own size), got {args.scale:g}")
|
|
150
|
+
# 2.2.6: whitespace-only text is no text -- stripped before the "needs --title" checks, which
|
|
151
|
+
# used to pass on " " and burn an empty bar
|
|
152
|
+
for _attr in ("name", "title", "subtitle", "text", "top", "bottom"):
|
|
153
|
+
_v = getattr(args, _attr, None)
|
|
154
|
+
if isinstance(_v, str):
|
|
155
|
+
# one line-break form for every route: libass draws a bare CR as nothing, drawtext
|
|
156
|
+
# ignores one trailing newline, and lines_of() counts the rest -- so the layout and the
|
|
157
|
+
# drawn lines agree only if the text is normalised here, once
|
|
158
|
+
_v = _v.replace("\r\n", "\n").replace("\r", "\n").rstrip("\n")
|
|
159
|
+
setattr(args, _attr, _v if _v.strip() else None)
|
|
160
|
+
|
|
161
|
+
args.platform = resolve_platform(args.platform)
|
|
162
|
+
if args.platform and not PLATFORMS[args.platform].get("frame"):
|
|
163
|
+
info(f"--platform {args.platform}: this destination has no frame and no app chrome; margins unchanged")
|
|
164
|
+
args.platform = None
|
|
165
|
+
brand = load_brand(args.brand)
|
|
166
|
+
primary = color_hex(args.primary or brand["colors"]["primary"])
|
|
167
|
+
text_c = color_hex(args.text_color or brand["colors"]["text"])
|
|
168
|
+
bg = color_hex(brand["colors"].get("background", "101418"))
|
|
169
|
+
margin = int(brand.get("safe_margin", 48))
|
|
170
|
+
style = brand_caption_style(brand) # styles.caption is shared with caption.py
|
|
171
|
+
if args.brand and style.get("font") and not args.font:
|
|
172
|
+
args.font = style["font"]
|
|
173
|
+
if args.brand and style.get("color") and not args.text_color:
|
|
174
|
+
text_c = color_hex(style["color"])
|
|
175
|
+
args.lang = args.lang or (brand.get("lang") if args.brand else None)
|
|
176
|
+
# checked where text is drawn with it: the progress template draws a bar only (review of #532)
|
|
177
|
+
if args.template != "progress" and (args.font_file or brand.get("font_file")):
|
|
178
|
+
require_font_file(args.font_file or brand["font_file"], "--font-file" if args.font_file else "the --brand file's font_file")
|
|
179
|
+
# a font that covers the text before drawtext renders boxes instead of glyphs (1.12)
|
|
180
|
+
_script, script_file, _family = script_font_for_text(
|
|
181
|
+
" ".join(t for t in (args.name, args.title, args.subtitle, args.text, args.top, args.bottom) if t),
|
|
182
|
+
lang=args.lang, font=args.font, font_explicit=bool(args.font), font_file=args.font_file or brand.get("font_file"))
|
|
183
|
+
fo, font_used = font_opts(brand, args.font, args.font_file, script_file, _family)
|
|
184
|
+
|
|
185
|
+
meta = probe(args.input)
|
|
186
|
+
if not meta.get("video"):
|
|
187
|
+
die("input has no video stream")
|
|
188
|
+
# --keep-alpha: drawn on the source's alpha (a transparent canvas from background.py
|
|
189
|
+
# --transparent, or any alpha clip), written in an alpha line with the source's tags kept
|
|
190
|
+
alpha_codec = check_alpha_args(args, args.output)
|
|
191
|
+
src_alpha = source_alpha(args, meta, args.input)
|
|
192
|
+
audio_streams = meta.get("audio_streams") or []
|
|
193
|
+
if audio_streams and not (0 <= args.audio_stream < len(audio_streams)):
|
|
194
|
+
die(f"--audio-stream {args.audio_stream}: input has {len(audio_streams)} audio stream(s), 0..{len(audio_streams) - 1}")
|
|
195
|
+
if args.audio_stream and not audio_streams:
|
|
196
|
+
die("--audio-stream needs an input with audio streams")
|
|
197
|
+
# the displayed frame: rotation applied, non-square pixels squared (square_pixels(), #411)
|
|
198
|
+
W, H = display_size(meta["video"])
|
|
199
|
+
square = square_pixels(meta["video"])
|
|
200
|
+
if square:
|
|
201
|
+
note(square_pixels_note(meta["video"]))
|
|
202
|
+
dur = meta.get("duration") or 0.0
|
|
203
|
+
# Per-edge margins. Without --margin/--platform every edge is the brand safe margin, exactly
|
|
204
|
+
# as before; --margin sets all four; --platform takes each edge from the destination's safe
|
|
205
|
+
# zone (scripts/_platforms.py), which is what keeps a sticker off TikTok's like column.
|
|
206
|
+
m_top = m_bottom = m_left = m_right = margin
|
|
207
|
+
if args.margin is not None:
|
|
208
|
+
if args.margin < 0:
|
|
209
|
+
die(f"--margin must be >= 0, got {args.margin}")
|
|
210
|
+
m_top = m_bottom = m_left = m_right = margin = args.margin
|
|
211
|
+
elif args.platform:
|
|
212
|
+
px = safe_margins_px(args.platform, W, H)
|
|
213
|
+
m_top, m_bottom, m_left, m_right = px["top"], px["bottom"], px["left"], px["right"]
|
|
214
|
+
margin = m_left
|
|
215
|
+
info(f"--platform {args.platform}: safe margins top {m_top} / bottom {m_bottom} / left {m_left} / right {m_right} px")
|
|
216
|
+
fps = meta["video"].get("fps")
|
|
217
|
+
s = time_arg(args.start, "--start", fps) if args.start else 0.0
|
|
218
|
+
if args.end:
|
|
219
|
+
e = time_arg(args.end, "--end", fps)
|
|
220
|
+
elif meta.get("dry_run"):
|
|
221
|
+
# #466 A202: an input an earlier --dry-run stage would write is probe()'s stub, whose
|
|
222
|
+
# length is unknown, not 0 s: planning to "the clip's end" refused with "--end must be
|
|
223
|
+
# after --start". The plan ends the graphic at a stated placeholder instead
|
|
224
|
+
e = s + PENDING_PLACEHOLDER_SECONDS
|
|
225
|
+
note(f"{args.input} does not exist yet, so its length is unknown: the planned graphic ends at a placeholder "
|
|
226
|
+
f"{e:g} s; a real run ends it at the clip's end (or pass --end)")
|
|
227
|
+
else:
|
|
228
|
+
e = input_length(meta) # no --end is the clip's end (#491)
|
|
229
|
+
# the picture's own length first: sound that runs on keeps the container open past the last frame
|
|
230
|
+
picture_len = meta["video"].get("duration") or dur
|
|
231
|
+
if picture_len and s >= picture_len:
|
|
232
|
+
# A172: a graphic that starts after the picture ends draws nothing (verified: true before)
|
|
233
|
+
die(f"--start {s:g} is at or after the end of the video ({picture_len:.3f} s): nothing would be drawn",
|
|
234
|
+
hint="give a --start inside the clip")
|
|
235
|
+
if e <= s:
|
|
236
|
+
die("--end must be after --start")
|
|
237
|
+
# the window's bounds sit half a frame from the frames they select (window_expr): `{:.3f}`
|
|
238
|
+
# put the frame at 1.234567 s of a 30000/1001 picture after a --start of "1.235"
|
|
239
|
+
en = f"enable='{window_expr(s, e, meta)}'"
|
|
240
|
+
base = min(W, H) * args.scale # scale everything from the short side
|
|
241
|
+
filters: List[str] = []
|
|
242
|
+
rate = f"{meta['video'].get('fps') or 30:g}"
|
|
243
|
+
# A drawn colour lands in the BT.709 the output is tagged with. When a template's box has
|
|
244
|
+
# chroma, its boxes are colour sources made in RGB and converted (rgb_chain_to_bt709), overlaid
|
|
245
|
+
# under the text, in order: drawbox turns its colour into YUV with BT.601 on every FFmpeg (and
|
|
246
|
+
# blends 4:2:0 chroma four times over, so a translucent box was nearly opaque in colour). A
|
|
247
|
+
# template whose boxes are all grey keeps its drawboxes, which are the same under every matrix.
|
|
248
|
+
# The text (drawtext, libass) goes through drawn_chain() at the end.
|
|
249
|
+
boxes: List[tuple] = [] # (colour, alpha, drawbox geometry, x, y, w, h, enable, x_expr), in order
|
|
250
|
+
layers: List[tuple] = [] # (colour source chain, overlay position and enable), under the text
|
|
251
|
+
converted: List[str] = [] # the colour sources layer_src() converted
|
|
252
|
+
|
|
253
|
+
def fill_box(colour: str, alpha: float, drawbox_geo: str, x: int, y: int, w: int, h: int, enable: str,
|
|
254
|
+
x_expr: Optional[str] = None) -> None:
|
|
255
|
+
"""A filled box: a drawbox (`drawbox_geo`) at its place in the filter chain, or a colour layer
|
|
256
|
+
of w x h at x, y (or at the per-frame `x_expr`) -- decided for all of a template's boxes."""
|
|
257
|
+
filters.append(f"{BOX}{len(boxes)}")
|
|
258
|
+
boxes.append((colour, alpha, drawbox_geo, x, y, w, h, enable, x_expr))
|
|
259
|
+
|
|
260
|
+
def layer_at(x, y, enable: str) -> str:
|
|
261
|
+
"""An overlay's `x=...:y=...` for a layer shown inside `enable`'s window: the window is in
|
|
262
|
+
the layer's position, which is evaluated on the picture's frames, where overlay's own
|
|
263
|
+
enable is evaluated on the layer's frames too (windowed_overlay_x)."""
|
|
264
|
+
return f"x={windowed_overlay_x(str(x).strip(chr(39)), enable[len('enable='):].strip(chr(39)))}:y={y}"
|
|
265
|
+
|
|
266
|
+
def layer_src(colour: str, alpha: float, w: int, h: int, left: int = 0, top: int = 0) -> str:
|
|
267
|
+
"""A colour source to overlay (a box, the lower-third bar, the progress fill), converted when it
|
|
268
|
+
has chroma. overlay places a 4:2:0 picture on even rows and columns only: a box that starts on
|
|
269
|
+
an odd one is placed one earlier with a transparent first column/row (`left`, `top`), so it
|
|
270
|
+
covers the rows and columns the drawbox did."""
|
|
271
|
+
conv = rgb_chain_to_bt709(meta) if (alpha_codec or draws_chroma([colour], meta)) else ""
|
|
272
|
+
if conv:
|
|
273
|
+
converted.append(colour)
|
|
274
|
+
edge = f",pad={w + left}:{h + top}:{left}:{top}:color=black@0" if left or top else ""
|
|
275
|
+
return (f"color=c=0x{colour}" + (f"@{alpha:g}" if alpha < 1 else "") + f":s={w}x{h}:r={rate},format=rgba"
|
|
276
|
+
+ edge + conv)
|
|
277
|
+
# Every template fades its text in and out over 0.3 s, cut to half the window when the window
|
|
278
|
+
# is shorter than the two together (#539): with a fixed 0.3 s a window under 0.3 s never
|
|
279
|
+
# reached its fade-out and vanished part way up, and one between 0.3 and 0.6 s jumped down in
|
|
280
|
+
# brightness where the fade-out took over, on drawtext and on the ASS route (\fad) alike. The
|
|
281
|
+
# emoji PNGs ride the same envelope (emoji_overlays below), as overlay.py cuts its fade-out.
|
|
282
|
+
fade_s = min(0.3, (e - s) / 2.0)
|
|
283
|
+
fade_ms = (round(fade_s * 1000), round(fade_s * 1000))
|
|
284
|
+
# Held in 0..1 for every t: the window selects frames by their own times, half a frame either
|
|
285
|
+
# side, so a frame a hair before --start (1.234567 s for "1.235" at 30000/1001) gave a
|
|
286
|
+
# negative alpha. FFmpeg 6.1.1 draws nothing for it; FFmpeg 9.0.2 drew the window's first
|
|
287
|
+
# frame far brighter than any other in #554's CI (drawtext only, one window; the cause was not
|
|
288
|
+
# established there, and no FFmpeg 9 was run here)
|
|
289
|
+
fade_a = (f"max(0,min(1,if(lt(t,{s:.3f}+{fade_s:g}),(t-{s:.3f})/{fade_s:g},"
|
|
290
|
+
f"if(gt(t,{e:.3f}-{fade_s:g}),({e:.3f}-t)/{fade_s:g},1))))")
|
|
291
|
+
|
|
292
|
+
# --- which renderer draws the text (1.15) --------------------------------------------------
|
|
293
|
+
# drawtext does bidi and Arabic joining on a fribidi build, but it never reorders or
|
|
294
|
+
# re-clusters (no harfbuzz), so Indic matras and Thai/Lao mark stacking come out wrong on
|
|
295
|
+
# every build. Those scripts -- and any run that has to reserve a gap for an emoji PNG -- go
|
|
296
|
+
# through libass instead; everything else keeps the exact drawtext graph 1.14 produced.
|
|
297
|
+
all_text = " ".join(t for t in (args.name, args.title, args.subtitle, args.text, args.top, args.bottom) if t)
|
|
298
|
+
shaping = needs_shaping(_script)
|
|
299
|
+
emoji_assets = resolve_emoji_assets(args.emoji_assets, None, brand if args.brand else None)
|
|
300
|
+
emoji_mode = None
|
|
301
|
+
emoji_overlays: List[dict] = []
|
|
302
|
+
if has_emoji(all_text):
|
|
303
|
+
_ff = args.font_file or brand.get("font_file")
|
|
304
|
+
support = emoji_support(emoji_assets, probe=True, fonts_dir=os.path.dirname(os.path.abspath(_ff)) if _ff else None)
|
|
305
|
+
emoji_mode = support["mode"] if args.emoji == "auto" else args.emoji
|
|
306
|
+
if args.emoji == "color" and not support["libass_color"]:
|
|
307
|
+
die("--emoji color: this ffmpeg renders emoji monochrome through libass "
|
|
308
|
+
f"({support['detail']}) -- pass --emoji-assets DIR for colour, or --emoji mono", kind="input")
|
|
309
|
+
if args.emoji == "png" and not emoji_assets:
|
|
310
|
+
die("--emoji png: no emoji assets directory resolved -- " + EMOJI_ASSET_HINT, kind="input")
|
|
311
|
+
if args.emoji == "mono" and support.get("libass_glyph") is False:
|
|
312
|
+
die("--emoji mono: this ffmpeg draws no emoji glyph through libass "
|
|
313
|
+
f"({support['detail']}), so they would come out as empty boxes -- pass --emoji-assets DIR "
|
|
314
|
+
"for colour, or --emoji none", kind="input")
|
|
315
|
+
if args.text_render == "drawtext" and shaping:
|
|
316
|
+
die(f"{LANGUAGE_NAMES.get(_script, _script)} text {shaping_refusal(_script)}: drop "
|
|
317
|
+
"--text-render drawtext to render it through libass, or draw it with caption.py",
|
|
318
|
+
kind="input")
|
|
319
|
+
route = "ass" if (args.text_render == "ass" or
|
|
320
|
+
(args.text_render == "auto" and (shaping or emoji_mode == "png"))) else "drawtext"
|
|
321
|
+
if force_route:
|
|
322
|
+
route = force_route
|
|
323
|
+
# drawtext loads exactly ONE font file and has no fallback chain, so "whatever glyph the text
|
|
324
|
+
# font has" for an emoji is an empty box on DejaVu Sans and on every script font: reporting
|
|
325
|
+
# mode "mono" from the drawtext route is a claim the frame does not keep. libass DOES have a
|
|
326
|
+
# fallback chain, so an auto run routes there instead; a run that pinned --text-render
|
|
327
|
+
# drawtext degrades to "none" (strip) and says so rather than drawing tofu.
|
|
328
|
+
# "color" as much as "mono" (#403): an auto run on a build whose libass draws colour reported
|
|
329
|
+
# mode color from the drawtext route, which drew the empty box.
|
|
330
|
+
emoji_count = len(emoji_clusters(all_text))
|
|
331
|
+
emoji_names = sorted({emoji_codepoint_name(cl) for _i, cl in emoji_clusters(all_text)})
|
|
332
|
+
not_drawn = None
|
|
333
|
+
mono_in_colour = emoji_mode == "mono" and args.emoji == "mono" and bool(support.get("libass_color"))
|
|
334
|
+
if mono_in_colour:
|
|
335
|
+
emoji_mode = "color"
|
|
336
|
+
if emoji_mode in ("mono", "color") and route == "drawtext":
|
|
337
|
+
if args.text_render == "auto":
|
|
338
|
+
route = "ass"
|
|
339
|
+
else:
|
|
340
|
+
emoji_mode = "none"
|
|
341
|
+
not_drawn = "--text-render drawtext has no font fallback chain, so each would be an empty box (--text-render auto draws them through libass)"
|
|
342
|
+
elif emoji_mode == "none" and args.emoji == "auto":
|
|
343
|
+
not_drawn = ("libass draws no emoji glyph on this build (an empty box at best)"
|
|
344
|
+
if support.get("libass_glyph") is False else "no face here draws them")
|
|
345
|
+
if mono_in_colour and emoji_mode == "color":
|
|
346
|
+
# said once the route is final: a pinned drawtext route strips them instead (mode none)
|
|
347
|
+
warn(emoji_mono_on_colour_note(support), "emoji_mono_drawn_in_colour")
|
|
348
|
+
if emoji_mode == "mono":
|
|
349
|
+
warn("emoji rendered monochrome (no colour path on this ffmpeg; "
|
|
350
|
+
"--emoji-assets DIR for colour). " + support["detail"], "emoji_monochrome")
|
|
351
|
+
if emoji_mode == "none":
|
|
352
|
+
if not "".join(ch for ch in all_text if char_script(ch) != "emoji").strip():
|
|
353
|
+
die("the template's text is nothing but emoji and this machine can draw none of them "
|
|
354
|
+
"(no glyph, no --emoji-assets DIR): that frame would be blank, which is not a "
|
|
355
|
+
"delivery -- " + EMOJI_ASSET_HINT, kind="input")
|
|
356
|
+
|
|
357
|
+
def _strip_emoji(text):
|
|
358
|
+
if not text:
|
|
359
|
+
return text
|
|
360
|
+
for _i, cl in emoji_clusters(text):
|
|
361
|
+
text = text.replace(cl, "")
|
|
362
|
+
return re.sub(r"[ \t]{2,}", " ", text).strip()
|
|
363
|
+
|
|
364
|
+
for _attr in ("name", "title", "subtitle", "text", "top", "bottom"):
|
|
365
|
+
setattr(args, _attr, _strip_emoji(getattr(args, _attr, None)))
|
|
366
|
+
all_text = " ".join(t for t in (args.name, args.title, args.subtitle, args.text,
|
|
367
|
+
args.top, args.bottom) if t)
|
|
368
|
+
if not_drawn:
|
|
369
|
+
# an auto or rerouted run did not get --emoji none: it says what it left out and why,
|
|
370
|
+
# as caption.py does (emoji_not_drawn), and counts what it left out
|
|
371
|
+
warn(f"emoji: {emoji_count} left out of the drawn text: {not_drawn} -- pass --emoji-assets DIR to draw them as PNGs",
|
|
372
|
+
"emoji_not_drawn", count=emoji_count, reason=support.get("detail"))
|
|
373
|
+
else:
|
|
374
|
+
info("emoji: stripped from the drawn text (--emoji none)")
|
|
375
|
+
elements: List[dict] = []
|
|
376
|
+
|
|
377
|
+
def ass_font_family() -> "Optional[str]":
|
|
378
|
+
explicit = args.font_file or brand.get("font_file")
|
|
379
|
+
if explicit:
|
|
380
|
+
return font_family_of_file(explicit) or args.font or brand.get("font")
|
|
381
|
+
if script_file:
|
|
382
|
+
return _family or font_family_of_file(script_file) or font_family_for_script(_script)
|
|
383
|
+
return args.font or brand.get("font", "DejaVu Sans")
|
|
384
|
+
|
|
385
|
+
def ass_fonts_dir() -> "Optional[str]":
|
|
386
|
+
explicit = args.font_file or brand.get("font_file")
|
|
387
|
+
if explicit:
|
|
388
|
+
return os.path.dirname(os.path.abspath(explicit))
|
|
389
|
+
if script_file:
|
|
390
|
+
return os.path.dirname(os.path.abspath(script_file))
|
|
391
|
+
return None
|
|
392
|
+
|
|
393
|
+
def chip_frac(left, right, pad):
|
|
394
|
+
"""The fraction of the frame a boxed label may use: the span between the margins, less
|
|
395
|
+
drawtext's own box padding on each side."""
|
|
396
|
+
usable = W - left - right - 2 * pad
|
|
397
|
+
return max(0.1, min(SAFE_WIDTH_FRACTION, usable / float(W))) if W else SAFE_WIDTH_FRACTION
|
|
398
|
+
|
|
399
|
+
sliced_atoms: List[int] = []
|
|
400
|
+
|
|
401
|
+
def wrapped(text, size_px, frac=SAFE_WIDTH_FRACTION):
|
|
402
|
+
"""A label broken to the frame's safe width (1.16).
|
|
403
|
+
|
|
404
|
+
drawtext and libass both render a literal newline as a line break, and every template
|
|
405
|
+
below already passes its label through one of them -- so wrapping is a matter of putting
|
|
406
|
+
the breaks in, at the same measured width and by the same four phrase rules caption.py
|
|
407
|
+
uses. A label that already fits comes back unchanged, which is why this is additive: the
|
|
408
|
+
only text it touches is text that used to run off the edge of the frame.
|
|
409
|
+
|
|
410
|
+
`slice_overlong=True` matches caption.py's burn path (1.18.4): a single atom that is
|
|
411
|
+
still wider than the column even alone -- a long hashtag/URL/name with no break point --
|
|
412
|
+
is hard-sliced at the column's edge (preferring an existing hyphen) rather than left to
|
|
413
|
+
render past the frame. An atom that already fits is never touched, so a fitting Thai
|
|
414
|
+
phrase or katakana run comes through exactly as before.
|
|
415
|
+
"""
|
|
416
|
+
text = str(text or "")
|
|
417
|
+
if not text or not size_px:
|
|
418
|
+
return text
|
|
419
|
+
max_em = (W * frac) / float(size_px)
|
|
420
|
+
if max_em <= 0:
|
|
421
|
+
return text
|
|
422
|
+
out = []
|
|
423
|
+
for para in text.split("\n"):
|
|
424
|
+
out.extend(wrap_text(para, max_em, mode=args.wrap, lang=args.lang,
|
|
425
|
+
slice_overlong=True, sliced=sliced_atoms) if para.strip() else [para])
|
|
426
|
+
return "\n".join(out)
|
|
427
|
+
|
|
428
|
+
def lines_of(text):
|
|
429
|
+
"""How many lines drawtext and libass draw for `text` (a trailing newline is not one)."""
|
|
430
|
+
return max(1, len(str(text or "").replace("\r\n", "\n").replace("\r", "\n").rstrip("\n").split("\n")))
|
|
431
|
+
|
|
432
|
+
def block_h(text, size_px):
|
|
433
|
+
"""The height the layouts below give a label: `size_px` for the first line, as they always
|
|
434
|
+
have, and a line pitch of 1.2 x the size for each further one."""
|
|
435
|
+
return size_px + (lines_of(text) - 1) * int(size_px * 1.2)
|
|
436
|
+
|
|
437
|
+
def add_text(text, drawtext, *, target=None, **el):
|
|
438
|
+
"""One line of template text: a drawtext filter on the old route, an ASS element on the
|
|
439
|
+
new one. The geometry is computed identically either way."""
|
|
440
|
+
if route != "ass":
|
|
441
|
+
(filters if target is None else target).append(drawtext)
|
|
442
|
+
return
|
|
443
|
+
el["text"] = text
|
|
444
|
+
elements.append(el)
|
|
445
|
+
|
|
446
|
+
fc: List[str] = [] # filter_complex chains (used by templates that need animated boxes)
|
|
447
|
+
if 0 < min(W, H) < 64: # 0x0 is a dry-run probe of an intermediate that does not exist yet
|
|
448
|
+
die(f"the frame is {W}x{H}; the templates are sized from it and need at least 64 px on the short side")
|
|
449
|
+
if args.template == "lower-third":
|
|
450
|
+
if not args.name:
|
|
451
|
+
die("lower-third needs --name")
|
|
452
|
+
h1 = int(base * 0.055)
|
|
453
|
+
h2 = int(base * 0.038)
|
|
454
|
+
pad = int(base * 0.02)
|
|
455
|
+
tx_pad = int(base * 0.035)
|
|
456
|
+
# both lines wrap to the room between the side margins, less the text's own inset, and
|
|
457
|
+
# the bar widens (up to that room) to the widest line: through 3.1.3 the bar was a fixed
|
|
458
|
+
# 62 % of the short side and a long name ran past it and off the frame (#411)
|
|
459
|
+
room = W - m_left - m_right
|
|
460
|
+
lt_frac = max(0.1, min(1.0, (room - 2 * tx_pad) / float(W))) if W else SAFE_WIDTH_FRACTION
|
|
461
|
+
lt_name = wrapped(args.name, h1, lt_frac)
|
|
462
|
+
lt_title = wrapped(args.title, h2, lt_frac) if args.title else args.title
|
|
463
|
+
widest = max([text_width_em(ln) * h1 for ln in lt_name.split("\n")]
|
|
464
|
+
+ [text_width_em(ln) * h2 for ln in (lt_title or "").split("\n")])
|
|
465
|
+
name_h = block_h(lt_name, h1)
|
|
466
|
+
bar_h = name_h + (block_h(lt_title, h2) + pad if lt_title else 0) + pad * 2
|
|
467
|
+
# the 62 % floor never takes the bar past the right margin (#416 review: at a large --scale
|
|
468
|
+
# it did)
|
|
469
|
+
bar_w = max(1, min(room, max(int(base * 0.62), int(widest + 0.999) + 2 * tx_pad)))
|
|
470
|
+
y0 = H - m_bottom - bar_h
|
|
471
|
+
# slide in from the left over 0.4 s, slide out over 0.3 s (overlay evaluates x per frame);
|
|
472
|
+
# a window shorter than the two together shares itself between them 4:3, so the bar still
|
|
473
|
+
# ends off the frame and does not jump where the slide-out takes over (#539)
|
|
474
|
+
in_s, out_s = min(0.4, (e - s) * 4 / 7), min(0.3, (e - s) * 3 / 7)
|
|
475
|
+
if in_s + out_s >= e - s:
|
|
476
|
+
# the two meet at one instant, which the ASS route writes in centiseconds: put it on
|
|
477
|
+
# one for both routes, or the text's slide-out started up to 5 ms before the bar's
|
|
478
|
+
# and sat ahead of it for the whole exit (11 px at 640 px wide, 60 fps; #554 review)
|
|
479
|
+
meet = round((s + in_s) * 100) / 100
|
|
480
|
+
if s < meet < e:
|
|
481
|
+
in_s, out_s = meet - s, e - meet
|
|
482
|
+
x_expr = (f"if(lt(t,{s:.3f}+{in_s:g}),-{bar_w}+({bar_w}+{m_left})*((t-{s:.3f})/{in_s:g}),"
|
|
483
|
+
f"if(gt(t,{e:.3f}-{out_s:g}),{m_left}-({bar_w}+{m_left})*(1-({e:.3f}-t)/{out_s:g}),{m_left}))")
|
|
484
|
+
fc.append(f"{layer_src(bg, 0.85, bar_w, bar_h)}[bar]")
|
|
485
|
+
fc.append(f"{layer_src(primary, 1.0, int(base * 0.012), bar_h)}[acc]")
|
|
486
|
+
fc.append(f"[0:v][bar]overlay={layer_at(x_expr, y0, en)}:eof_action=pass[v1]")
|
|
487
|
+
fc.append(f"[v1][acc]overlay={layer_at(x_expr, y0, en)}:eof_action=pass[v2]")
|
|
488
|
+
tx = f"({x_expr})+{tx_pad}"
|
|
489
|
+
x_rest, x_off = m_left + tx_pad, -bar_w + tx_pad
|
|
490
|
+
draws = []
|
|
491
|
+
for text, fs, colour, ty in ((lt_name, h1, text_c, y0 + pad),
|
|
492
|
+
(lt_title, h2, primary, y0 + pad + name_h + pad // 2)):
|
|
493
|
+
if not text:
|
|
494
|
+
continue
|
|
495
|
+
draws.append(f"drawtext={drawtext_text_opts(text)}:{fo}:fontsize={fs}:"
|
|
496
|
+
f"fontcolor={ff_color(colour)}:x='{tx}':y={ty}:{en}")
|
|
497
|
+
if route == "ass":
|
|
498
|
+
# the same three phases the bar itself slides through, as \move Dialogues
|
|
499
|
+
elements.append(dict(text=text, size=fs, color=colour, font=ass_font_family(),
|
|
500
|
+
align=7, x=x_rest, y=ty, outline=max(1.0, fs / 16.0),
|
|
501
|
+
outline_color="000000", start=s, end=s + in_s,
|
|
502
|
+
move=(x_off, ty, x_rest, ty, 0, round(in_s * 1000)), x_expr=tx))
|
|
503
|
+
if e - out_s > s + in_s:
|
|
504
|
+
# no rest phase in a window the two slides fill: a line of no length drew
|
|
505
|
+
# nothing, but its emoji PNG, which has no fade, showed for the one frame at
|
|
506
|
+
# that instant between the other two phases' faded ones (#554 review)
|
|
507
|
+
elements.append(dict(text=text, size=fs, color=colour, font=ass_font_family(),
|
|
508
|
+
align=7, x=x_rest, y=ty, outline=max(1.0, fs / 16.0),
|
|
509
|
+
outline_color="000000", start=s + in_s, end=e - out_s,
|
|
510
|
+
x_expr=tx))
|
|
511
|
+
elements.append(dict(text=text, size=fs, color=colour, font=ass_font_family(),
|
|
512
|
+
align=7, x=x_rest, y=ty, outline=max(1.0, fs / 16.0),
|
|
513
|
+
outline_color="000000", start=e - out_s, end=e,
|
|
514
|
+
move=(x_rest, ty, x_off, ty, 0, round(out_s * 1000)), x_expr=tx))
|
|
515
|
+
fc.append(f"[v2]{TEXT}[vout]" if route != "ass" else "[v2]null[vout]")
|
|
516
|
+
if route != "ass":
|
|
517
|
+
filters.extend(draws) # the text chain, which drawn_chain() places at TEXT
|
|
518
|
+
|
|
519
|
+
elif args.template == "title":
|
|
520
|
+
if not args.title:
|
|
521
|
+
die("title needs --title")
|
|
522
|
+
h1 = int(base * 0.11)
|
|
523
|
+
h2 = int(base * 0.045)
|
|
524
|
+
# the title and the subtitle wrap to the frame's safe width (#411: they never did)
|
|
525
|
+
title_t = wrapped(args.title, h1)
|
|
526
|
+
sub_t = wrapped(args.subtitle, h2) if args.subtitle else args.subtitle
|
|
527
|
+
fill_box(bg, 0.55, "x=0:y=0:w=iw:h=ih", 0, 0, W, H, en)
|
|
528
|
+
# the title is centred as a block, so the bar and the subtitle sit below its last line:
|
|
529
|
+
# `title_h` is the block's height, as the one-line layout has always taken h1; a further
|
|
530
|
+
# subtitle line hangs below the first, whose position the one-line layout fixes
|
|
531
|
+
title_h = block_h(title_t, h1)
|
|
532
|
+
sub_y = title_h // 2 + int(base * 0.03)
|
|
533
|
+
sub_extra = block_h(sub_t, h2) - h2 if sub_t else 0
|
|
534
|
+
tall = title_h + (sub_y - title_h // 2 + block_h(sub_t, h2) if sub_t else 0)
|
|
535
|
+
if tall > H:
|
|
536
|
+
# the wrap measures width only; a centred block taller than the frame loses its first
|
|
537
|
+
# and last lines off the edges (#416 review)
|
|
538
|
+
note(f"the wrapped title{' and subtitle' if sub_t else ''} are about {tall} px tall, taller than the "
|
|
539
|
+
f"{H} px frame: the lines past its edges are not drawn -- shorten the text or lower --scale")
|
|
540
|
+
add_text(title_t,
|
|
541
|
+
f"drawtext={drawtext_text_opts(title_t)}:{fo}:fontsize={h1}:fontcolor={ff_color(text_c)}{drawtext_center_align()}:x=(w-text_w)/2:y=(h-text_h)/2-{h2 if sub_t else 0}:alpha='{fade_a}':{en}",
|
|
542
|
+
size=h1, color=text_c, font=ass_font_family(), align=5, x=W / 2,
|
|
543
|
+
y=H / 2 - (h2 if sub_t else 0), outline=max(1.0, h1 / 20.0),
|
|
544
|
+
outline_color="000000", start=s, end=e, fade=fade_ms)
|
|
545
|
+
acc_w, acc_h = int(base * 0.12), max(2, int(base * 0.006))
|
|
546
|
+
fill_box(primary, 1.0, f"x=(iw-{acc_w})/2:y=(ih)/2+{title_h // 2}:w={acc_w}:h={acc_h}",
|
|
547
|
+
(W - acc_w) // 2, H // 2 + title_h // 2, acc_w, acc_h, en)
|
|
548
|
+
if sub_t:
|
|
549
|
+
add_text(sub_t,
|
|
550
|
+
f"drawtext={drawtext_text_opts(sub_t)}:{fo}:fontsize={h2}:fontcolor={ff_color(primary)}{drawtext_center_align()}:x=(w-text_w)/2:y=(h-text_h)/2+{sub_y + sub_extra // 2}:alpha='{fade_a}':{en}",
|
|
551
|
+
size=h2, color=primary, font=ass_font_family(), align=5, x=W / 2,
|
|
552
|
+
y=H / 2 + sub_y + sub_extra // 2, outline=max(1.0, h2 / 20.0),
|
|
553
|
+
outline_color="000000", start=s, end=e, fade=fade_ms)
|
|
554
|
+
|
|
555
|
+
elif args.template in ("chapter", "bug"):
|
|
556
|
+
if not args.title:
|
|
557
|
+
die(f"{args.template} needs --title")
|
|
558
|
+
pos = args.position or ("bottom-left" if args.template == "chapter" else "top-right")
|
|
559
|
+
fs = int(base * (0.04 if args.template == "chapter" else 0.032))
|
|
560
|
+
padx, pady = int(fs * 0.6), int(fs * 0.35)
|
|
561
|
+
# the chip wraps to the room between the side margins, as the sticker's does (#411)
|
|
562
|
+
chip_t = wrapped(args.title, fs, chip_frac(m_left, m_right, padx))
|
|
563
|
+
xe = f"{m_left}" if "left" in pos else f"w-text_w-{m_right}"
|
|
564
|
+
ye = f"{m_top}" if "top" in pos else f"h-text_h-{m_bottom}"
|
|
565
|
+
box_color = ff_color(primary if args.template == "chapter" else bg, 0.9 if args.template == "chapter" else 0.7)
|
|
566
|
+
txt_color = ff_color(bg if args.template == "chapter" else text_c)
|
|
567
|
+
box_hex = primary if args.template == "chapter" else bg
|
|
568
|
+
txt_hex = bg if args.template == "chapter" else text_c
|
|
569
|
+
align = (7 if "left" in pos else 9) if "top" in pos else (1 if "left" in pos else 3)
|
|
570
|
+
add_text(chip_t,
|
|
571
|
+
f"drawtext={drawtext_text_opts(chip_t)}:{fo}:fontsize={fs}:fontcolor={txt_color}:x={xe}:y={ye}:box=1:boxcolor={box_color}:boxborderw={drawtext_boxborderw(pady, padx)}:alpha='{fade_a}':{en}",
|
|
572
|
+
size=fs, color=txt_hex, font=ass_font_family(), align=align,
|
|
573
|
+
x=(m_left if "left" in pos else W - m_right),
|
|
574
|
+
y=(m_top if "top" in pos else H - m_bottom),
|
|
575
|
+
box=True, box_color=box_hex, box_alpha=(0x19 if args.template == "chapter" else 0x4C),
|
|
576
|
+
outline=float(pady), outline_color=box_hex, start=s, end=e, fade=fade_ms)
|
|
577
|
+
|
|
578
|
+
elif args.template == "progress":
|
|
579
|
+
h = max(3, int(base * 0.008))
|
|
580
|
+
fps = meta['video'].get('fps') or 30
|
|
581
|
+
fc.append(f"{layer_src(primary, 1.0, W, h)}[pb]")
|
|
582
|
+
if draws_chroma([bg], meta) or alpha_codec or overlay_format(meta):
|
|
583
|
+
# a layer (overlay composites the alpha too; drawbox leaves it as it was, and takes a
|
|
584
|
+
# 10-bit picture to 8 bits)
|
|
585
|
+
fc.append(f"{layer_src(bg, 0.5, W, h, 0, (H - h) % 2)}[pbg]")
|
|
586
|
+
fc.append(f"[0:v][pbg]overlay={layer_at(0, (H - h) // 2 * 2, en)}:eof_action=pass[v1]")
|
|
587
|
+
else:
|
|
588
|
+
fc.append(f"[0:v]drawbox=x=0:y=ih-{h}:w=iw:h={h}:color={ff_color(bg, 0.5)}:t=fill:{en}[v1]")
|
|
589
|
+
fc.append(f"[v1][pb]overlay={layer_at(f'-w+w*min(1,max(0,(t-{s:.3f})/{e - s:.3f}))', H - h, en)}:eof_action=pass[vout]")
|
|
590
|
+
|
|
591
|
+
elif args.template == "sticker":
|
|
592
|
+
# A social sticker: a filled chip of text that pops in. drawtext's box gives the chip
|
|
593
|
+
# (its corners are square -- drawtext has no rounded box), and the pop is the two things
|
|
594
|
+
# drawtext *can* animate per frame: alpha and position, so the chip fades up while
|
|
595
|
+
# rising the last few pixels into place over 0.25 s.
|
|
596
|
+
if not args.text:
|
|
597
|
+
die("sticker needs --text")
|
|
598
|
+
pos = args.position or "top-right"
|
|
599
|
+
fs = int(base * 0.05)
|
|
600
|
+
padx, pady = int(fs * 0.7), int(fs * 0.45)
|
|
601
|
+
rise = int(fs * 0.5)
|
|
602
|
+
# the pop is cut to the fade's length in a short window, on both routes: drawtext kept
|
|
603
|
+
# its 0.25 s while the ASS \fad was cut, so the chip reached half the brightness there
|
|
604
|
+
# (#554 review)
|
|
605
|
+
pop_s = min(0.25, fade_s)
|
|
606
|
+
pop = f"max(0,min(1,(t-{s:.3f})/{pop_s:g}))" # held in 0..1, as fade_a is, for a frame selected before --start
|
|
607
|
+
xe = f"{m_left}" if "left" in pos else f"w-text_w-{m_right}"
|
|
608
|
+
# every position rises into place, on both routes: a bottom chip started `rise` px above
|
|
609
|
+
# its rest on drawtext and dropped, where the ASS \move below rises (A177)
|
|
610
|
+
ye = (f"{m_top}+{rise}*(1-{pop})" if "top" in pos else f"h-text_h-{m_bottom}+{rise}*(1-{pop})")
|
|
611
|
+
alpha = f"min({pop},{fade_a})"
|
|
612
|
+
align = (7 if "left" in pos else 9) if "top" in pos else (1 if "left" in pos else 3)
|
|
613
|
+
y_rest = m_top if "top" in pos else H - m_bottom
|
|
614
|
+
y_start = y_rest + rise if "top" in pos else y_rest + rise
|
|
615
|
+
# the chip is a box between the two side margins, not the whole frame: wrapping to the
|
|
616
|
+
# frame width let a long --text run off the plate even though it "fitted"
|
|
617
|
+
sticker_text = wrapped(args.text, fs, chip_frac(m_left, m_right, padx))
|
|
618
|
+
add_text(sticker_text,
|
|
619
|
+
f"drawtext={drawtext_text_opts(sticker_text)}:{fo}:fontsize={fs}:fontcolor={ff_color(bg)}:"
|
|
620
|
+
f"x={xe}:y='{ye}':box=1:boxcolor={ff_color(primary, 0.95)}:boxborderw={drawtext_boxborderw(pady, padx)}:"
|
|
621
|
+
f"alpha='{alpha}':{en}",
|
|
622
|
+
size=fs, color=bg, font=ass_font_family(), align=align,
|
|
623
|
+
x=(m_left if "left" in pos else W - m_right), y=y_rest,
|
|
624
|
+
box=True, box_color=primary, box_alpha=0x0D, outline=float(pady),
|
|
625
|
+
outline_color=primary, start=s, end=e, fade=(round(pop_s * 1000), min(250, fade_ms[1])),
|
|
626
|
+
move=(m_left if "left" in pos else W - m_right, y_start,
|
|
627
|
+
m_left if "left" in pos else W - m_right, y_rest, 0, round(pop_s * 1000)))
|
|
628
|
+
|
|
629
|
+
elif args.template == "hook":
|
|
630
|
+
# The opener: a full-width card over the first --duration seconds with a thin bar along
|
|
631
|
+
# the top that empties as the card's time runs out, so the viewer sees how long it lasts.
|
|
632
|
+
if not args.title:
|
|
633
|
+
die("hook needs --title")
|
|
634
|
+
if args.duration <= 0:
|
|
635
|
+
die(f"--duration must be > 0, got {args.duration:g}")
|
|
636
|
+
he = min(e, s + args.duration)
|
|
637
|
+
hen = f"enable='{window_expr(s, he, meta)}'"
|
|
638
|
+
h1 = int(base * 0.085)
|
|
639
|
+
bar_h = max(3, int(base * 0.01))
|
|
640
|
+
hook_title = wrapped(args.title, h1)
|
|
641
|
+
# the base band (30% of the short side) holds two lines; a longer wrapped title (a 9:16
|
|
642
|
+
# hook is four or five) grows the band to the text plus 0.7 of a line of margin, instead of
|
|
643
|
+
# drawing white text on the bare video. The band is clipped at the frame edges.
|
|
644
|
+
band_h = min(H, max(int(base * 0.30), block_h(hook_title, h1) + int(h1 * 0.7)))
|
|
645
|
+
y0 = (H - band_h) // 2
|
|
646
|
+
fill_box(bg, 0.78, f"x=0:y={y0}:w=iw:h={band_h}", 0, y0, W, band_h, hen)
|
|
647
|
+
add_text(hook_title,
|
|
648
|
+
f"drawtext={drawtext_text_opts(hook_title)}:{fo}:fontsize={h1}:fontcolor={ff_color(text_c)}"
|
|
649
|
+
f"{drawtext_center_align()}:x=(w-text_w)/2:y=(h-text_h)/2:{hen}",
|
|
650
|
+
size=h1, color=text_c, font=ass_font_family(), align=5, x=W / 2, y=H / 2,
|
|
651
|
+
outline=max(1.0, h1 / 20.0), outline_color="000000", start=s, end=he)
|
|
652
|
+
# the bar empties from the right: the overlay slides a full-width bar out to the left
|
|
653
|
+
fill_box(primary, 1.0, f"x=0:y=0:w='iw*max(0,1-(t-{s:.3f})/{max(0.001, he - s):.3f})':h={bar_h}", 0, 0, W, bar_h,
|
|
654
|
+
hen, x_expr=f"'-W*min(1,max(0,(t-{s:.3f})/{max(0.001, he - s):.3f}))'")
|
|
655
|
+
|
|
656
|
+
elif args.template == "meme":
|
|
657
|
+
# The classic layout: heavy white upper-case lines with a black outline, top and bottom,
|
|
658
|
+
# sized so a short line fills the frame's width; a longer one is broken by the same
|
|
659
|
+
# phrase-aware wrap caption.py uses (1.16 -- drawtext itself still never wraps).
|
|
660
|
+
if not (args.top or args.bottom):
|
|
661
|
+
die("meme needs --top and/or --bottom")
|
|
662
|
+
fs = int(base * 0.09)
|
|
663
|
+
bw = max(2, int(fs / 12))
|
|
664
|
+
white, black = ff_color("FFFFFF"), ff_color("000000")
|
|
665
|
+
for text, y in ((args.top, f"{m_top}"), (args.bottom, f"h-text_h-{m_bottom}")):
|
|
666
|
+
if not text:
|
|
667
|
+
continue
|
|
668
|
+
meme_line = wrapped(text.upper(), fs)
|
|
669
|
+
add_text(meme_line,
|
|
670
|
+
f"drawtext={drawtext_text_opts(meme_line)}:{fo}:fontsize={fs}:fontcolor={white}:"
|
|
671
|
+
f"borderw={bw}:bordercolor={black}{drawtext_center_align()}:x=(w-text_w)/2:y={y}:{en}",
|
|
672
|
+
size=fs, color="FFFFFF", font=ass_font_family(), bold=True,
|
|
673
|
+
align=(8 if y == f"{m_top}" else 2), x=W / 2,
|
|
674
|
+
y=(m_top if y == f"{m_top}" else H - m_bottom),
|
|
675
|
+
outline=float(bw), outline_color="000000", start=s, end=e)
|
|
676
|
+
|
|
677
|
+
elif args.template == "countdown":
|
|
678
|
+
n = args.count_from
|
|
679
|
+
seg = (e - s) / (n + 1)
|
|
680
|
+
fs = int(base * 0.32)
|
|
681
|
+
for k in range(n, -1, -1):
|
|
682
|
+
ks = s + (n - k) * seg
|
|
683
|
+
ke = ks + seg
|
|
684
|
+
pulse = f"1-0.15*min(1,(t-{ks:.3f})/{seg * 0.5:.3f})"
|
|
685
|
+
add_text(str(k),
|
|
686
|
+
f"drawtext=text='{k}':{fo}:fontsize={fs}:fontcolor={ff_color(primary)}:borderw={max(2, fs // 40)}:bordercolor={ff_color(bg)}:x=(w-text_w)/2:y=(h-text_h)/2:alpha='{pulse}':enable='{window_expr(ks, ke, meta, half_open=k > 0)}'",
|
|
687
|
+
size=fs, color=primary, font=ass_font_family(), align=5, x=W / 2, y=H / 2,
|
|
688
|
+
outline=float(max(2, fs // 40)), outline_color=bg, start=ks, end=ke,
|
|
689
|
+
scale_t=(0, seg * 500, 115))
|
|
690
|
+
|
|
691
|
+
# FFmpeg 8.0, 8.0.1 and 8.1 draw the font's missing-glyph box at the end of every line but the
|
|
692
|
+
# last of a multi-line drawtext (and widen text_w by it). Every template lays out the same
|
|
693
|
+
# elements for libass, so an auto run whose labels came out multi-line -- given that way or
|
|
694
|
+
# wrapped to the frame above -- is laid out again on that route; a pinned drawtext run says so.
|
|
695
|
+
if route == "drawtext" and drawtext_draws_newline_glyph() and any(is_multiline(t) for t in _DRAWTEXT_PENDING.values()):
|
|
696
|
+
if args.text_render == "auto" and not force_route:
|
|
697
|
+
info("multi-line text: this ffmpeg's drawtext draws a box at each line break "
|
|
698
|
+
"(FFmpeg 8.0-8.0.1 and 8.1.0; fixed in 8.0.2/8.1.1), so it is rendered through libass")
|
|
699
|
+
_DRAWTEXT_PENDING.clear()
|
|
700
|
+
return main(force_route="ass")
|
|
701
|
+
warn("this ffmpeg's drawtext draws a box at each line break of a multi-line label "
|
|
702
|
+
"(FFmpeg 8.0-8.0.1 and 8.1.0; fixed in 8.0.2/8.1.1): drop --text-render drawtext to render it "
|
|
703
|
+
"through libass, or upgrade FFmpeg", "drawtext_newline_glyph", text_render="drawtext")
|
|
704
|
+
|
|
705
|
+
output = args.output or default_output(args.input, "gfx", default_ext(alpha_codec) if alpha_codec else None)
|
|
706
|
+
# the brand file and the font file are read here and by drawtext's fontfile=, never as an -i, so
|
|
707
|
+
# run()'s guard did not see them (#522's sweep)
|
|
708
|
+
refuse_output_is_input(output, *[q for q in (args.brand, args.font_file or brand.get("font_file")) if isinstance(q, str) and q])
|
|
709
|
+
ass_path = None
|
|
710
|
+
emoji_result = None
|
|
711
|
+
if route == "ass":
|
|
712
|
+
scale_em = float(args.emoji_scale or 1.0)
|
|
713
|
+
missing: List[str] = []
|
|
714
|
+
seen: List[str] = []
|
|
715
|
+
for el in elements:
|
|
716
|
+
el["box_px"] = int(round(el["size"] * scale_em))
|
|
717
|
+
if not emoji_clusters(el["text"]) or emoji_mode not in ("png",):
|
|
718
|
+
continue
|
|
719
|
+
# a wrapped label is several lines: each is measured from its own start and sits one
|
|
720
|
+
# line pitch below the last (#416 review: they were measured as one line, on the first)
|
|
721
|
+
all_lines = el["text"].split("\n")
|
|
722
|
+
align = int(el.get("align", 7))
|
|
723
|
+
line_h = el["size"] * 1.2
|
|
724
|
+
block = len(all_lines) * line_h
|
|
725
|
+
block_top = el["y"] if align in (7, 8, 9) else (
|
|
726
|
+
el["y"] - block / 2.0 if align in (4, 5, 6) else el["y"] - block)
|
|
727
|
+
rebuilt_lines = []
|
|
728
|
+
for k, line in enumerate(all_lines):
|
|
729
|
+
clusters = emoji_clusters(line)
|
|
730
|
+
if not clusters:
|
|
731
|
+
rebuilt_lines.append(line)
|
|
732
|
+
continue
|
|
733
|
+
line_w = text_width_em(line, scale_em) * el["size"]
|
|
734
|
+
left = el["x"] if align in (7, 4, 1) else (
|
|
735
|
+
el["x"] - line_w / 2.0 if align in (8, 5, 2) else el["x"] - line_w)
|
|
736
|
+
y_top = block_top + k * line_h
|
|
737
|
+
# An RTL line is rendered right-to-left: measure the suffix, not the logical prefix.
|
|
738
|
+
rtl = detect_script(line) in BIDI_SCRIPTS
|
|
739
|
+
rebuilt, cursor = "", 0
|
|
740
|
+
for idx, cluster in clusters:
|
|
741
|
+
name = emoji_codepoint_name(cluster)
|
|
742
|
+
if name not in seen:
|
|
743
|
+
seen.append(name)
|
|
744
|
+
asset = emoji_asset_for(cluster, emoji_assets)
|
|
745
|
+
if not asset:
|
|
746
|
+
if name not in missing:
|
|
747
|
+
missing.append(name)
|
|
748
|
+
rebuilt += line[cursor:idx + len(cluster)]
|
|
749
|
+
cursor = idx + len(cluster)
|
|
750
|
+
continue
|
|
751
|
+
if rtl:
|
|
752
|
+
prefix_px = line_w - text_width_em(line[:idx] + cluster, scale_em) * el["size"]
|
|
753
|
+
else:
|
|
754
|
+
prefix_px = text_width_em(line[:idx], scale_em) * el["size"]
|
|
755
|
+
if el.get("x_expr"):
|
|
756
|
+
# the lower-third slides: the emoji rides the same expression the bar does
|
|
757
|
+
x = f"({el['x_expr']})+{prefix_px:.0f}"
|
|
758
|
+
else:
|
|
759
|
+
x = int(round(max(0.0, min(left + prefix_px, W - el["box_px"]))))
|
|
760
|
+
emoji_overlays.append({"asset": asset, "cluster": name, "x": x,
|
|
761
|
+
"y": int(round(max(0.0, min(y_top + (line_h - el["box_px"]) / 2.0,
|
|
762
|
+
H - el["box_px"])))),
|
|
763
|
+
"start": round(el["start"], 3), "end": round(el["end"], 3),
|
|
764
|
+
"box": el["box_px"],
|
|
765
|
+
# every template fades its text in and out over 0.3 s
|
|
766
|
+
# (fade_a above); the PNG rides the same envelope.
|
|
767
|
+
"fade_in": round(min(0.3, max(0.0, (el["end"] - el["start"]) / 2.0)), 3),
|
|
768
|
+
"fade_out": round(min(0.3, max(0.0, (el["end"] - el["start"]) / 2.0)), 3)})
|
|
769
|
+
rebuilt += line[cursor:idx] + EMOJI_SENTINEL
|
|
770
|
+
cursor = idx + len(cluster)
|
|
771
|
+
rebuilt_lines.append(rebuilt + line[cursor:])
|
|
772
|
+
el["text"] = "\n".join(rebuilt_lines)
|
|
773
|
+
# `or 60` would swallow --emoji-max 0, the one value meaning "none at all".
|
|
774
|
+
_max = 60 if args.emoji_max is None else int(args.emoji_max)
|
|
775
|
+
if len(emoji_overlays) > _max:
|
|
776
|
+
die(f"{len(emoji_overlays)} emoji overlays would be built for this job "
|
|
777
|
+
f"(limit {_max}, --emoji-max raises it); ffmpeg's filter graph and the "
|
|
778
|
+
"per-frame cost both grow linearly -- split the job, or use --emoji none", kind="input")
|
|
779
|
+
if missing:
|
|
780
|
+
warn(emoji_missing_asset_note(list(missing), support), "emoji_assets_missing", missing=list(missing))
|
|
781
|
+
if emoji_mode:
|
|
782
|
+
emoji_result = {"mode": emoji_mode, "count": emoji_count,
|
|
783
|
+
"clusters": sorted(seen) or emoji_names,
|
|
784
|
+
"assets": emoji_assets, "missing": missing,
|
|
785
|
+
"overlays": len(emoji_overlays)}
|
|
786
|
+
ass_path = args.write_ass or os.path.splitext(output)[0] + "_gfx.ass"
|
|
787
|
+
require_filter("ass", "drawing this text through libass") # before the sidecar is written
|
|
788
|
+
# a file this run writes itself: never the input or the video, a missing directory or an
|
|
789
|
+
# existing file without --overwrite is refused before anything is written (#408)
|
|
790
|
+
# the font the text is drawn with, a brand file's font_file included (review of #534: only
|
|
791
|
+
# --font-file was here, and --write-ass naming the brand's font replaced it with ASS text)
|
|
792
|
+
guard_sidecar(ass_path, *[q for q in (args.input, getattr(args, "brand", None), args.font_file or brand.get("font_file"))
|
|
793
|
+
if isinstance(q, str) and q], siblings=(output,))
|
|
794
|
+
if STATE.dry_run:
|
|
795
|
+
info(f"[dry-run] would write {ass_path} ({len(elements)} text elements)")
|
|
796
|
+
else:
|
|
797
|
+
text_overlay_ass(elements, play_w=W, play_h=H, path=ass_path, fonts_dir=ass_fonts_dir())
|
|
798
|
+
info(f"wrote {ass_path} ({len(elements)} text elements, rendered through libass)")
|
|
799
|
+
elif emoji_mode:
|
|
800
|
+
emoji_result = {"mode": emoji_mode, "count": emoji_count,
|
|
801
|
+
"clusters": emoji_names,
|
|
802
|
+
"assets": emoji_assets, "missing": [], "overlays": 0}
|
|
803
|
+
|
|
804
|
+
# The boxes with chroma (layers) go under the text, and the picture they and a converted colour
|
|
805
|
+
# source are overlaid on gets its BT.709 label (an untagged one, tags only), so 7.1+'s overlay
|
|
806
|
+
# converts neither picture to the other's matrix. The text is drawn in BT.709 (drawn_chain).
|
|
807
|
+
# On an alpha line every box is a layer: overlay composites the box's alpha over the picture's,
|
|
808
|
+
# while drawbox paints the colour and leaves the alpha as it was (a box on a transparent canvas
|
|
809
|
+
# stayed invisible). On a 10-bit picture too: drawbox is 8-bit only on 6.1, so FFmpeg took the
|
|
810
|
+
# whole picture to 8 bits around it (overlay_format)
|
|
811
|
+
as_layers = bool(alpha_codec) or bool(overlay_format(meta)) or any(draws_chroma([b[0]], meta) for b in boxes)
|
|
812
|
+
drawboxes = []
|
|
813
|
+
for colour, alpha, geo, x, y, w, h, enable, x_expr in boxes:
|
|
814
|
+
if as_layers:
|
|
815
|
+
layers.append((layer_src(colour, alpha, w, h, x % 2, y % 2), layer_at(x_expr or x - x % 2, y - y % 2, enable)))
|
|
816
|
+
drawboxes.append(f"drawbox={geo}:color={ff_color(colour, alpha)}:t=fill:{enable}")
|
|
817
|
+
filters = [("" if as_layers else drawboxes[int(f[len(BOX):])]) if f.startswith(BOX) else f for f in filters]
|
|
818
|
+
filters = [f for f in filters if f]
|
|
819
|
+
base_label = layer_base_chain(meta) if (layers or converted) else ""
|
|
820
|
+
text = (drawn_chain(",".join(filters), meta, re.findall(r"color=([0-9A-Za-z#@.]+)", ",".join(filters)),
|
|
821
|
+
labelled=bool(base_label)) if filters else "")
|
|
822
|
+
if layers:
|
|
823
|
+
cur = "0:v"
|
|
824
|
+
for k, (src, pos) in enumerate(layers):
|
|
825
|
+
fc.append(f"{src}[gl{k}]")
|
|
826
|
+
fc.append(f"[{cur}][gl{k}]overlay={pos}:eof_action=pass[gv{k}]")
|
|
827
|
+
cur = f"gv{k}"
|
|
828
|
+
fc.append(f"[{cur}]{TEXT}[vout]")
|
|
829
|
+
fc = [c.replace(TEXT, text or "null") for c in fc]
|
|
830
|
+
if fc and base_label:
|
|
831
|
+
fc = [f"[0:v]{base_label}null[gbase]"] + [c.replace("[0:v]", "[gbase]") for c in fc]
|
|
832
|
+
if fc and square:
|
|
833
|
+
fc = [f"[0:v]{square}[gsq]"] + [c.replace("[0:v]", "[gsq]") for c in fc]
|
|
834
|
+
if alpha_codec:
|
|
835
|
+
# the picture is drawn on at 4:4:4 with its alpha plane, and every layer is overlaid at
|
|
836
|
+
# 4:4:4 (overlay's default is 4:2:0); drawtext and libass (alpha=1) draw into the alpha too
|
|
837
|
+
fc = [c.replace(":eof_action=pass", ":eof_action=pass:format=yuv444") for c in fc]
|
|
838
|
+
if fc:
|
|
839
|
+
fc = [f"[0:v]{source_format(meta)}[ka0]"] + [c.replace("[0:v]", "[ka0]") for c in fc]
|
|
840
|
+
square = source_format(meta) + ("," + square if square else "")
|
|
841
|
+
elif overlay_format(meta):
|
|
842
|
+
# a 10-bit picture on a 10-bit line is composited at 10 bits (overlay's default is 8-bit)
|
|
843
|
+
fc = [c.replace(":eof_action=pass", ":eof_action=pass" + overlay_format(meta)) for c in fc]
|
|
844
|
+
finish = finish_chain(alpha_codec, args.alpha_mode, meta) if alpha_codec else ""
|
|
845
|
+
|
|
846
|
+
cmd = ffmpeg_base() + (decoder_args_for(meta, args.input) if alpha_codec else []) + ["-i", args.input]
|
|
847
|
+
if route == "ass" or emoji_overlays:
|
|
848
|
+
chains = list(fc) if fc else [f"[0:v]{(square + ',') if square else ''}{text or 'null'}[vout]"]
|
|
849
|
+
last = "vout"
|
|
850
|
+
if route == "ass":
|
|
851
|
+
vf = f"ass=filename={escape_filter_path(ass_path)}"
|
|
852
|
+
fdir = ass_fonts_dir()
|
|
853
|
+
if fdir:
|
|
854
|
+
vf += f":fontsdir={escape_filter_path(fdir)}"
|
|
855
|
+
if alpha_codec:
|
|
856
|
+
vf += ":alpha=1"
|
|
857
|
+
vf = drawn_chain(vf, meta, [el.get(k) for el in elements for k in ("color", "outline_color", "box_color")],
|
|
858
|
+
labelled=bool(base_label))
|
|
859
|
+
chains.append(f"[{last}]{vf}[vtxt]")
|
|
860
|
+
last = "vtxt"
|
|
861
|
+
eo, emoji_inputs = emoji_filter_chain({"overlays": emoji_overlays}, last, "vfinal", first_input=1,
|
|
862
|
+
to_yuv=rgb_chain_to_bt709(meta),
|
|
863
|
+
base_chain=layer_base_chain(meta), overlay_opts=overlay_format(meta))
|
|
864
|
+
for spec in emoji_inputs:
|
|
865
|
+
cmd += spec
|
|
866
|
+
asset = spec[-1]
|
|
867
|
+
if asset not in STATE.plan_inputs:
|
|
868
|
+
STATE.plan_inputs.append(asset)
|
|
869
|
+
if eo:
|
|
870
|
+
if alpha_codec:
|
|
871
|
+
# at 4:4:4 like every other layer here (overlay's default 4:2:0 subsamples the picture)
|
|
872
|
+
eo = [re.sub(r"(overlay=x=.*?:enable='[^']*')\[", r"\1:format=yuv444[", c) for c in eo]
|
|
873
|
+
chains += eo
|
|
874
|
+
last = "vfinal"
|
|
875
|
+
if finish:
|
|
876
|
+
chains.append(f"[{last}]{finish}[ka_v]")
|
|
877
|
+
last = "ka_v"
|
|
878
|
+
# the conform of a VFR source is the fps filter on the picture as it is decoded (#512)
|
|
879
|
+
cmd += ["-filter_complex", cfr_at_input(";".join(chains), meta), "-map", f"[{last}]",
|
|
880
|
+
"-map", f"0:a:{args.audio_stream}?"]
|
|
881
|
+
elif fc:
|
|
882
|
+
if finish:
|
|
883
|
+
fc.append(f"[vout]{finish}[ka_v]")
|
|
884
|
+
cmd += ["-filter_complex", cfr_at_input(";".join(fc), meta), "-map", "[ka_v]" if finish else "[vout]",
|
|
885
|
+
"-map", f"0:a:{args.audio_stream}?"]
|
|
886
|
+
else:
|
|
887
|
+
vf = ",".join(p for p in (square, text, finish) if p) if finish else (square + "," if square else "") + text
|
|
888
|
+
cmd += ["-vf", with_cfr(vf, meta),
|
|
889
|
+
"-map", "0:v:0", "-map", f"0:a:{args.audio_stream}?"]
|
|
890
|
+
if alpha_codec:
|
|
891
|
+
cmd += video_line(alpha_codec) + tag_args(meta) + cfr_args(meta)
|
|
892
|
+
cmd += audio_line(alpha_codec) if meta.get("audio") else ["-an"]
|
|
893
|
+
if STATE.hw:
|
|
894
|
+
note(f"--hw: --alpha-codec {alpha_codec} stays on the CPU (no VideoToolbox encoder writes it with its alpha)")
|
|
895
|
+
else:
|
|
896
|
+
cmd += video_args(meta, args.crf, args.preset) + cfr_args(meta)
|
|
897
|
+
cmd += aac_args() if meta.get("audio") else ["-an"]
|
|
898
|
+
dropped_streams = run_keeping_subtitles(cmd, output)
|
|
899
|
+
r = probe(output, role="output")
|
|
900
|
+
info(f"wrote {output} ({fmt_secs(r['duration'])}, {args.template})")
|
|
901
|
+
if route == "ass":
|
|
902
|
+
# libass looks the family up itself (fontconfig): the same choice, asked for that renderer
|
|
903
|
+
font_used = font_opts(brand, args.font, args.font_file, script_file, _family, renderer="libass")[1]
|
|
904
|
+
extra = {"template": args.template, "dropped_non_av_streams": dropped_streams,
|
|
905
|
+
"text_renderer": route, "script": _script, "font_used": record_font_choice(font_used)}
|
|
906
|
+
if ass_path:
|
|
907
|
+
extra["ass"] = ass_path
|
|
908
|
+
if emoji_result:
|
|
909
|
+
extra["emoji"] = emoji_result
|
|
910
|
+
if sliced_atoms:
|
|
911
|
+
extra["broken_inside_word"] = len(sliced_atoms)
|
|
912
|
+
# drawn layers add coverage: with --keep-alpha the written alpha is at or above the source's
|
|
913
|
+
# in every frame; without it, an output that lost a used alpha fails the `alpha` step
|
|
914
|
+
alpha_report(args, alpha_codec, src_alpha, output, extra, composite=True)
|
|
915
|
+
emit(output, **extra)
|
|
916
|
+
return 0
|
|
917
|
+
|
|
918
|
+
|
|
919
|
+
if __name__ == "__main__":
|
|
920
|
+
sys.exit(main())
|