@clipen/clipen-cli 0.0.0-stage → 1.0.1

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 (232) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +89 -2
  3. package/apps/web/dist/assets/index-D5D2HiB1.js +14 -0
  4. package/apps/web/dist/assets/index-DIMuOXSu.css +1 -0
  5. package/apps/web/dist/favicon.svg +1 -0
  6. package/apps/web/dist/index.html +16 -0
  7. package/bin/clipen.js +157 -0
  8. package/clipen +18 -0
  9. package/install +25 -0
  10. package/package.json +55 -4
  11. package/pyproject.toml +44 -0
  12. package/requirements/asr-runtime.txt +13 -0
  13. package/requirements/dev.txt +2 -0
  14. package/requirements/runtime.txt +20 -0
  15. package/src/clipen/__init__.py +3 -0
  16. package/src/clipen/analysis/__init__.py +89 -0
  17. package/src/clipen/analysis/artifacts.py +410 -0
  18. package/src/clipen/analysis/audio.py +394 -0
  19. package/src/clipen/analysis/evidence.py +102 -0
  20. package/src/clipen/analysis/evidence_service.py +929 -0
  21. package/src/clipen/analysis/image_similarity.py +134 -0
  22. package/src/clipen/analysis/keyframes.py +159 -0
  23. package/src/clipen/analysis/models.py +228 -0
  24. package/src/clipen/analysis/qwen_worker.py +594 -0
  25. package/src/clipen/analysis/resources.py +22 -0
  26. package/src/clipen/analysis/runtime.py +62 -0
  27. package/src/clipen/analysis/service.py +594 -0
  28. package/src/clipen/analysis/setup.py +921 -0
  29. package/src/clipen/analysis/setup_cli.py +107 -0
  30. package/src/clipen/analysis/storage.py +1864 -0
  31. package/src/clipen/analysis/transcription.py +906 -0
  32. package/src/clipen/analysis/visual.py +237 -0
  33. package/src/clipen/annotations/__init__.py +13 -0
  34. package/src/clipen/annotations/models.py +22 -0
  35. package/src/clipen/annotations/storage.py +428 -0
  36. package/src/clipen/annotations/suggestions.py +115 -0
  37. package/src/clipen/asr_release.py +132 -0
  38. package/src/clipen/bootstrap.py +978 -0
  39. package/src/clipen/candidates.py +222 -0
  40. package/src/clipen/cli.py +84 -0
  41. package/src/clipen/controller/__init__.py +17 -0
  42. package/src/clipen/controller/app.py +1657 -0
  43. package/src/clipen/controller/server.py +533 -0
  44. package/src/clipen/domain/__init__.py +30 -0
  45. package/src/clipen/domain/errors.py +5 -0
  46. package/src/clipen/domain/media_time.py +110 -0
  47. package/src/clipen/domain/timeline.py +582 -0
  48. package/src/clipen/domain/validation.py +14 -0
  49. package/src/clipen/editing/EDITORIAL_REGRESSIONS.md +38 -0
  50. package/src/clipen/editing/PROGRAM_FORMAT.md +102 -0
  51. package/src/clipen/editing/README.md +115 -0
  52. package/src/clipen/editing/REFACTOR_DESIGN.md +241 -0
  53. package/src/clipen/editing/REFACTOR_HANDOFF.md +73 -0
  54. package/src/clipen/editing/__init__.py +15 -0
  55. package/src/clipen/editing/agent.py +13 -0
  56. package/src/clipen/editing/agent_models.py +127 -0
  57. package/src/clipen/editing/agent_repository.py +978 -0
  58. package/src/clipen/editing/agent_tools.py +613 -0
  59. package/src/clipen/editing/alignment.py +150 -0
  60. package/src/clipen/editing/alignment_setup.py +156 -0
  61. package/src/clipen/editing/alignment_worker.py +24 -0
  62. package/src/clipen/editing/change_report.py +128 -0
  63. package/src/clipen/editing/compiler.py +40 -0
  64. package/src/clipen/editing/component_looks.py +131 -0
  65. package/src/clipen/editing/component_review.py +74 -0
  66. package/src/clipen/editing/coordinator.py +497 -0
  67. package/src/clipen/editing/editorial_review.py +309 -0
  68. package/src/clipen/editing/evidence_jobs.py +552 -0
  69. package/src/clipen/editing/history_changes.py +192 -0
  70. package/src/clipen/editing/music_choices.py +18 -0
  71. package/src/clipen/editing/production_catalog.py +629 -0
  72. package/src/clipen/editing/production_limits.py +85 -0
  73. package/src/clipen/editing/production_media.py +435 -0
  74. package/src/clipen/editing/production_preview.py +373 -0
  75. package/src/clipen/editing/production_progress.py +236 -0
  76. package/src/clipen/editing/production_requirements.py +117 -0
  77. package/src/clipen/editing/production_tools.py +1198 -0
  78. package/src/clipen/editing/program_audio.py +248 -0
  79. package/src/clipen/editing/program_direction.py +83 -0
  80. package/src/clipen/editing/program_story.py +91 -0
  81. package/src/clipen/editing/program_subtitles.py +232 -0
  82. package/src/clipen/editing/programme_review.py +121 -0
  83. package/src/clipen/editing/prompt_history.py +84 -0
  84. package/src/clipen/editing/recut.py +167 -0
  85. package/src/clipen/editing/refinement_references.py +278 -0
  86. package/src/clipen/editing/resolve_export.py +847 -0
  87. package/src/clipen/editing/resolve_titles.py +291 -0
  88. package/src/clipen/editing/skill_tools.py +951 -0
  89. package/src/clipen/editing/source_dialogue.py +192 -0
  90. package/src/clipen/editing/speech_coverage.py +50 -0
  91. package/src/clipen/editing/speech_quality.py +11 -0
  92. package/src/clipen/editing/tool_receipts.py +98 -0
  93. package/src/clipen/editing/versions.py +219 -0
  94. package/src/clipen/editing/visual_preview.py +189 -0
  95. package/src/clipen/editing/workbench.py +136 -0
  96. package/src/clipen/filesystem.py +25 -0
  97. package/src/clipen/finishing/README.md +103 -0
  98. package/src/clipen/finishing/__init__.py +1 -0
  99. package/src/clipen/finishing/audio.py +188 -0
  100. package/src/clipen/finishing/catalog.py +264 -0
  101. package/src/clipen/finishing/models.py +14 -0
  102. package/src/clipen/finishing/renderer.py +45 -0
  103. package/src/clipen/mcp_editing/__init__.py +5 -0
  104. package/src/clipen/mcp_editing/__main__.py +42 -0
  105. package/src/clipen/mcp_editing/server.py +396 -0
  106. package/src/clipen/media/__init__.py +50 -0
  107. package/src/clipen/media/discovery.py +253 -0
  108. package/src/clipen/media/models.py +349 -0
  109. package/src/clipen/media/preview.py +137 -0
  110. package/src/clipen/media/probe.py +418 -0
  111. package/src/clipen/media/service.py +304 -0
  112. package/src/clipen/media/storage.py +694 -0
  113. package/src/clipen/music_vocabulary.py +34 -0
  114. package/src/clipen/power.py +28 -0
  115. package/src/clipen/projects/__init__.py +26 -0
  116. package/src/clipen/projects/agent_schema.py +94 -0
  117. package/src/clipen/projects/annotation_schema.py +40 -0
  118. package/src/clipen/projects/deletion.py +256 -0
  119. package/src/clipen/projects/evidence_schema.py +52 -0
  120. package/src/clipen/projects/finishing_schema.py +36 -0
  121. package/src/clipen/projects/models.py +189 -0
  122. package/src/clipen/projects/picker.py +232 -0
  123. package/src/clipen/projects/preview_schema.py +29 -0
  124. package/src/clipen/projects/service.py +159 -0
  125. package/src/clipen/projects/storage.py +1458 -0
  126. package/src/clipen/projects/timeline_schema.py +32 -0
  127. package/src/clipen/projects/validation_schema.py +28 -0
  128. package/src/clipen/provider_registry.py +77 -0
  129. package/src/clipen/providers/__init__.py +43 -0
  130. package/src/clipen/providers/account.py +245 -0
  131. package/src/clipen/providers/claude.py +409 -0
  132. package/src/clipen/providers/claude_editing.py +118 -0
  133. package/src/clipen/providers/codex.py +991 -0
  134. package/src/clipen/providers/codex_editing.py +91 -0
  135. package/src/clipen/providers/editing_agent.py +567 -0
  136. package/src/clipen/providers/errors.py +51 -0
  137. package/src/clipen/providers/recovery.py +269 -0
  138. package/src/clipen/py.typed +1 -0
  139. package/src/clipen/rendering/__init__.py +12 -0
  140. package/src/clipen/rendering/cover.py +139 -0
  141. package/src/clipen/rendering/custom_components.py +328 -0
  142. package/src/clipen/rendering/custom_render.py +218 -0
  143. package/src/clipen/rendering/fonts/anton-OFL.txt +93 -0
  144. package/src/clipen/rendering/fonts/bebasneue-OFL.txt +93 -0
  145. package/src/clipen/rendering/fonts/caveat-OFL.txt +93 -0
  146. package/src/clipen/rendering/fonts/chenyu-OFL.txt +93 -0
  147. package/src/clipen/rendering/fonts/delagothicone-OFL.txt +93 -0
  148. package/src/clipen/rendering/fonts/hachimarupop-OFL.txt +93 -0
  149. package/src/clipen/rendering/fonts/iansui-OFL.txt +93 -0
  150. package/src/clipen/rendering/fonts/manifest.json +145 -0
  151. package/src/clipen/rendering/fonts/playfairdisplay-OFL.txt +93 -0
  152. package/src/clipen/rendering/fonts/rocknrollone-OFL.txt +93 -0
  153. package/src/clipen/rendering/fonts/yomogi-OFL.txt +94 -0
  154. package/src/clipen/rendering/fonts/yuseimagic-OFL.txt +93 -0
  155. package/src/clipen/rendering/fonts/zenkurenaido-OFL.txt +93 -0
  156. package/src/clipen/rendering/fonts/zenmarugothic-OFL.txt +93 -0
  157. package/src/clipen/rendering/production_effects.py +96 -0
  158. package/src/clipen/rendering/program_components.py +254 -0
  159. package/src/clipen/rendering/program_creator.py +804 -0
  160. package/src/clipen/rendering/program_identities.py +350 -0
  161. package/src/clipen/rendering/program_motion.py +186 -0
  162. package/src/clipen/rendering/program_studio.py +227 -0
  163. package/src/clipen/rendering/program_styles.py +321 -0
  164. package/src/clipen/rendering/program_subtitles.py +89 -0
  165. package/src/clipen/rendering/renderer.py +737 -0
  166. package/src/clipen/rendering/storage.py +230 -0
  167. package/src/clipen/rendering/titles.py +467 -0
  168. package/src/clipen/skills/__init__.py +5 -0
  169. package/src/clipen/skills/builtin/SKILL.md +72 -0
  170. package/src/clipen/skills/builtin/assets/sample-daily-vlog.mp4 +0 -0
  171. package/src/clipen/skills/builtin/assets/sample-event-recap.mp4 +0 -0
  172. package/src/clipen/skills/builtin/assets/sample-food-review.mp4 +0 -0
  173. package/src/clipen/skills/builtin/assets/sample-product-demo.mp4 +0 -0
  174. package/src/clipen/skills/builtin/assets/sample-product-review.mp4 +0 -0
  175. package/src/clipen/skills/builtin/assets/sample-product-unboxing.mp4 +0 -0
  176. package/src/clipen/skills/builtin/assets/sample-shorts-highlight.mp4 +0 -0
  177. package/src/clipen/skills/builtin/assets/sample-travel-highlight.mp4 +0 -0
  178. package/src/clipen/skills/builtin/assets/sample-travel-vlog.mp4 +0 -0
  179. package/src/clipen/skills/builtin/assets/style-cinema.png +0 -0
  180. package/src/clipen/skills/builtin/assets/style-editorial.png +0 -0
  181. package/src/clipen/skills/builtin/assets/style-tpl-daily-vlog.png +0 -0
  182. package/src/clipen/skills/builtin/assets/style-tpl-event-recap.png +0 -0
  183. package/src/clipen/skills/builtin/assets/style-tpl-food-review.png +0 -0
  184. package/src/clipen/skills/builtin/assets/style-tpl-product-demo.png +0 -0
  185. package/src/clipen/skills/builtin/assets/style-tpl-product-review.png +0 -0
  186. package/src/clipen/skills/builtin/assets/style-tpl-product-unboxing.png +0 -0
  187. package/src/clipen/skills/builtin/assets/style-tpl-shorts-highlight.png +0 -0
  188. package/src/clipen/skills/builtin/assets/style-tpl-travel-highlight.png +0 -0
  189. package/src/clipen/skills/builtin/assets/style-tpl-travel-vlog.png +0 -0
  190. package/src/clipen/skills/builtin/assets/style-variety.png +0 -0
  191. package/src/clipen/skills/builtin/components.json +133 -0
  192. package/src/clipen/skills/builtin/font_sources.json +20 -0
  193. package/src/clipen/skills/builtin/font_styles.json +329 -0
  194. package/src/clipen/skills/builtin/manifest.json +32 -0
  195. package/src/clipen/skills/builtin/presets.json +8 -0
  196. package/src/clipen/skills/builtin/references/captions.md +14 -0
  197. package/src/clipen/skills/builtin/references/channel-design.md +37 -0
  198. package/src/clipen/skills/builtin/references/editing.md +30 -0
  199. package/src/clipen/skills/builtin/references/font-chenyu-OFL.txt +93 -0
  200. package/src/clipen/skills/builtin/references/font-iansui-OFL.txt +93 -0
  201. package/src/clipen/skills/builtin/references/graphics.md +59 -0
  202. package/src/clipen/skills/builtin/references/review.md +16 -0
  203. package/src/clipen/skills/builtin/references/sound.md +8 -0
  204. package/src/clipen/skills/builtin/references/story.md +7 -0
  205. package/src/clipen/skills/builtin/skills/travel-program/SKILL.md +27 -0
  206. package/src/clipen/skills/builtin/skills/travel-program/manifest.json +6 -0
  207. package/src/clipen/skills/builtin/template-skills/clipen-daily-vlog/SKILL.md +33 -0
  208. package/src/clipen/skills/builtin/template-skills/clipen-daily-vlog/manifest.json +8 -0
  209. package/src/clipen/skills/builtin/template-skills/clipen-event-recap/SKILL.md +34 -0
  210. package/src/clipen/skills/builtin/template-skills/clipen-event-recap/manifest.json +8 -0
  211. package/src/clipen/skills/builtin/template-skills/clipen-food-review/SKILL.md +33 -0
  212. package/src/clipen/skills/builtin/template-skills/clipen-food-review/manifest.json +8 -0
  213. package/src/clipen/skills/builtin/template-skills/clipen-product-demo/SKILL.md +35 -0
  214. package/src/clipen/skills/builtin/template-skills/clipen-product-demo/manifest.json +8 -0
  215. package/src/clipen/skills/builtin/template-skills/clipen-product-review/SKILL.md +36 -0
  216. package/src/clipen/skills/builtin/template-skills/clipen-product-review/manifest.json +8 -0
  217. package/src/clipen/skills/builtin/template-skills/clipen-product-unboxing/SKILL.md +39 -0
  218. package/src/clipen/skills/builtin/template-skills/clipen-product-unboxing/manifest.json +8 -0
  219. package/src/clipen/skills/builtin/template-skills/clipen-shorts-highlight/SKILL.md +38 -0
  220. package/src/clipen/skills/builtin/template-skills/clipen-shorts-highlight/manifest.json +8 -0
  221. package/src/clipen/skills/builtin/template-skills/clipen-travel-highlight/SKILL.md +34 -0
  222. package/src/clipen/skills/builtin/template-skills/clipen-travel-highlight/manifest.json +8 -0
  223. package/src/clipen/skills/builtin/template-skills/clipen-travel-vlog/SKILL.md +37 -0
  224. package/src/clipen/skills/builtin/template-skills/clipen-travel-vlog/manifest.json +8 -0
  225. package/src/clipen/skills/builtin/templates.json +284 -0
  226. package/src/clipen/skills/builtin/visual_styles.json +1074 -0
  227. package/src/clipen/skills/catalog.py +314 -0
  228. package/src/clipen/skills/library.py +137 -0
  229. package/src/clipen/skills/package.py +254 -0
  230. package/src/clipen/skills/visual_styles.py +55 -0
  231. package/src/clipen/workspace.py +181 -0
  232. package/uninstall +25 -0
