@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.
Files changed (230) hide show
  1. package/README.md +62 -2
  2. package/cli.mjs +149 -0
  3. package/lib/dependencies.mjs +384 -0
  4. package/lib/run.mjs +114 -0
  5. package/lib/workspace.mjs +167 -0
  6. package/package.json +240 -3
  7. package/workspace/.agents/skills/cleoedits/SKILL.md +29 -0
  8. package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/audiogram.json +41 -0
  9. package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/facebook.json +48 -0
  10. package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/linkedin.json +48 -0
  11. package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/podcast.json +23 -0
  12. package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/reels.json +48 -0
  13. package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/shorts.json +48 -0
  14. package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/tiktok.json +48 -0
  15. package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/x.json +48 -0
  16. package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/youtube-shorts.json +48 -0
  17. package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/youtube.json +48 -0
  18. package/workspace/.agents/skills/cleoedits/assets/reel_effects/assets/LICENSE-SimpleIcons +30 -0
  19. package/workspace/.agents/skills/cleoedits/assets/reel_effects/assets/logos.json +1 -0
  20. package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Anton-Regular.ttf +0 -0
  21. package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/ArchivoBlack-Regular.ttf +0 -0
  22. package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/InstrumentSerif-Italic.ttf +0 -0
  23. package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Inter.ttf +0 -0
  24. package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/LICENSE-PermanentMarker.txt +202 -0
  25. package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Montserrat.ttf +0 -0
  26. package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-Anton.txt +93 -0
  27. package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-ArchivoBlack.txt +93 -0
  28. package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-InstrumentSerif.txt +93 -0
  29. package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-Inter.txt +93 -0
  30. package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-Montserrat.txt +93 -0
  31. package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-PlayfairDisplay.txt +93 -0
  32. package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-Poppins.txt +93 -0
  33. package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-SpaceMono.txt +93 -0
  34. package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/PermanentMarker-Regular.ttf +0 -0
  35. package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/PlayfairDisplay-Italic.ttf +0 -0
  36. package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/PlayfairDisplay.ttf +0 -0
  37. package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Poppins-Black.ttf +0 -0
  38. package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Poppins-Bold.ttf +0 -0
  39. package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Poppins-ExtraBold.ttf +0 -0
  40. package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/SpaceMono-Bold.ttf +0 -0
  41. package/workspace/.agents/skills/cleoedits/assets/reel_effects/models/LICENSE-MediaPipe +218 -0
  42. package/workspace/.agents/skills/cleoedits/assets/reel_effects/models/LICENSE-YuNet +21 -0
  43. package/workspace/.agents/skills/cleoedits/assets/reel_effects/models/NOTICE.md +4 -0
  44. package/workspace/.agents/skills/cleoedits/assets/reel_effects/models/selfie_segmenter.tflite +0 -0
  45. package/workspace/.agents/skills/cleoedits/assets/reel_effects/models/yunet.onnx +0 -0
  46. package/workspace/.agents/skills/cleoedits/assets/video_styles/LICENSE +21 -0
  47. package/workspace/.agents/skills/cleoedits/assets/video_styles/audio-app-ui/STYLE.md +65 -0
  48. package/workspace/.agents/skills/cleoedits/assets/video_styles/blueprint/STYLE.md +53 -0
  49. package/workspace/.agents/skills/cleoedits/assets/video_styles/blueprint/index.html +328 -0
  50. package/workspace/.agents/skills/cleoedits/assets/video_styles/blueprint/studio.js +57 -0
  51. package/workspace/.agents/skills/cleoedits/assets/video_styles/data-story/STYLE.md +65 -0
  52. package/workspace/.agents/skills/cleoedits/assets/video_styles/data-story/index.html +575 -0
  53. package/workspace/.agents/skills/cleoedits/assets/video_styles/design-app-ui/STYLE.md +68 -0
  54. package/workspace/.agents/skills/cleoedits/assets/video_styles/editor-ui/STYLE.md +73 -0
  55. package/workspace/.agents/skills/cleoedits/assets/video_styles/editorial-paper/STYLE.md +54 -0
  56. package/workspace/.agents/skills/cleoedits/assets/video_styles/editorial-paper/index.html +189 -0
  57. package/workspace/.agents/skills/cleoedits/assets/video_styles/editorial-paper/studio.js +57 -0
  58. package/workspace/.agents/skills/cleoedits/assets/video_styles/explainer-diagram/STYLE.md +64 -0
  59. package/workspace/.agents/skills/cleoedits/assets/video_styles/explainer-diagram/index.html +620 -0
  60. package/workspace/.agents/skills/cleoedits/assets/video_styles/graphite-ui/STYLE.md +55 -0
  61. package/workspace/.agents/skills/cleoedits/assets/video_styles/graphite-ui/index.html +238 -0
  62. package/workspace/.agents/skills/cleoedits/assets/video_styles/graphite-ui/studio.js +57 -0
  63. package/workspace/.agents/skills/cleoedits/assets/video_styles/growing-city/STYLE.md +66 -0
  64. package/workspace/.agents/skills/cleoedits/assets/video_styles/growing-city/index.html +602 -0
  65. package/workspace/.agents/skills/cleoedits/assets/video_styles/ink-line/STYLE.md +66 -0
  66. package/workspace/.agents/skills/cleoedits/assets/video_styles/ink-line/index.html +777 -0
  67. package/workspace/.agents/skills/cleoedits/assets/video_styles/midnight-grid/STYLE.md +56 -0
  68. package/workspace/.agents/skills/cleoedits/assets/video_styles/midnight-grid/index.html +186 -0
  69. package/workspace/.agents/skills/cleoedits/assets/video_styles/midnight-grid/studio.js +57 -0
  70. package/workspace/.agents/skills/cleoedits/assets/video_styles/motion-app-ui/STYLE.md +68 -0
  71. package/workspace/.agents/skills/cleoedits/assets/video_styles/paper-cut/STYLE.md +56 -0
  72. package/workspace/.agents/skills/cleoedits/assets/video_styles/paper-cut/index.html +244 -0
  73. package/workspace/.agents/skills/cleoedits/assets/video_styles/paper-cut/studio.js +57 -0
  74. package/workspace/.agents/skills/cleoedits/assets/video_styles/paper-world/STYLE.md +67 -0
  75. package/workspace/.agents/skills/cleoedits/assets/video_styles/paper-world/index.html +663 -0
  76. package/workspace/.agents/skills/cleoedits/assets/video_styles/particle-field/STYLE.md +59 -0
  77. package/workspace/.agents/skills/cleoedits/assets/video_styles/particle-field/index.html +395 -0
  78. package/workspace/.agents/skills/cleoedits/assets/video_styles/poster-pop/STYLE.md +52 -0
  79. package/workspace/.agents/skills/cleoedits/assets/video_styles/poster-pop/index.html +194 -0
  80. package/workspace/.agents/skills/cleoedits/assets/video_styles/poster-pop/studio.js +57 -0
  81. package/workspace/.agents/skills/cleoedits/assets/video_styles/risograph/STYLE.md +58 -0
  82. package/workspace/.agents/skills/cleoedits/assets/video_styles/risograph/index.html +242 -0
  83. package/workspace/.agents/skills/cleoedits/assets/video_styles/risograph/studio.js +57 -0
  84. package/workspace/.agents/skills/cleoedits/assets/video_styles/swiss-grid/STYLE.md +53 -0
  85. package/workspace/.agents/skills/cleoedits/assets/video_styles/swiss-grid/index.html +138 -0
  86. package/workspace/.agents/skills/cleoedits/assets/video_styles/swiss-grid/studio.js +57 -0
  87. package/workspace/.agents/skills/cleoedits/assets/video_styles/swiss-kinetic/STYLE.md +63 -0
  88. package/workspace/.agents/skills/cleoedits/assets/video_styles/swiss-kinetic/index.html +599 -0
  89. package/workspace/.agents/skills/cleoedits/assets/video_styles/time-travel/STYLE.md +65 -0
  90. package/workspace/.agents/skills/cleoedits/assets/video_styles/time-travel/index.html +1297 -0
  91. package/workspace/.agents/skills/cleoedits/assets/video_styles/weather-widget/STYLE.md +69 -0
  92. package/workspace/.agents/skills/cleoedits/assets/video_styles/weather-widget/index.html +674 -0
  93. package/workspace/.agents/skills/cleoedits/references/audio-clearervoice-elevenlabs.md +11 -0
  94. package/workspace/.agents/skills/cleoedits/references/ffmpeg-and-reels.md +15 -0
  95. package/workspace/.agents/skills/cleoedits/references/hyperframes-workflows.md +13 -0
  96. package/workspace/.agents/skills/cleoedits/references/kdenlive-cli-and-mcp.md +12 -0
  97. package/workspace/.agents/skills/cleoedits/references/motion-design-pipeline.md +7 -0
  98. package/workspace/.agents/skills/cleoedits/references/motion-taste-emil.md +5 -0
  99. package/workspace/.agents/skills/cleoedits/references/playwright-demo-capture.md +9 -0
  100. package/workspace/.agents/skills/cleoedits/references/remotion-workflows.md +13 -0
  101. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/LICENSE +21 -0
  102. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_ass_overlay.py +399 -0
  103. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/__init__.py +235 -0
  104. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/alpha.py +560 -0
  105. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/asr.py +1237 -0
  106. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/color.py +540 -0
  107. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/decision.py +2452 -0
  108. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/drawtext.py +290 -0
  109. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/emit.py +1309 -0
  110. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/emoji.py +518 -0
  111. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/fonts.py +875 -0
  112. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/pacing.py +263 -0
  113. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/pacing_edit.py +432 -0
  114. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/probe.py +1613 -0
  115. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/runner.py +3994 -0
  116. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/text.py +73 -0
  117. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/timeline.py +721 -0
  118. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/wrap.py +981 -0
  119. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_contract.py +2454 -0
  120. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_platforms.py +258 -0
  121. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_review.html +754 -0
  122. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_review.py +258 -0
  123. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_smartcut.py +450 -0
  124. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/audio.py +867 -0
  125. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/background.py +136 -0
  126. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/batch.py +1409 -0
  127. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/broll.py +282 -0
  128. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/caption.py +2207 -0
  129. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/check.py +815 -0
  130. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/color.py +695 -0
  131. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/crop.py +91 -0
  132. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/cropdetect.py +214 -0
  133. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/cut.py +2076 -0
  134. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/deinterlace.py +90 -0
  135. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/denoise.py +94 -0
  136. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/export.py +1033 -0
  137. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/fit.py +729 -0
  138. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/freeze.py +197 -0
  139. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/graphics.py +920 -0
  140. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/grid.py +235 -0
  141. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/insert.py +142 -0
  142. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/join.py +1083 -0
  143. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/look.py +475 -0
  144. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/loop.py +395 -0
  145. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/loudness.py +397 -0
  146. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/metadata.py +416 -0
  147. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/multicam.py +414 -0
  148. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/overlay.py +766 -0
  149. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/pad.py +121 -0
  150. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/probe.py +145 -0
  151. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/proxy.py +93 -0
  152. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/redact.py +162 -0
  153. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/render.py +2424 -0
  154. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/report.py +354 -0
  155. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/reverse.py +114 -0
  156. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/scenes.py +439 -0
  157. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/sequence.py +285 -0
  158. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/silence.py +945 -0
  159. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/speedramp.py +193 -0
  160. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/sphere.py +137 -0
  161. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/stabilize.py +141 -0
  162. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/straighten.py +120 -0
  163. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/sync.py +500 -0
  164. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/verify.py +411 -0
  165. package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/waveform.py +502 -0
  166. package/workspace/.agents/skills/cleoedits/scripts/kdenlive_builder.py +284 -0
  167. package/workspace/.agents/skills/cleoedits/scripts/motion/LICENSE-claude-motion +21 -0
  168. package/workspace/.agents/skills/cleoedits/scripts/motion/LICENSE-motion-design +21 -0
  169. package/workspace/.agents/skills/cleoedits/scripts/motion/_media.py +43 -0
  170. package/workspace/.agents/skills/cleoedits/scripts/motion/pacing_check.py +90 -0
  171. package/workspace/.agents/skills/cleoedits/scripts/motion/storyboard.py +77 -0
  172. package/workspace/.agents/skills/cleoedits/scripts/reel_effects/LICENSE +26 -0
  173. package/workspace/.agents/skills/cleoedits/scripts/reel_effects/fx.py +2717 -0
  174. package/workspace/.agents/skills/cleoedits/scripts/reel_effects/logos.py +194 -0
  175. package/workspace/.agents/skills/cleoedits/scripts/reel_effects/sfx.py +105 -0
  176. package/workspace/.agents/skills/cleoedits/scripts/reel_effects/trim.py +99 -0
  177. package/workspace/.agents/skills/cleoedits/scripts/reel_effects/words.py +60 -0
  178. package/workspace/.claude/commands/blender-3d.md +12 -0
  179. package/workspace/.claude/commands/business-short-form-reels.md +12 -0
  180. package/workspace/.claude/commands/color-grade.md +12 -0
  181. package/workspace/.claude/commands/cutout-grid-reel.md +12 -0
  182. package/workspace/.claude/commands/depth-ui-reel.md +12 -0
  183. package/workspace/.claude/commands/explainer-panel-reel.md +12 -0
  184. package/workspace/.claude/commands/freeze-frame.md +12 -0
  185. package/workspace/.claude/commands/glass-graph.md +12 -0
  186. package/workspace/.claude/commands/over-the-shoulder.md +12 -0
  187. package/workspace/.claude/commands/personal-short-form-reels.md +12 -0
  188. package/workspace/.claude/commands/ranking-format.md +12 -0
  189. package/workspace/.claude/commands/relight.md +12 -0
  190. package/workspace/.claude/commands/reverse-engineer.md +12 -0
  191. package/workspace/.claude/commands/text-behind.md +12 -0
  192. package/workspace/.claude/commands/tier-list.md +12 -0
  193. package/workspace/.claude-plugin/plugin.json +8 -0
  194. package/workspace/.npmignore +15 -0
  195. package/workspace/AGENTS.md +30 -0
  196. package/workspace/README.md +63 -0
  197. package/workspace/assets/fonts/TikTokSans-OFL.txt +93 -0
  198. package/workspace/assets/fonts/TikTokSans-Variable.ttf +0 -0
  199. package/workspace/assets/luts/clean_warm.cube +4917 -0
  200. package/workspace/assets/luts/golden_hour.cube +4917 -0
  201. package/workspace/assets/luts/moody_dark.cube +4917 -0
  202. package/workspace/assets/luts/teal_orange.cube +4917 -0
  203. package/workspace/assets/sfx/NOTICE.txt +1 -0
  204. package/workspace/assets/sfx/click.wav +0 -0
  205. package/workspace/assets/sfx/pop.wav +0 -0
  206. package/workspace/assets/sfx/riser.wav +0 -0
  207. package/workspace/assets/sfx/whoosh.wav +0 -0
  208. package/workspace/generators/hyperframes/index.html +39 -0
  209. package/workspace/generators/hyperframes/package.json +15 -0
  210. package/workspace/generators/hyperframes/pnpm-lock.yaml +1181 -0
  211. package/workspace/generators/hyperframes/pnpm-workspace.yaml +10 -0
  212. package/workspace/generators/remotion/eslint.config.mjs +3 -0
  213. package/workspace/generators/remotion/package.json +36 -0
  214. package/workspace/generators/remotion/pnpm-lock.yaml +4179 -0
  215. package/workspace/generators/remotion/pnpm-workspace.yaml +10 -0
  216. package/workspace/generators/remotion/remotion.config.ts +13 -0
  217. package/workspace/generators/remotion/src/Root.tsx +52 -0
  218. package/workspace/generators/remotion/src/index.css +1 -0
  219. package/workspace/generators/remotion/src/index.ts +4 -0
  220. package/workspace/generators/remotion/tsconfig.json +15 -0
  221. package/workspace/pipeline/scripts/_codec.py +28 -0
  222. package/workspace/pipeline/scripts/ai_media_api.py +109 -0
  223. package/workspace/pipeline/scripts/blender_render.py +166 -0
  224. package/workspace/pipeline/scripts/composite.py +49 -0
  225. package/workspace/pipeline/scripts/melt.sh +68 -0
  226. package/workspace/pipeline/scripts/normalize_audio.py +39 -0
  227. package/workspace/pipeline/scripts/person_matte.py +216 -0
  228. package/workspace/pipeline/scripts/record_demo.py +69 -0
  229. package/workspace/pipeline/scripts/whisper_cut.py +98 -0
  230. package/workspace-manifest.json +908 -0