@@ -0,0 +1,93 @@
1
+ Copyright 2021 The Zen Maru Gothic Project Authors (https://github.com/googlefonts/zen-marugothic)
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ http://scripts.sil.org/OFL
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -0,0 +1,96 @@
1
+ """Trusted filter builders for timed masks, transitions, grade and camera sound."""
2
+
3
+ import math
4
+
5
+ from clipen.projects import ProjectError
6
+
7
+
8
+ def mosaic_filters(filters, label, item, timeline, index):
9
+ fps = timeline.frame_rate.numerator / timeline.frame_rate.denominator
10
+ regions = [r for e in item.effects if e.effect_id == "video.mosaic" for r in e.parameters["regions"]]
11
+ for n, r in enumerate(regions):
12
+ if not all(
13
+ isinstance(r[k], (int, float)) and not isinstance(r[k], bool) and math.isfinite(r[k])
14
+ for k in ("x", "y", "width", "height", "block_size", "start_frame", "duration_frames")
15
+ ):
16
+ raise ProjectError("agent_mosaic_invalid", "馬賽克參數必須是有限數字。", status_code=422)
17
+ if not (
18
+ 0 <= r["x"] < 1
19
+ and 0 <= r["y"] < 1
20
+ and 0 < r["width"] <= 1 - r["x"]
21
+ and 0 < r["height"] <= 1 - r["y"]
22
+ and 4 <= r["block_size"] <= 96
23
+ and 0 <= r["start_frame"] < item.duration_frames
24
+ and 0 < r["duration_frames"] <= item.duration_frames - r["start_frame"]
25
+ ):
26
+ raise ProjectError("agent_mosaic_invalid", "馬賽克區域或時間超出範圍。", status_code=422)
27
+ width = max(2, min(timeline.width, round(timeline.width * r["width"]) // 2 * 2))
28
+ height = max(2, min(timeline.height, round(timeline.height * r["height"]) // 2 * 2))
29
+ x = min(timeline.width - width, round(timeline.width * r["x"]) // 2 * 2)
30
+ y = min(timeline.height - height, round(timeline.height * r["y"]) // 2 * 2)
31
+ small_w = max(1, math.ceil(width / r["block_size"]))
32
+ small_h = max(1, math.ceil(height / r["block_size"]))
33
+ stem = f"mosaic{index}_{n}"
34
+ output = stem + "out"
35
+ filters.append(f"[{label}]split=2[{stem}base][{stem}crop]")
36
+ filters.append(
37
+ f"[{stem}crop]crop={width}:{height}:{x}:{y},scale={small_w}:{small_h}:flags=area,scale={width}:{height}:flags=neighbor[{stem}pixel]"
38
+ )
39
+ start = r["start_frame"] / fps
40
+ end = (r["start_frame"] + r["duration_frames"]) / fps
41
+ filters.append(
42
+ f"[{stem}base][{stem}pixel]overlay={x}:{y}:enable='gte(t,{start:.9f})*lt(t,{end:.9f})'[{output}]"
43
+ )
44
+ label = output
45
+ return label
46
+
47
+
48
+ def grade_filters(item):
49
+ grade = next((e.parameters for e in item.effects if e.effect_id == "video.grade"), None)
50
+ if grade is None:
51
+ return ""
52
+ values = (float(grade["contrast"]), float(grade["saturation"]), float(grade["brightness"]))
53
+ if not (0.5 <= values[0] <= 2 and 0 <= values[1] <= 2 and -0.3 <= values[2] <= 0.3):
54
+ raise ValueError("invalid grade")
55
+ return f",eq=contrast={values[0]:.6f}:saturation={values[1]:.6f}:brightness={values[2]:.6f}"
56
+
57
+
58
+ def transition_filters(item, following, timeline):
59
+ fps = timeline.frame_rate.numerator / timeline.frame_rate.denominator
60
+ incoming = next((e.parameters for e in item.effects if e.effect_id == "video.transition"), None)
61
+ outgoing = (
62
+ next((e.parameters for e in following.effects if e.effect_id == "video.transition"), None)
63
+ if following
64
+ else next((e.parameters for e in item.effects if e.effect_id == "video.transition_out"), None)
65
+ )
66
+ result = ""
67
+ for kind, p in (("in", incoming), ("out", outgoing)):
68
+ if p:
69
+ duration = p["duration_frames"] / fps / 2
70
+ start = 0 if kind == "in" else max(0, item.duration_frames / fps - duration)
71
+ color = "white" if p["kind"] == "dip_white" else "black"
72
+ result += f",fade=t={kind}:st={start:.9f}:d={duration:.9f}:color={color}"
73
+ fade = next((e.parameters for e in item.effects if e.effect_id == "video.fade"), None)
74
+ if fade:
75
+ for kind, key in (("in", "fade_in_frames"), ("out", "fade_out_frames")):
76
+ frames = fade[key]
77
+ if isinstance(frames, bool) or not isinstance(frames, int) or frames < 0:
78
+ raise ValueError("invalid fade")
79
+ if frames:
80
+ duration = frames / fps
81
+ start = 0 if kind == "in" else item.duration_frames / fps - duration
82
+ if start < 0:
83
+ raise ValueError("fade exceeds clip")
84
+ result += f",fade=t={kind}:st={start:.9f}:d={duration:.9f}:color=black"
85
+ return result
86
+
87
+
88
+ def camera_audio_filters(item):
89
+ policy = next((e.parameters for e in item.effects if e.effect_id == "audio.source"), None)
90
+ if policy is None:
91
+ return ""
92
+ gain = -120 if policy["mode"] == "mute" else policy["gain_db"]
93
+ result = f",volume={float(gain):.6f}dB"
94
+ if policy["mode"] == "dialogue":
95
+ result += ",highpass=f=85,lowpass=f=11000,acompressor=threshold=0.125:ratio=2"
96
+ return result
@@ -0,0 +1,254 @@
1
+ """Deterministic in-picture graphics for versioned programme skill packages."""
2
+
3
+ import math
4
+
5
+ from PIL import Image, ImageDraw
6
+
7
+ from . import custom_components, program_creator, program_identities
8
+ from .program_motion import FAMILIES, draw_motion_graphic, layout, motion_frames
9
+ from .program_styles import draw_styled_graphic, load_style_font, skin, style_font, styled_text_length, type_outline
10
+ from .titles import TitleRenderError
11
+
12
+
13
+ def animation_boundaries(item, profile, timeline=None):
14
+ if custom_components.is_custom(profile):
15
+ # A free design can change on any frame; the frames themselves say where.
16
+ return (
17
+ custom_components.changes(timeline, item, profile)
18
+ if timeline is not None
19
+ else set(range(item.start_frame, item.start_frame + item.duration_frames + 1))
20
+ )
21
+ motion = profile["presets"]["motion"]
22
+ if program_creator.is_creator(profile):
23
+ entry_length, exit_length = program_creator.frames(profile)
24
+ else:
25
+ entry_length, exit_length = (
26
+ motion_frames(profile["component_id"], profile)
27
+ if profile["component_id"] in FAMILIES
28
+ else (motion["entry_frames"], motion["exit_frames"])
29
+ )
30
+ entry = min(entry_length, item.duration_frames)
31
+ exit_frames = min(exit_length, item.duration_frames)
32
+ return {
33
+ item.start_frame + n
34
+ for n in (*range(entry + 1), *range(item.duration_frames - exit_frames, item.duration_frames + 1))
35
+ }
36
+
37
+
38
+ def _bounds(draw, font_path, timeline, item, profile):
39
+ if program_creator.is_creator(profile):
40
+ return program_creator.layout(draw, font_path, timeline, item, profile)
41
+ if program_identities.identity(profile):
42
+ return program_identities.layout(draw, font_path, timeline, item, profile)
43
+ if profile["component_id"] in FAMILIES:
44
+ return layout(draw, font_path, timeline, item, profile)
45
+ if skin(profile) == "studio":
46
+ from .program_studio import layout as studio_layout
47
+
48
+ return studio_layout(draw, font_path, timeline, item, profile)
49
+ font_path = style_font(font_path, profile)
50
+ typography = profile["presets"].get("typography", {})
51
+ scale = (
52
+ typography.get("reaction", 0.064)
53
+ if profile["component_id"] == "reaction"
54
+ else typography.get("component_primary", 0.038)
55
+ )
56
+ font = load_style_font(font_path, max(14, round(timeline.height * scale)), profile)
57
+ primary, _, detail = item.text.partition("\n")
58
+ detail_font = load_style_font(
59
+ font_path, max(12, round(timeline.height * typography.get("component_detail", 0.024))), profile, role="detail"
60
+ )
61
+ width = max(styled_text_length(primary, font), styled_text_length(detail, detail_font) if detail else 0)
62
+ pad = max(8, round(timeline.height * 0.016))
63
+ x, y = round(timeline.width * profile["x"]), round(timeline.height * profile["y"])
64
+ box_width = max(math.ceil(width) + pad * 2, round(timeline.width * 0.15))
65
+ box_height = round(timeline.height * scale * 1.65) + pad
66
+ if profile["component_id"] != "reaction":
67
+ box_height += round(timeline.height * 0.025)
68
+ if detail:
69
+ box_height += round(timeline.height * 0.038)
70
+ if (
71
+ box_width > timeline.width * 0.58
72
+ or x + box_width > timeline.width * 0.95
73
+ or y + box_height > timeline.height * 0.77
74
+ ):
75
+ raise TitleRenderError("program_component_overflow")
76
+ return (x, y, x + box_width, y + box_height), font, pad
77
+
78
+
79
+ def _draw(draw, font_path, timeline, item, profile, relative_frame=None):
80
+ if program_creator.is_creator(profile):
81
+ return program_creator.draw_graphic(draw, font_path, timeline, item, profile, relative_frame)
82
+ identity = program_identities.identity(profile)
83
+ if profile["component_id"] in FAMILIES and not identity:
84
+ return draw_motion_graphic(draw, font_path, timeline, item, profile, relative_frame)
85
+ bounds, font, pad = _bounds(draw, font_path, timeline, item, profile)
86
+ motion = profile["presets"]["motion"]
87
+ relative = motion["entry_frames"] if relative_frame is None else relative_frame
88
+ entering = min(1.0, max(0.0, (relative + 1) / motion["entry_frames"]))
89
+ leaving = min(1.0, (item.duration_frames - relative) / motion["exit_frames"])
90
+ opacity = min(entering, leaving)
91
+ eased = 1 - (1 - entering) ** 3
92
+ dx = round((1 - eased) * timeline.width * motion["entry_distance_ratio"])
93
+ x, y, right, bottom = bounds
94
+ x -= dx
95
+ right -= dx
96
+ palette = profile["presets"]["palette"]
97
+
98
+ def color(name):
99
+ r, g, b, a = palette[name]
100
+ return (r, g, b, round(a * opacity))
101
+
102
+ kind = profile["component_id"]
103
+ primary, _, detail = item.text.partition("\n")
104
+ stroke = max(2, round(timeline.height * 0.004))
105
+ if identity:
106
+ program_identities.draw_graphic(draw, font_path, timeline, item, profile, bounds, font, pad, relative_frame)
107
+ elif skin(profile) != "variety":
108
+ draw_styled_graphic(draw, font_path, timeline, item, profile, bounds, font, pad, relative_frame)
109
+ elif kind == "reaction":
110
+ draw.text(
111
+ (x + pad, y + pad // 2),
112
+ primary,
113
+ font=font,
114
+ fill=color("accent"),
115
+ stroke_width=type_outline(profile, font, stroke * 2),
116
+ stroke_fill=color("ink"),
117
+ )
118
+ if detail:
119
+ detail_font = load_style_font(font_path, max(12, round(timeline.height * 0.024)), profile, role="detail")
120
+ draw.text(
121
+ (x + pad, y + pad + round(timeline.height * 0.075)),
122
+ detail,
123
+ font=detail_font,
124
+ fill=color("paper"),
125
+ stroke_width=stroke,
126
+ stroke_fill=color("ink"),
127
+ )
128
+ # A short pair of ticks gives an actual reaction a shared programme
129
+ # accent without turning every dialogue line into a reaction graphic.
130
+ draw.line((x - pad // 2, y + pad, x - pad, y - pad // 2), fill=color("accent"), width=stroke)
131
+ draw.line((right + pad // 2, y + pad, right + pad, y - pad // 2), fill=color("accent"), width=stroke)
132
+ else:
133
+ # Narrow editorial labels sit inside the footage, with no full-screen
134
+ # background. A shared accent edge and typography form programme identity.
135
+ draw.rectangle((x + 3, y + 4, right + 3, bottom + 4), fill=(0, 0, 0, round(75 * opacity)))
136
+ draw.rectangle((x, y, right, bottom), fill=color("ink"))
137
+ draw.rectangle((x, y, x + stroke * 2, bottom), fill=color("secondary" if kind == "person" else "accent"))
138
+ typography = profile["presets"].get("typography", {})
139
+ kicker_font = load_style_font(
140
+ font_path,
141
+ max(10, round(timeline.height * typography.get("component_kicker", 0.017))),
142
+ profile,
143
+ role="detail",
144
+ )
145
+ kicker = (
146
+ profile.get("eyebrow")
147
+ or {"location": "現場", "person": "人物", "fact": "資訊", "pointer": "看這裡", "circle": "細節"}[kind]
148
+ )
149
+ draw.text(
150
+ (x + pad, y + pad // 2), kicker, font=kicker_font, fill=color("secondary" if kind == "person" else "accent")
151
+ )
152
+ primary_y = y + pad // 2 + round(timeline.height * 0.027)
153
+ draw.text((x + pad, primary_y), primary, font=font, fill=color("paper"))
154
+ if detail:
155
+ detail_font = load_style_font(
156
+ font_path,
157
+ max(12, round(timeline.height * typography.get("component_detail", 0.024))),
158
+ profile,
159
+ role="detail",
160
+ )
161
+ draw.text(
162
+ (x + pad, primary_y + round(timeline.height * 0.052)), detail, font=detail_font, fill=color("paper")
163
+ )
164
+ draw.line(
165
+ (x + pad, bottom - pad // 2, right - pad, bottom - pad // 2),
166
+ fill=color("accent"),
167
+ width=max(1, stroke // 2),
168
+ )
169
+ if kind not in {"pointer", "circle"}:
170
+ return bounds
171
+ target = profile["target"]
172
+ tx, ty = target["x"] * timeline.width, target["y"] * timeline.height
173
+ radius = target["radius"] * min(timeline.width, timeline.height)
174
+ if kind == "circle":
175
+ rect = (tx - radius, ty - radius, tx + radius, ty + radius)
176
+ draw.arc(rect, -90, -90 + max(2, round(360 * eased)), fill=color("accent"), width=stroke * 2)
177
+ else:
178
+ origin = (right, (y + bottom) / 2)
179
+ angle = math.atan2(ty - origin[1], tx - origin[0])
180
+ tip = (origin[0] + (tx - origin[0]) * eased, origin[1] + (ty - origin[1]) * eased)
181
+ draw.line((origin, tip), fill=color("ink"), width=stroke * 3)
182
+ draw.line((origin, tip), fill=color("accent"), width=stroke)
183
+ size = max(9, timeline.height * 0.025)
184
+ points = [
185
+ tip,
186
+ (tip[0] - size * math.cos(angle - 0.45), tip[1] - size * math.sin(angle - 0.45)),
187
+ (tip[0] - size * math.cos(angle + 0.45), tip[1] - size * math.sin(angle + 0.45)),
188
+ ]
189
+ draw.polygon(points, fill=color("accent"))
190
+ return bounds
191
+
192
+
193
+ class _Canvas:
194
+ """A timeline seen at another size, so every style's own proportions scale with it."""
195
+
196
+ def __init__(self, timeline, width, height):
197
+ self._timeline, self.width, self.height = timeline, width, height
198
+
199
+ def __getattr__(self, name):
200
+ return getattr(self._timeline, name)
201
+
202
+
203
+ def _scaled(timeline, profile):
204
+ """For a graphic a person resized: a larger or smaller canvas to draw it on, and where to place
205
+ that canvas so the graphic keeps its top-left corner. None at its designed size."""
206
+ scale = profile.get("scale", 1)
207
+ if scale == 1:
208
+ return None
209
+ canvas = _Canvas(timeline, max(2, round(timeline.width * scale)), max(2, round(timeline.height * scale)))
210
+ return canvas, (
211
+ round(timeline.width * profile["x"]) - round(canvas.width * profile["x"]),
212
+ round(timeline.height * profile["y"]) - round(canvas.height * profile["y"]),
213
+ )
214
+
215
+
216
+ def component_bounds(draw, font_path, timeline, item, profile):
217
+ """The graphic's box on the picture, after any size a person chose."""
218
+ if custom_components.is_custom(profile):
219
+ box = custom_components.bounds(timeline, item, profile)
220
+ dx, dy = round(profile.get("x", 0) * timeline.width), round(profile.get("y", 0) * timeline.height)
221
+ return (box or (dx, dy, dx, dy)), None, 0
222
+ scaled = _scaled(timeline, profile)
223
+ if scaled is None:
224
+ return _bounds(draw, font_path, timeline, item, profile)
225
+ canvas, (dx, dy) = scaled
226
+ (left, top, right, bottom), font, pad = _bounds(draw, font_path, canvas, item, profile)
227
+ box = (left + dx, top + dy, right + dx, bottom + dy)
228
+ # Enlarged, it must still clear the picture's edge and the subtitles at the bottom.
229
+ if box[0] < 0 or box[1] < 0 or box[2] > timeline.width * 0.97 or box[3] > timeline.height * 0.8:
230
+ raise TitleRenderError("program_component_overflow")
231
+ return box, font, pad
232
+
233
+
234
+ def draw_program_component(draw, font_path, timeline, item, profile, relative_frame=None):
235
+ if custom_components.is_custom(profile):
236
+ return custom_components.draw(draw, timeline, item, profile, relative_frame)
237
+ scaled = _scaled(timeline, profile)
238
+ if scaled is None:
239
+ return _draw(draw, font_path, timeline, item, profile, relative_frame)
240
+ canvas, (dx, dy) = scaled
241
+ component_bounds(draw, font_path, timeline, item, profile)
242
+ # Drawn at its new size on a canvas of its own, so type stays sharp instead of being resampled.
243
+ layer = Image.new("RGBA", (canvas.width, canvas.height), (0, 0, 0, 0))
244
+ result = _draw(ImageDraw.Draw(layer), font_path, canvas, item, profile, relative_frame)
245
+ target = draw._image
246
+ sx, sy, tx, ty = max(0, -dx), max(0, -dy), max(0, dx), max(0, dy)
247
+ width, height = min(layer.width - sx, target.width - tx), min(layer.height - sy, target.height - ty)
248
+ if width > 0 and height > 0:
249
+ piece = layer.crop((sx, sy, sx + width, sy + height))
250
+ if target.mode == "RGBA":
251
+ target.alpha_composite(piece, (tx, ty))
252
+ else:
253
+ target.paste(piece, (tx, ty), piece)
254
+ return result