@@ -0,0 +1,518 @@
1
+ """Emoji: cluster detection (ZWJ sequences, keycaps, flags, skin tones), the PNG asset lookup,
2
+ the per-machine support probe and the overlay filter chain that composites the assets.
3
+ Split out of _common.text in the refactor after 1.17.3; every body is byte-identical.
4
+ """
5
+ from __future__ import annotations
6
+
7
+ import os
8
+ import subprocess
9
+ from typing import Any, Dict, List, Tuple, Optional
10
+ from _common.decision import escape_filter_path
11
+ from _common.emit import die
12
+ from _common.runner import ffmpeg_exe
13
+ from _common.runner import safe_which as _safe_which
14
+
15
+
16
+ # --------------------------------------------------------------------------- emoji (1.15)
17
+ # Emoji are orthogonal to the writing system: "やった 🎉" is Japanese AND emoji. They are detected
18
+ # separately from detect_script() so a cue's font resolution is still decided by its letters.
19
+ EMOJI_RANGES = (
20
+ (0x1F300, 0x1FAFF), # symbols & pictographs, supplemental, extended-A
21
+ (0x1F000, 0x1F0FF), # mahjong/domino/playing cards (only 🀄 and 🃏 are emoji)
22
+ (0x2600, 0x27BF), # misc symbols + dingbats (Emoji_Presentation only: _is_emoji_char)
23
+ (0x2B00, 0x2BFF), # misc symbols and arrows (likewise)
24
+ (0xFE0F, 0xFE0F), # VS16 (emoji presentation selector)
25
+ (0x1F1E6, 0x1F1FF), # regional indicators (flags)
26
+ (0x20E3, 0x20E3), # combining enclosing keycap
27
+ (0x1F3FB, 0x1F3FF), # skin-tone modifiers
28
+ )
29
+
30
+
31
+ # U+200D ZWJ is deliberately NOT in EMOJI_RANGES: it is ordinary Indic/Persian orthography
32
+ # (क्‍ष is ka + virama + ZWJ + ssa) and only becomes emoji glue *between two emoji bases*.
33
+ # Characters that never START a cluster: they bind to whatever stands before them.
34
+ _EMOJI_TAIL = frozenset({0x200D, 0xFE0F, 0x20E3} | set(range(0x1F3FB, 0x1F400)))
35
+
36
+
37
+ _EMOJI_REGIONAL = range(0x1F1E6, 0x1F200)
38
+
39
+
40
+ _ZWJ = 0x200D
41
+
42
+
43
+ _VS15 = 0xFE0E # text-presentation selector: "draw this as a character, not as an emoji"
44
+
45
+
46
+ _VS16 = 0xFE0F
47
+
48
+
49
+ _KEYCAP = 0x20E3
50
+
51
+
52
+ _KEYCAP_BASES = frozenset("0123456789#*")
53
+
54
+
55
+ def _cps(*spans) -> "frozenset":
56
+ out = set()
57
+ for span in spans:
58
+ lo, hi = span if isinstance(span, tuple) else (span, span)
59
+ out.update(range(lo, hi + 1))
60
+ return frozenset(out)
61
+
62
+
63
+ # The text-symbol blocks in EMOJI_RANGES (U+2600-27BF, U+2B00-2BFF, U+1F000-1F0FF) are mostly
64
+ # *text*: ♪ U+266A, ✓ U+2713 and ★ U+2605 are not emoji at all in Unicode's emoji-data.txt, and
65
+ # ♥ U+2665, ✔ U+2714, ☺ U+263A are emoji only when VS16 asks for the picture -- their default
66
+ # presentation is the character, which the caption font draws. Counting the whole block made
67
+ # SDH music notes and check marks "emoji", and `--emoji none` (what macOS and a Linux box
68
+ # without a colour face get under auto) cut them out of the burned text. In those blocks only
69
+ # Emoji_Presentation=Yes characters start a cluster on their own; an Emoji=Yes one does when
70
+ # VS16 or a skin-tone modifier follows it. The pictograph blocks also contain
71
+ # text-default emoji. Both sets are pinned from emoji-data.txt (Unicode 15.1).
72
+ _EMOJI_PRESENTATION_SYMBOLS = _cps(
73
+ (0x2614, 0x2615), (0x2648, 0x2653), 0x267F, 0x2693, 0x26A1, (0x26AA, 0x26AB),
74
+ (0x26BD, 0x26BE), (0x26C4, 0x26C5), 0x26CE, 0x26D4, 0x26EA, (0x26F2, 0x26F3), 0x26F5,
75
+ 0x26FA, 0x26FD, 0x2705, (0x270A, 0x270B), 0x2728, 0x274C, 0x274E, (0x2753, 0x2755), 0x2757,
76
+ (0x2795, 0x2797), 0x27B0, 0x27BF, (0x2B1B, 0x2B1C), 0x2B50, 0x2B55, 0x1F004, 0x1F0CF)
77
+ _EMOJI_TEXT_DEFAULT_SYMBOLS = _cps(
78
+ (0x2600, 0x2604), 0x260E, 0x2611, 0x2618, 0x261D, 0x2620, (0x2622, 0x2623), 0x2626, 0x262A,
79
+ (0x262E, 0x262F), (0x2638, 0x263A), 0x2640, 0x2642, (0x265F, 0x2660), 0x2663,
80
+ (0x2665, 0x2666), 0x2668, 0x267B, 0x267E, (0x2692, 0x2697), 0x2699, (0x269B, 0x269C),
81
+ 0x26A0, 0x26A7, (0x26B0, 0x26B1), 0x26C8, 0x26CF, 0x26D1, 0x26D3, 0x26E9, (0x26F0, 0x26F1),
82
+ 0x26F4, (0x26F7, 0x26F9), 0x2702, (0x2708, 0x2709), (0x270C, 0x270D), 0x270F, 0x2712, 0x2714,
83
+ 0x2716, 0x271D, 0x2721, (0x2733, 0x2734), 0x2744, 0x2747, (0x2763, 0x2764), 0x27A1,
84
+ (0x2B05, 0x2B07),
85
+ 0x1F321, (0x1F324, 0x1F32C), 0x1F336, 0x1F37D, (0x1F396, 0x1F397), (0x1F399, 0x1F39B),
86
+ (0x1F39E, 0x1F39F), (0x1F3CB, 0x1F3CE), (0x1F3D4, 0x1F3DF), 0x1F3F3, 0x1F3F5, 0x1F3F7,
87
+ 0x1F43F, 0x1F441, 0x1F4FD, (0x1F549, 0x1F54A), (0x1F56F, 0x1F570), (0x1F573, 0x1F579),
88
+ 0x1F587, (0x1F58A, 0x1F58D), 0x1F590, 0x1F5A5, 0x1F5A8, (0x1F5B1, 0x1F5B2), 0x1F5BC,
89
+ (0x1F5C2, 0x1F5C4), (0x1F5D1, 0x1F5D3), (0x1F5DC, 0x1F5DE), 0x1F5E1, 0x1F5E3, 0x1F5E8,
90
+ 0x1F5EF, 0x1F5F3, 0x1F5FA, 0x1F6CB, (0x1F6CD, 0x1F6CF), (0x1F6E0, 0x1F6E5), 0x1F6E9,
91
+ 0x1F6F0, 0x1F6F3)
92
+ _SYMBOL_BLOCKS = ((0x2600, 0x27BF), (0x2B00, 0x2BFF), (0x1F000, 0x1F0FF))
93
+
94
+
95
+ def _in_symbol_block(cp: int) -> bool:
96
+ return any(lo <= cp <= hi for lo, hi in _SYMBOL_BLOCKS)
97
+
98
+
99
+ def _is_emoji_char(ch: str) -> bool:
100
+ """Does this character use emoji presentation by default?"""
101
+ cp = ord(ch)
102
+ if _in_symbol_block(cp):
103
+ return cp in _EMOJI_PRESENTATION_SYMBOLS
104
+ return cp not in _EMOJI_TEXT_DEFAULT_SYMBOLS and any(lo <= cp <= hi for lo, hi in EMOJI_RANGES)
105
+
106
+
107
+ def _can_be_emoji(ch: str) -> bool:
108
+ """Emoji=Yes: an emoji by default, or a text-default symbol VS16 can turn into one (♥ ✔)."""
109
+ return _is_emoji_char(ch) or ord(ch) in _EMOJI_TEXT_DEFAULT_SYMBOLS
110
+
111
+
112
+ def _is_emoji_base(ch: str) -> bool:
113
+ """Can this character START an emoji cluster? Pictographs and regional indicators can;
114
+ the joiners and modifiers (ZWJ, VS16, keycap, skin tone) never can -- they only bind to an
115
+ emoji base that already stands before them. Without this, a ZWJ or a VS16 sitting after an
116
+ ordinary letter turned that letter into "an emoji" and the PNG route replaced it with a gap.
117
+ A text-default symbol (♥ ✔ ☝) is a base only with the VS16 or modifier that follows it:
118
+ emoji_clusters() checks that, this function answers for the character alone."""
119
+ return ord(ch) not in _EMOJI_TAIL and _is_emoji_char(ch)
120
+
121
+
122
+ def _starts_emoji(text: str, i: int) -> bool:
123
+ """Does an emoji cluster start at text[i]? A default-emoji base does; a text-default symbol
124
+ does only when VS16 or a skin-tone modifier follows it (♥️, ☝🏽), the sequences Unicode
125
+ defines as emoji; ♥ alone, and ♪ ✓ ★ always, are characters the font draws."""
126
+ ch = text[i]
127
+ if _is_emoji_base(ch):
128
+ return True
129
+ if ord(ch) in _EMOJI_TEXT_DEFAULT_SYMBOLS and i + 1 < len(text):
130
+ nxt = ord(text[i + 1])
131
+ return nxt == _VS16 or 0x1F3FB <= nxt <= 0x1F3FF
132
+ return False
133
+
134
+
135
+ def emoji_clusters(text: str) -> "List[Tuple[int, str]]":
136
+ """(index in `text`, cluster) for every emoji in it, ZWJ sequences, VS16, keycaps, flag pairs
137
+ and skin-tone modifiers kept together -- 👩‍💻 is one cluster, not three, and 1️⃣ starts at the
138
+ digit even though the digit is not itself an emoji character.
139
+
140
+ A cluster can only START at an emoji base (a pictograph, a regional indicator) or at a keycap
141
+ base (`0-9 # *`) that is actually followed by U+20E3. A ZWJ is glue *inside* a cluster, never
142
+ a starter and never a tail on its own: `क्‍ष` (Hindi ka + virama + ZWJ + ssa) and `abc‍def`
143
+ contain no emoji. A base explicitly marked with U+FE0E (VS15, text presentation) is likewise
144
+ not an emoji -- the author asked for the character, not the picture. A text-default symbol
145
+ (♥ ✔ ☝) starts one only with the VS16 or skin-tone modifier after it, and a symbol that is
146
+ not emoji at all (♪ ✓ ★) never does: the caption font draws those.
147
+ """
148
+ out: "List[Tuple[int, str]]" = []
149
+ i = 0
150
+ n = len(text or "")
151
+ while i < n:
152
+ ch = text[i]
153
+ start = i
154
+ if _starts_emoji(text, i):
155
+ j = i + 1
156
+ if j < n and ord(text[j]) == _VS15: # text presentation requested: not an emoji
157
+ i = j + 1
158
+ continue
159
+ elif ch in _KEYCAP_BASES:
160
+ j = i + 1
161
+ if j < n and ord(text[j]) == _VS16:
162
+ j += 1
163
+ if not (j < n and ord(text[j]) == _KEYCAP):
164
+ i += 1
165
+ continue
166
+ j += 1
167
+ else:
168
+ i += 1
169
+ continue
170
+ # extend: modifiers bind rightwards, a ZWJ only when a real emoji base follows it
171
+ while j < n:
172
+ cp = ord(text[j])
173
+ if cp in (_VS16, _KEYCAP) or 0x1F3FB <= cp <= 0x1F3FF:
174
+ j += 1
175
+ continue
176
+ if cp == _ZWJ and j + 1 < n and ord(text[j + 1]) not in _EMOJI_TAIL \
177
+ and _can_be_emoji(text[j + 1]):
178
+ # inside a ZWJ sequence a text-default symbol is emoji glue too: 🏃‍♀ ends in ♀
179
+ j += 2
180
+ continue
181
+ if (j == start + 1 and ord(ch) in _EMOJI_REGIONAL and cp in _EMOJI_REGIONAL):
182
+ j += 1
183
+ continue
184
+ break
185
+ out.append((start, text[start:j]))
186
+ i = j
187
+ return out
188
+
189
+
190
+ def has_emoji(text: str) -> bool:
191
+ return bool(emoji_clusters(text or ""))
192
+
193
+
194
+ def emoji_codepoint_name(cluster: str) -> str:
195
+ """The asset filename stem for a cluster: lowercase hex code points joined by '-', the
196
+ Twemoji convention (1f389, 1f469-200d-1f4bb, 1f1ef-1f1f5); emoji_asset_for() also tries Noto's."""
197
+ return "-".join(f"{ord(c):x}" for c in cluster)
198
+
199
+
200
+ def _emoji_name_candidates(cluster: str) -> "List[str]":
201
+ """Asset stems to try, most specific first: exact, without VS16, without skin tone, the ZWJ
202
+ sequence reduced to its first code point, the bare base."""
203
+ cps = [ord(c) for c in cluster]
204
+ names = [emoji_codepoint_name(cluster)]
205
+
206
+ def add(seq):
207
+ name = "-".join(f"{c:x}" for c in seq)
208
+ if name and name not in names:
209
+ names.append(name)
210
+ add([c for c in cps if c != 0xFE0F])
211
+ add([c for c in cps if c != 0xFE0F and not (0x1F3FB <= c <= 0x1F3FF)])
212
+ if 0x200D in cps:
213
+ add([cps[0]])
214
+ add([cps[0]])
215
+ return names
216
+
217
+
218
+ def emoji_asset_for(cluster: str, assets_dir: "Optional[str]") -> "Optional[str]":
219
+ """The PNG for `cluster` under `assets_dir`, or None when nothing matches."""
220
+ if not assets_dir or not os.path.isdir(assets_dir):
221
+ return None
222
+ for name in _emoji_name_candidates(cluster):
223
+ # Twemoji's name (1f469-200d-1f4bb.png, 31-20e3.png), then Noto Emoji's, whose code points
224
+ # are at least four hex digits (emoji_u1f469_200d_1f4bb.png, emoji_u0031_20e3.png): the hint
225
+ # names noto-emoji/png/128, whose files were never found (#404)
226
+ for stem in (name, "emoji_u" + "_".join(cp.zfill(4) for cp in name.split("-"))):
227
+ for ext in (".png", ".PNG"):
228
+ candidate = os.path.join(assets_dir, stem + ext)
229
+ if os.path.isfile(candidate):
230
+ return candidate
231
+ return None
232
+
233
+
234
+ def emoji_mono_on_colour_note(support: "Dict[str, Any]") -> str:
235
+ """--emoji mono on a build whose libass draws the emoji face in colour: nothing here makes that
236
+ glyph monochrome (mono and color build the same text), so the result says color (#403: the
237
+ warning said "no colour path" beside a detail saying it renders in colour)."""
238
+ return ("--emoji mono: libass draws the emoji face in colour on this build and nothing here makes it "
239
+ "monochrome, so the emoji are drawn in colour (mode: color). " + str(support.get("detail") or ""))
240
+
241
+
242
+ def emoji_missing_asset_note(missing: "List[str]", support: "Dict[str, Any]") -> str:
243
+ """What happens to the clusters --emoji-assets has no PNG for: they stay in the text for libass,
244
+ which is said as measured (libass_glyph), not as "drawn by the text font" (#403)."""
245
+ names = ", ".join(missing)
246
+ if support.get("libass_glyph") is False:
247
+ return (f"no PNG in the assets directory for {names} -- those clusters stay in the text, and libass draws no "
248
+ "emoji glyph on this build: an empty box at best")
249
+ return (f"no PNG in the assets directory for {names} -- those clusters stay in the text for libass to draw "
250
+ "with an installed face" + ("" if support.get("libass_glyph") else " (whether one has the glyph was not measured)"))
251
+
252
+
253
+ EMOJI_ASSET_HINT = (
254
+ "point --emoji-assets at a directory of PNGs named by code point (1f389.png): "
255
+ "twemoji/assets/72x72 (Twemoji, CC-BY 4.0) or noto-emoji/png/128 (Noto Emoji, OFL/Apache-2.0) "
256
+ "are the two people already have. The skill has no network at runtime, so the assets must "
257
+ "already exist on this machine -- nothing is ever downloaded")
258
+
259
+
260
+ _EMOJI_COLOR_FAMILIES = ("Noto Color Emoji", "Apple Color Emoji", "Segoe UI Emoji")
261
+
262
+
263
+ def _fc_list_path(line: str) -> str:
264
+ """The file from one `fc-list ... file` line.
265
+
266
+ fontconfig prints `<file>: <families>`. The separator is a colon followed by a space.
267
+ A Windows drive letter is `C:` followed by a backslash, so splitting on the first colon
268
+ yields `C` and the font is reported missing.
269
+ """
270
+ if ": " in line:
271
+ return line.partition(": ")[0].strip()
272
+ return line.strip().rstrip(":")
273
+
274
+
275
+ _EMOJI_SUPPORT_CACHE: "Dict[Tuple[Optional[str], bool], Dict[str, Any]]" = {}
276
+
277
+
278
+ def _emoji_color_font() -> "Tuple[Optional[str], Optional[str], bool]":
279
+ """(family, file, fontconfig_answered) for the first installed colour emoji family."""
280
+ exe = _safe_which("fc-list")
281
+ if not exe:
282
+ return None, None, False
283
+ for family in _EMOJI_COLOR_FAMILIES:
284
+ try:
285
+ proc = subprocess.run([exe, f":family={family}", "file"], stdout=subprocess.PIPE,
286
+ stderr=subprocess.DEVNULL, text=True, encoding="utf-8", errors="replace", timeout=10)
287
+ except (subprocess.TimeoutExpired, OSError):
288
+ return None, None, False
289
+ if proc.returncode != 0:
290
+ return None, None, False
291
+ for line in proc.stdout.splitlines():
292
+ path = _fc_list_path(line)
293
+ if path and os.path.exists(path):
294
+ return family, path, True
295
+ return None, None, True
296
+
297
+
298
+ def _libass_color_probe() -> "Optional[bool]":
299
+ """Does THIS ffmpeg render an emoji in colour through libass? Answered by a render, never by
300
+ the font listing: Noto Color Emoji installs happily on builds whose freetype/libass has no
301
+ colour-bitmap path at all, and those render a monochrome outline instead (measured). ~80 ms.
302
+ None means the probe could not be run (no ffmpeg, a failure) -- unknown, not false."""
303
+ exe = ffmpeg_exe("ffmpeg")[0]
304
+ if not exe:
305
+ return None
306
+ import tempfile
307
+ with tempfile.TemporaryDirectory() as td:
308
+ srt = os.path.join(td, "e.srt")
309
+ with open(srt, "w", encoding="utf-8") as fh:
310
+ fh.write("1\n00:00:00,000 --> 00:00:01,000\n\U0001F389\n")
311
+ try:
312
+ proc = subprocess.run(
313
+ [exe, "-hide_banner", "-loglevel", "error", "-f", "lavfi",
314
+ "-i", "color=c=black:s=64x64:d=0.04",
315
+ "-vf", "subtitles=" + escape_filter_path(srt, bind=False), "-frames:v", "1",
316
+ "-f", "rawvideo", "-pix_fmt", "rgb24", "-"],
317
+ stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, timeout=20)
318
+ except (subprocess.TimeoutExpired, OSError):
319
+ return None
320
+ if proc.returncode != 0 or len(proc.stdout) < 64 * 64 * 3:
321
+ return None
322
+ data = proc.stdout
323
+ for i in range(0, 64 * 64 * 3, 3):
324
+ r, g, b = data[i], data[i + 1], data[i + 2]
325
+ if max(r, g, b) - min(r, g, b) > 40:
326
+ return True
327
+ return False
328
+
329
+
330
+ def _libass_render(exe: str, char: str, fonts_dir: "Optional[str]" = None) -> "Optional[bytes]":
331
+ """One 96x96 rgb24 frame of `char` drawn through libass (subtitles=), or None when it failed."""
332
+ import tempfile
333
+ with tempfile.TemporaryDirectory() as td:
334
+ srt = os.path.join(td, "g.srt")
335
+ with open(srt, "w", encoding="utf-8") as fh:
336
+ fh.write(f"1\n00:00:00,000 --> 00:00:01,000\n{char}\n")
337
+ try:
338
+ proc = subprocess.run(
339
+ [exe, "-hide_banner", "-loglevel", "error", "-f", "lavfi",
340
+ "-i", "color=c=black:s=96x96:d=0.04",
341
+ "-vf", "subtitles=" + escape_filter_path(srt, bind=False) + ":force_style='FontSize=64,Alignment=5'"
342
+ + (":fontsdir=" + escape_filter_path(fonts_dir, bind=False) if fonts_dir else ""),
343
+ "-frames:v", "1", "-f", "rawvideo", "-pix_fmt", "rgb24", "-"],
344
+ stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, timeout=20)
345
+ except (subprocess.TimeoutExpired, OSError):
346
+ return None
347
+ if proc.returncode != 0 or len(proc.stdout) < 96 * 96 * 3:
348
+ return None
349
+ return proc.stdout
350
+
351
+
352
+ def _libass_glyph_probe(fonts_dir: "Optional[str]" = None) -> "Optional[bool]":
353
+ """Does libass draw an emoji GLYPH at all, or only what it draws for a character no face has?
354
+ "No colour pixels" (_libass_color_probe False) covers both a monochrome glyph and the empty
355
+ .notdef box: Apple Color Emoji (an sbix bitmap face) gives libass no usable glyph, and the box
356
+ is white (#395). So the emoji is compared with U+10FFFD, a code point no font carries: the same
357
+ frame, or nothing lit, is no glyph. A caller's --fonts-dir is searched too, as the burn searches it.
358
+ None: the probe could not run."""
359
+ exe = ffmpeg_exe("ffmpeg")[0]
360
+ if not exe:
361
+ return None
362
+ emoji, nothing = _libass_render(exe, "\U0001F389", fonts_dir), _libass_render(exe, "\U0010FFFD", fonts_dir)
363
+ if emoji is None or nothing is None:
364
+ return None
365
+ lit = any(emoji[i] > 60 for i in range(0, len(emoji)))
366
+ return bool(lit and emoji != nothing)
367
+
368
+
369
+ def emoji_support(assets: "Optional[str]" = None, probe: bool = True, fonts_dir: "Optional[str]" = None) -> "Dict[str, Any]":
370
+ """What this machine can actually do with emoji, cached per process.
371
+
372
+ `mode` is `color` when a render probe proves libass draws colour, else `png` when an assets
373
+ directory resolves, else `mono` when some installed face has a glyph at all, else `none`.
374
+ An installed colour emoji font proves nothing on its own -- that is why `libass_color` comes
375
+ from a render (see references/gotchas.md#emoji). `probe=False` (`contract --json --static`, and every
376
+ static/JSON-only path) skips the render entirely and leaves `libass_color` unknown.
377
+ """
378
+ key = (assets or None, bool(probe), fonts_dir or None)
379
+ if key in _EMOJI_SUPPORT_CACHE:
380
+ return dict(_EMOJI_SUPPORT_CACHE[key])
381
+ family, file, fc_answered = _emoji_color_font()
382
+ libass_color = _libass_color_probe() if probe else None
383
+ # a colour render is a glyph; without one, ask whether libass draws one at all (#395)
384
+ libass_glyph = True if libass_color else (_libass_glyph_probe(fonts_dir) if probe and libass_color is False else None)
385
+ assets_dir = assets if (assets and os.path.isdir(assets)) else None
386
+ if libass_color:
387
+ mode = "color"
388
+ elif assets_dir:
389
+ mode = "png"
390
+ elif family and libass_glyph is False:
391
+ mode = "none"
392
+ elif family or libass_glyph:
393
+ # a face libass draws the emoji from, colour family listed or not (A64, #457: a glyph from
394
+ # a monochrome face was answered `none`, against this docstring and libass_glyph: true)
395
+ mode = "mono"
396
+ elif not fc_answered:
397
+ # No fontconfig to ask (a static ffmpeg build, a bare container): the PNG path needs none,
398
+ # so the honest answer is png-or-none, never "none because fc-list is missing".
399
+ mode = "none"
400
+ else:
401
+ mode = "none"
402
+ if not fc_answered:
403
+ detail = "no fontconfig on this machine; the PNG overlay path needs none"
404
+ elif libass_color:
405
+ detail = f"{family or 'an installed face'} renders in colour through libass on this ffmpeg"
406
+ elif family and libass_glyph is False:
407
+ detail = (f"{family} installed but libass draws no emoji glyph from it on this build (the render "
408
+ "matches a code point no font has: an empty box or nothing)")
409
+ elif family and libass_color is False:
410
+ detail = f"{family} installed but libass renders it monochrome on this build"
411
+ elif family and libass_color is None:
412
+ detail = f"{family} installed; the colour render probe was not run"
413
+ elif assets_dir:
414
+ detail = "no colour emoji family installed; using the PNG assets directory"
415
+ elif libass_glyph:
416
+ detail = "no colour emoji family installed; libass draws the emoji monochrome from an installed face"
417
+ else:
418
+ detail = "no colour emoji family installed and no --emoji-assets directory"
419
+ result = {"mode": mode, "color_font": family, "color_font_file": file,
420
+ "libass_color": libass_color, "libass_glyph": libass_glyph, "assets": assets_dir,
421
+ "detail": detail, "fix": EMOJI_ASSET_HINT}
422
+ _EMOJI_SUPPORT_CACHE[key] = result
423
+ return dict(result)
424
+
425
+
426
+ def resolve_emoji_assets(flag: "Optional[str]" = None, project: "Optional[str]" = None,
427
+ brand: "Optional[dict]" = None) -> "Optional[str]":
428
+ """--emoji-assets DIR, else the project key, else brand.json, else FFMPEG_SKILL_EMOJI_ASSETS.
429
+ A directory that was named but does not exist is a failed job, never a silent downgrade."""
430
+ brand = brand or {}
431
+ styles = (brand.get("styles") or {}).get("caption") or {}
432
+ for value, where in ((flag, "--emoji-assets"), (project, "the project's text.emoji_assets"),
433
+ (styles.get("emoji_assets"), "brand.json styles.caption.emoji_assets"),
434
+ (brand.get("emoji_assets"), "brand.json emoji_assets"),
435
+ (os.environ.get("FFMPEG_SKILL_EMOJI_ASSETS"), "FFMPEG_SKILL_EMOJI_ASSETS")):
436
+ if not value:
437
+ continue
438
+ if not os.path.isdir(str(value)):
439
+ die(f"{where}: {value} is not a readable directory -- {EMOJI_ASSET_HINT}", kind="input")
440
+ return str(value)
441
+ return None
442
+
443
+
444
+
445
+
446
+ def emoji_filter_chain(plan, base_label, out_label, first_input=1, to_yuv="", base_chain="", overlay_opts=""):
447
+ """(chains, inputs) that composite the planned PNGs on top of `base_label`.
448
+
449
+ `inputs` is a list of argv fragments, each ending in the asset path, to be appended to the
450
+ ffmpeg command in order (an overlay that fades needs `-loop 1` on its input so the still has
451
+ a timeline the fade filter can move along; one that does not is a plain `-i`).
452
+ `to_yuv` ends each PNG's chain: the caller's rgb_chain_to_bt709(meta), so the RGBA asset is
453
+ converted to the BT.709 the output is tagged with instead of by overlay's BT.601 default;
454
+ `base_chain` (label_chain(meta, meta): an untagged source's BT.709 label) goes in front of
455
+ the first overlay, so 7.1+ does not convert the two pictures to one another.
456
+ `overlay_opts` ends each overlay's options: the caller's overlay_format(meta), so a 10-bit
457
+ picture is not composited at overlay's 8-bit default.
458
+ """
459
+ overlays = plan.get("overlays") or []
460
+ if not overlays:
461
+ return [], []
462
+ # Group by everything that makes two uses of the same PNG a different STREAM: the fade is
463
+ # expressed in the cue's own timeline, so two cues cannot share one faded input.
464
+ def _key(o):
465
+ fades = (round(float(o.get("fade_in") or 0.0), 3), round(float(o.get("fade_out") or 0.0), 3))
466
+ window = (round(float(o["start"]), 3), round(float(o["end"]), 3)) if any(fades) else (None, None)
467
+ return (o["asset"], o["box"]) + fades + window
468
+
469
+ groups: "List[Tuple]" = []
470
+ for o in overlays:
471
+ if _key(o) not in groups:
472
+ groups.append(_key(o))
473
+ chains: List[str] = []
474
+ inputs: "List[List[str]]" = []
475
+ pads: "Dict[Tuple, List[str]]" = {}
476
+ for k, key in enumerate(groups):
477
+ asset, box, fin, fout, gstart, gend = key
478
+ uses = [o for o in overlays if _key(o) == key]
479
+ idx = first_input + k
480
+ labels = [f"e{k}_{j}" for j in range(len(uses))]
481
+ chain = f"[{idx}:v]format=rgba,scale={box}:{box}"
482
+ if fin or fout:
483
+ # -loop 1 gives the still an advancing timeline on the SAME clock as the main video,
484
+ # so the fade times below are the cue's own seconds. The emoji then appears and
485
+ # leaves with the text instead of popping in against a fading line.
486
+ # -t bounds the loop at the cue's end: an unbounded looped still never EOFs and the
487
+ # whole encode hangs (overlay keeps pulling from it after the main video is done).
488
+ inputs.append(["-loop", "1", "-t", f"{gend:.3f}", "-i", asset])
489
+ if fin:
490
+ chain += f",fade=t=in:st={gstart:.3f}:d={fin:.3f}:alpha=1"
491
+ if fout:
492
+ chain += f",fade=t=out:st={max(gstart, gend - fout):.3f}:d={fout:.3f}:alpha=1"
493
+ else:
494
+ inputs.append(["-i", asset])
495
+ chain += to_yuv
496
+ if len(labels) > 1:
497
+ chain += f",split={len(labels)}"
498
+ chains.append(chain + "".join(f"[{l}]" for l in labels))
499
+ pads[key] = labels
500
+ cur = base_label
501
+ if base_chain:
502
+ chains.append(f"[{cur}]{base_chain}null[ebase]")
503
+ cur = "ebase"
504
+ remaining = {key: list(v) for key, v in pads.items()}
505
+ for j, o in enumerate(overlays):
506
+ label = remaining[_key(o)].pop(0)
507
+ nxt = out_label if j == len(overlays) - 1 else f"eov{j}"
508
+ x = o["x"]
509
+ x = f"'{x}'" if isinstance(x, str) else x
510
+ # No eof_action=pass here: a PNG input is a SINGLE frame at pts 0, and eof_action=pass
511
+ # switches off overlay's default "hold the last frame of the secondary input", so the
512
+ # asset would be composited on frame 0 only and vanish for the rest of the cue (that is
513
+ # exactly what shipped first). eof_action=repeat (the default) holds the still for the
514
+ # whole timeline; enable= is what confines it to the cue's window.
515
+ chains.append(f"[{cur}][{label}]overlay=x={x}:y={o['y']}:"
516
+ f"enable='between(t,{o['start']:.3f},{o['end']:.3f})'{overlay_opts}[{nxt}]")
517
+ cur = nxt
518
+ return chains, inputs