@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,414 @@
1
+ #!/usr/bin/env python3
2
+ """Multicam: align two or more cameras (and an optional external recorder) by
3
+ audio, then cut between them from a simple switch list.
4
+
5
+ All sources are aligned to the FIRST input (the reference) using the same
6
+ cross-correlation as sync.py. The output takes video from whichever camera the
7
+ switch list names for each time range (reference timeline), and audio from the
8
+ reference unless --audio picks another source.
9
+
10
+ Switch list format: "START-END:CAM,START-END:CAM,..." with times on the
11
+ reference timeline (seconds or mm:ss) and CAM = input index (0 = reference).
12
+ Gaps fall back to camera 0.
13
+
14
+ Each camera's `confidence` (in the report, and warned on stderr below 0.1)
15
+ is how well its audio matched the reference's, not a guarantee the cut lands
16
+ in sync: a source with no shared audio event (music-only vs. a silent room,
17
+ or two rooms recording different conversations) can score low and still get
18
+ an offset applied. Check it before trusting a low-confidence multicam edit.
19
+ This aligns audio tracks to each other, the same as sync.py, and does not
20
+ check lip sync (mouth movement vs. audio) at all -- see sync.py's docstring.
21
+
22
+ Examples:
23
+ python3 multicam.py camA.mp4 camB.mp4 --offsets-only # just report the offsets
24
+ python3 multicam.py camA.mp4 camB.mp4 --switch "0-12:0,12-30:1,30-45:0" -o edit.mp4
25
+ python3 multicam.py camA.mp4 camB.mp4 recorder.wav --audio 2 --switch "0-20:0,20-40:1" --fix-drift
26
+ python3 multicam.py camA.mp4 camB.mp4 --auto 8 -o edit.mp4 # alternate cameras every 8 s
27
+ """
28
+ import argparse
29
+ import json
30
+ import math
31
+ import os
32
+ import sys
33
+ from typing import Dict, List, Optional, Tuple
34
+
35
+ from _common import guard_sidecar, mix_color_chains, video_args, aac_args, add_common, apply_common, default_output, die, emit, ffmpeg_base, info, time_arg, probe, run, X264_PRESETS, fmt_secs, decode_pcm_mono, rms_envelope, STATE
36
+ from _common.emit import note, record_fallback, record_skip, warn
37
+ from _common.decision import av_trim, conform_output_t, conform_to_length, rebase_project_paths
38
+ from _common.probe import display_size, square_pixels, square_pixels_note
39
+ from _common.emit import input_length
40
+ from sync import measure_offset
41
+
42
+ ENERGY_WINDOW_S = 0.25 # --switch energy: loudness measured over this window on the reference timeline
43
+ ENERGY_RATE = 8000 # decode rate for the per-camera loudness envelope
44
+
45
+
46
+ def parse_switch(spec: str, n: int) -> List[Tuple[float, float, int]]:
47
+ out = []
48
+ for raw in spec.split(","):
49
+ raw = raw.strip()
50
+ if not raw:
51
+ continue
52
+ try:
53
+ rng, cam = raw.rsplit(":", 1)
54
+ a, b = rng.rsplit("-", 1)
55
+ c = int(cam)
56
+ except ValueError:
57
+ die(f"bad switch entry '{raw}' (want START-END:CAM)")
58
+ s, e = time_arg(a, f"--switch {raw!r} start"), time_arg(b, f"--switch {raw!r} end")
59
+ if not 0 <= c < n:
60
+ die(f"camera {c} does not exist (inputs are 0..{n - 1})")
61
+ if e <= s:
62
+ die(f"switch entry '{raw}': end must be after start")
63
+ if round(e, 3) <= round(s, 3):
64
+ # the cut list (--edl, `cuts`) is written to the millisecond: this range was its
65
+ # "0.000-0.000", a line cut.py --segments refuses (the scenes.py --edl sibling)
66
+ die(f"switch entry '{raw}': shorter than a millisecond, the precision the cut list is written in",
67
+ kind="input")
68
+ out.append((s, e, c))
69
+ out.sort()
70
+ # A132: ranges on one timeline cannot overlap. The fill below kept both, so the picture of the
71
+ # overlap played twice while the sound played once, and every later cut ran behind it
72
+ for (s0, e0, _c0), (s1, e1, _c1) in zip(out, out[1:]):
73
+ if s1 < e0:
74
+ die(f"--switch ranges overlap: {fmt_secs(s0)}-{fmt_secs(e0)} and {fmt_secs(s1)}-{fmt_secs(e1)} "
75
+ "(on the reference timeline each moment has one camera)", kind="input")
76
+ return out
77
+
78
+
79
+ def energy_switch(inputs: List[str], metas: List["Dict"], offsets: List[float], ratios: List[float],
80
+ ref_dur: float, min_shot: float, window_s: float = ENERGY_WINDOW_S) -> List[Tuple[float, float, int]]:
81
+ """Auto-switch cuts: at every `window_s` step on the reference timeline, cut to whichever
82
+ camera (of those WITH video) measures the loudest audio at that moment, then merge the
83
+ winners into runs and fold any run shorter than `min_shot` into its neighbour. This is a
84
+ measured loudest-camera pick, the same spirit as scenes.py --rank-by audio: it is a proxy for
85
+ "who is talking", not a judgement -- a loud crowd or a camera with a hot mic wins over a
86
+ quiet subject exactly like scenes.py's own audio ranking does."""
87
+ candidates = [c for c, m in enumerate(metas) if m.get("video")]
88
+ if not candidates:
89
+ die("no input has video; --switch energy needs at least one camera with a picture")
90
+ envs: "Dict[int, List[float]]" = {}
91
+ step = max(1, int(ENERGY_RATE * window_s))
92
+ for c in candidates:
93
+ samples = decode_pcm_mono(inputs[c], ENERGY_RATE, check=False)
94
+ envs[c] = rms_envelope(samples, step) if samples else []
95
+ n_windows = max(1, int(math.ceil(ref_dur / window_s)))
96
+ winners: List[int] = []
97
+ for i in range(n_windows):
98
+ t = i * window_s
99
+ best_c, best_v = candidates[0], -1.0
100
+ for c in candidates:
101
+ src_t = (t - offsets[c]) * ratios[c]
102
+ idx = int(src_t / window_s)
103
+ env = envs[c]
104
+ val = env[idx] if 0 <= idx < len(env) else -1.0
105
+ if val > best_v:
106
+ best_v, best_c = val, c
107
+ winners.append(best_c)
108
+ # collapse into runs
109
+ runs: List[List] = []
110
+ for i, c in enumerate(winners):
111
+ t0, t1 = i * window_s, min(ref_dur, (i + 1) * window_s)
112
+ if runs and runs[-1][2] == c:
113
+ runs[-1][1] = t1
114
+ else:
115
+ runs.append([t0, t1, c])
116
+ # fold a run shorter than min_shot into its neighbour: the next run if there is one, else the
117
+ # previous one -- a single pass is enough because folding only ever lengthens a run, and a
118
+ # run just extended is re-checked on the next iteration through the while loop.
119
+ changed = True
120
+ while changed and len(runs) > 1:
121
+ changed = False
122
+ for i, r in enumerate(runs):
123
+ if r[1] - r[0] < min_shot:
124
+ if i + 1 < len(runs):
125
+ runs[i + 1][0] = r[0]
126
+ else:
127
+ runs[i - 1][1] = r[1]
128
+ del runs[i]
129
+ changed = True
130
+ break
131
+ return [(s, e, c) for s, e, c in runs]
132
+
133
+
134
+ def main() -> int:
135
+ ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
136
+ ap.add_argument("inputs", nargs="+", help="reference camera first, then other cameras / recorders")
137
+ ap.add_argument("-o", "--output", help="output file (default: <reference>_multicam.mp4)")
138
+ ap.add_argument("--switch", help="switch list START-END:CAM,... on the reference timeline, or "
139
+ "the literal 'energy' to auto-switch to whichever camera is "
140
+ "loudest at each moment (respecting --min-shot)")
141
+ ap.add_argument("--auto", type=float, help="no switch list: alternate through the cameras every N seconds")
142
+ ap.add_argument("--min-shot", type=float, default=1.5,
143
+ help="--switch energy: never cut to a new camera for less than this many "
144
+ "seconds (default 1.5)")
145
+ ap.add_argument("--edl", help="write the resulting cut list to this file, one START-END per line "
146
+ "(cut.py --segments format); the camera index for each cut is in "
147
+ "the JSON `cuts` field alongside it")
148
+ ap.add_argument("--write-project", help="also write a render.py-compatible project JSON to this "
149
+ "file, reproducing the exact same cut decision: one "
150
+ "clips[] entry per cut, naming that cut's own camera "
151
+ "file with in/out on THAT camera's timeline (the "
152
+ "reference cut shifted by its measured offset). Running "
153
+ "render.py on it reproduces this same edit; the combined "
154
+ "output above is still written as usual.")
155
+ ap.add_argument("--audio", type=int, default=0, help="input index to take audio from (default 0 = reference)")
156
+ ap.add_argument("--offsets-only", action="store_true", help="print the measured offsets and exit")
157
+ ap.add_argument("--max-offset", type=float, default=30.0, help="largest offset to search in seconds (default 30)")
158
+ ap.add_argument("--analyze-seconds", type=float, default=120.0, help="how much audio to analyse from each file (default 120, at most 900)")
159
+ ap.add_argument("--fix-drift", action="store_true", help="also correct clock drift of each source (long recordings)")
160
+ ap.add_argument("--width", type=int, help="output width (default: reference)")
161
+ ap.add_argument("--height", type=int, help="output height (default: reference)")
162
+ ap.add_argument("--fps", type=float, help="output fps (default: reference)")
163
+ ap.set_defaults(crf=18) # --quality's default (the --crf alias was removed in 2.0)
164
+ ap.add_argument("--preset", default="medium", choices=X264_PRESETS, help="x264 preset")
165
+ add_common(ap)
166
+ args = ap.parse_args()
167
+ apply_common(args)
168
+ if not args.offsets_only: # an offsets-only run writes nothing
169
+ media_out = args.output or default_output(args.inputs[0], "multicam", "mp4")
170
+ guard_sidecar(args.edl, *args.inputs, siblings=(args.write_project, media_out))
171
+ guard_sidecar(args.write_project, *args.inputs, siblings=(media_out,))
172
+ if args.edl or args.write_project: # refused up front with them, before any decode
173
+ guard_sidecar(media_out, *args.inputs)
174
+ if args.analyze_seconds > 900:
175
+ die(f"--analyze-seconds {args.analyze_seconds:g}: the window is decoded into memory; 900 s is the ceiling")
176
+ if args.fps is not None and args.fps <= 0:
177
+ die(f"--fps must be positive, got {args.fps:g}")
178
+ if not 0 <= args.audio < len(args.inputs):
179
+ die(f"--audio {args.audio}: inputs are numbered 0..{len(args.inputs) - 1}")
180
+
181
+ n = len(args.inputs)
182
+ if n < 2:
183
+ die("give at least two inputs")
184
+ metas = [probe(p) for p in args.inputs]
185
+ for p, m in zip(args.inputs, metas):
186
+ if not m.get("audio"):
187
+ die(f"{p} has no audio to align with")
188
+ if not metas[0].get("video"):
189
+ die("the reference (first input) must have video")
190
+
191
+ offsets = [0.0]
192
+ ratios = [1.0]
193
+ conf = [1.0]
194
+ # A131: per camera, why --fix-drift measured no drift (too_short / low_confidence, as sync.py
195
+ # says it); None when it was measured, and for the reference, which is the clock (0 by definition)
196
+ drift_skipped: List[object] = [None]
197
+ for p in args.inputs[1:]:
198
+ off, score = measure_offset(args.inputs[0], p, 0.0, args.analyze_seconds, 20.0, args.max_offset, 1.0)
199
+ ratio = 1.0
200
+ skipped_reason = None
201
+ if args.fix_drift:
202
+ ref_dur = input_length(metas[0])
203
+ sec_dur = input_length(probe(p))
204
+ overlap_end = min(ref_dur, sec_dur + off)
205
+ window = 60.0
206
+ head_len = min(args.analyze_seconds, overlap_end)
207
+ tail_start = overlap_end - window
208
+ if tail_start <= head_len / 2 + 5:
209
+ skipped_reason = "too_short"
210
+ record_skip(f"{p} too short to measure drift reliably; skipping drift correction", "drift_correction_skipped",
211
+ path=p, reason=skipped_reason, overlap_seconds=round(overlap_end, 3), drift_window=window)
212
+ else:
213
+ ref_start, sec_start = tail_start, tail_start - off
214
+ if sec_start < 0:
215
+ ref_start -= sec_start
216
+ sec_start = 0.0
217
+ from sync import decode_mono, envelope, cross_correlate, refine, SR
218
+ ref_s = decode_mono(args.inputs[0], window, ref_start)
219
+ oth_s = decode_mono(p, window, sec_start)
220
+ step = int(SR * 0.02)
221
+ lag, sc = cross_correlate(envelope(ref_s, step), envelope(oth_s, step), int(2.0 * SR / step))
222
+ residual = refine(ref_s, oth_s, lag * step / SR, int(SR * 0.001), 0.04)
223
+ elapsed = (ref_start + window / 2) - head_len / 2
224
+ if elapsed > 0 and sc > 0.1:
225
+ ratio = 1.0 - residual / elapsed
226
+ off = off + (ratio - 1.0) * (head_len / 2)
227
+ else:
228
+ skipped_reason = "low_confidence"
229
+ record_skip(f"could not measure drift with confidence for {p}; skipping drift correction",
230
+ "drift_correction_skipped", path=p, reason=skipped_reason,
231
+ confidence=round(max(0.0, sc), 3), measured_over_seconds=round(elapsed, 2))
232
+ drift_skipped.append(skipped_reason)
233
+ offsets.append(off)
234
+ ratios.append(ratio)
235
+ conf.append(score)
236
+ info(f"{p}: offset {off:+.3f}s (confidence {score:.2f})"
237
+ + (f", drift {(ratio - 1) * 1e6:+.0f} ppm" if args.fix_drift and not skipped_reason else
238
+ f", drift not measured ({skipped_reason})" if args.fix_drift else ""))
239
+ if score < 0.1:
240
+ warn(f"{p} has low correlation confidence ({score:.2f}); check that it shares an audio event with the reference before "
241
+ "trusting this offset", "sync_low_confidence", path=p, confidence=round(score, 3))
242
+
243
+ report = {"inputs": args.inputs, "offsets_seconds": [round(o, 4) for o in offsets],
244
+ "confidence": [round(c, 3) for c in conf]}
245
+ if args.fix_drift:
246
+ report["drift_ppm"] = [None if why else round((r - 1) * 1e6, 1) for r, why in zip(ratios, drift_skipped)]
247
+ report["drift_skipped_reason"] = drift_skipped
248
+ if args.offsets_only:
249
+ emit(None, **report)
250
+ if not args.json:
251
+ for p, o, c in zip(args.inputs, offsets, conf):
252
+ print(f"{p}: {o:+.3f}s (confidence {c:.2f})")
253
+ return 0
254
+
255
+ if args.min_shot <= 0:
256
+ die(f"--min-shot must be positive, got {args.min_shot:g}")
257
+ ref_dur = input_length(metas[0])
258
+ energy_mode = args.switch == "energy"
259
+ if energy_mode:
260
+ cuts = energy_switch(args.inputs, metas, offsets, ratios, ref_dur, args.min_shot)
261
+ elif args.switch:
262
+ cuts = parse_switch(args.switch, n)
263
+ elif args.auto:
264
+ if args.auto <= 0:
265
+ die(f"--auto must be a positive number of seconds, got {args.auto:g}")
266
+ cams = [i for i, m in enumerate(metas) if m.get("video")]
267
+ cuts, t, k = [], 0.0, 0
268
+ while t < ref_dur:
269
+ cuts.append((t, min(ref_dur, t + args.auto), cams[k % len(cams)]))
270
+ t += args.auto
271
+ k += 1
272
+ else:
273
+ die("give --switch or --auto (or --offsets-only)")
274
+ # fill gaps with camera 0 and clip to the reference length
275
+ filled: List[Tuple[float, float, int]] = []
276
+ cursor = 0.0
277
+ for s, e, c in cuts:
278
+ s, e = max(0.0, s), min(ref_dur, e)
279
+ if s > cursor:
280
+ filled.append((cursor, s, 0))
281
+ if e > s:
282
+ filled.append((s, e, c))
283
+ cursor = max(cursor, e)
284
+ if cursor < ref_dur:
285
+ filled.append((cursor, ref_dur, 0))
286
+ # a gap or a clipped range under a millisecond is nothing at the precision the cut list is
287
+ # written in (--switch "0.0004-3:1" left a leading "0.000-0.000", the line cut.py --segments
288
+ # refuses, and a 0.4 ms trim in the render): its neighbour takes it, so the timeline stays whole
289
+ whole: List[Tuple[float, float, int]] = []
290
+ carry: Optional[float] = None
291
+ for s, e, c in filled:
292
+ if carry is not None:
293
+ s, carry = carry, None
294
+ if round(e, 3) <= round(s, 3):
295
+ if whole:
296
+ whole[-1] = (whole[-1][0], e, whole[-1][2])
297
+ else:
298
+ carry = s
299
+ continue
300
+ whole.append((s, e, c))
301
+ filled = whole
302
+ for s, e, c in filled:
303
+ if not metas[c].get("video"):
304
+ die(f"camera {c} ({args.inputs[c]}) has no video; it can only be used with --audio")
305
+
306
+ v0 = metas[0]["video"]
307
+ # camera 0's displayed frame: rotation applied, non-square pixels squared (#411)
308
+ w, h = args.width or display_size(v0)[0], args.height or display_size(v0)[1]
309
+ fps = args.fps or v0.get("fps") or 30.0
310
+ fps = round(fps) if abs(fps - round(fps)) < 0.02 else fps
311
+ pixfmt = "yuv420p10le" if v0.get("bt2020_or_hdr") else "yuv420p"
312
+ geo = f"scale={w}:{h}:force_original_aspect_ratio=decrease,pad={w}:{h}:(ow-iw)/2:(oh-ih)/2,setsar=1,fps={fps:g},format={pixfmt}"
313
+
314
+ for p, m in zip(args.inputs, metas):
315
+ if square_pixels(m.get("video")):
316
+ note(square_pixels_note(m["video"], p))
317
+ cmd = ffmpeg_base()
318
+ for p in args.inputs:
319
+ cmd += ["-i", p]
320
+ parts: List[str] = []
321
+ labels: List[str] = []
322
+ project_clips: List[Dict] = []
323
+ convert = mix_color_chains(metas, metas[0])
324
+ # what is actually rendered: a range whose camera has not started yet plays camera 0, and the
325
+ # result says so (`cuts` names the camera on screen, diagnostics.fallbacks the one asked for)
326
+ rendered: List[Tuple[float, float, int]] = []
327
+ for i, (s, e, c) in enumerate(filled):
328
+ # reference time t maps to source time (t - offset_c) * ratio_c
329
+ src_s = (s - offsets[c]) * ratios[c]
330
+ src_e = (e - offsets[c]) * ratios[c]
331
+ if src_s < 0:
332
+ record_fallback(f"camera {c} has not started at reference {s:.2f}s; using camera 0 for that range "
333
+ f"({s:.3f}-{e:.3f}s)", "camera_not_started", start=round(s, 3), end=round(e, 3),
334
+ requested_camera=c, camera=0, starts_at=round(offsets[c], 3))
335
+ c, src_s, src_e = 0, s, e
336
+ rendered.append((s, e, c))
337
+ sq = (square_pixels(metas[c]["video"]) + ",") if square_pixels(metas[c]["video"]) else ""
338
+ # A130: a drift-corrected camera's range is (e - s) * ratio of its own time; played at that
339
+ # rate it lasts e - s on the reference, as its sound does (asetrate) -- at its own rate the
340
+ # picture ran (ratio - 1) * (e - s) long and every later cut fell behind the sound
341
+ retime = f"(PTS-STARTPTS)/{ratios[c]:.9f}" if abs(ratios[c] - 1.0) > 1e-7 else "PTS-STARTPTS"
342
+ parts.append(f"[{c}:v]trim=start={src_s:.4f}:end={src_e:.4f},setpts={retime},{convert[c]}{sq}{geo}[v{i}]")
343
+ labels.append(f"[v{i}]")
344
+ clip = {"src": args.inputs[c], "in": round(src_s, 3), "out": round(src_e, 3)}
345
+ if abs(ratios[c] - 1.0) > 1e-7:
346
+ # render.py plays a clip at clips[].speed (its length / speed), as the retime above
347
+ # does: without it a drift-corrected camera's clip ran (ratio - 1) * (e - s) long
348
+ clip["speed"] = round(ratios[c], 9)
349
+ project_clips.append(clip)
350
+ parts.append("".join(labels) + f"concat=n={len(filled)}:v=1:a=0[vout]")
351
+ a = args.audio
352
+ a_start = -offsets[a] if offsets[a] < 0 else 0.0
353
+ # a_start is a trim point in the source's own, pre-drift-correction time axis, so it must be
354
+ # applied before asetrate/aresample rescale that axis -- otherwise the trim lands at the wrong
355
+ # point once the stream's timebase has already been stretched/compressed by the drift ratio
356
+ # (mirrors sync.py, which seeks with -ss, an input-level operation, before its drift_af filters).
357
+ # shifted by a_start, not to its own first sample: a sound that starts after its file's start
358
+ # keeps that offset (padded with silence), as the offset was measured on the file's clock (#409)
359
+ afx = [av_trim(a_start, None)[1]]
360
+ if abs(ratios[a] - 1.0) > 1e-7:
361
+ sr = metas[a]["audio"].get("sample_rate") or 48000
362
+ afx += [f"asetrate={sr * ratios[a]:.6f}", f"aresample={sr}"]
363
+ if offsets[a] > 0:
364
+ afx.append(f"adelay={int(round(offsets[a] * 1000))}:all=1")
365
+ # the sound ends with the reference, to the sample (#493), counted at the 48 kHz it is written
366
+ # in; `atrim=0:{:.3f}` and `-t {:.3f}` cut it to the millisecond. A dry run's pending reference
367
+ # has no length to count, and keeps the old filter.
368
+ conformed = ref_dur > 0
369
+ afx += [conform_to_length(ref_dur, 48000) if conformed else f"atrim=0:{ref_dur:.3f}",
370
+ "aformat=sample_rates=48000:channel_layouts=stereo"]
371
+ parts.append(f"[{a}:a]{','.join(afx)}[aout]")
372
+
373
+ output = args.output or default_output(args.inputs[0], "multicam", "mp4")
374
+ cmd += ["-filter_complex", ";".join(parts), "-map", "[vout]", "-map", "[aout]"]
375
+ cmd += video_args(metas[0], args.crf, args.preset, convert_matrix=False) + aac_args() + ["-t", conform_output_t(ref_dur, 48000) if conformed else f"{ref_dur:.3f}", output]
376
+
377
+ if args.write_project:
378
+ # Same cut decision as the combined render above (project_clips was built alongside the
379
+ # filter graph, from the same src_s/src_e/c after the camera-0 fallback), expressed as a
380
+ # render.py project instead of the direct render this tool already does -- additive, not
381
+ # a replacement: the combined output below is still written as usual.
382
+ project = {"output": default_output(args.inputs[0], "multicam_project", "mp4"),
383
+ "clips": project_clips,
384
+ # a switch is a cut: render.py's default is a 0.5 s crossfade at every join,
385
+ # which shortens the timeline by 0.5 s a switch and moves every later one
386
+ "transition": {"type": "none"}}
387
+ # the inputs are named as given, relative to the working directory, and render.py reads a
388
+ # project's relative paths against the project file's directory: written elsewhere
389
+ # (--write-project out/cut.json), they named files that are not there
390
+ project = rebase_project_paths(project, os.getcwd())
391
+
392
+ run(cmd)
393
+ # the EDL and the project record the cut: written once it exists, not before an encode that then
394
+ # failed (#462 A41, the silence.py --edl sibling)
395
+ if args.edl:
396
+ if not STATE.dry_run:
397
+ with open(args.edl, "w", encoding="utf-8") as fh:
398
+ for s, e, _c in filled:
399
+ fh.write(f"{s:.3f}-{e:.3f}\n")
400
+ info(f"wrote {args.edl}")
401
+ if args.write_project:
402
+ if not STATE.dry_run:
403
+ with open(args.write_project, "w", encoding="utf-8") as fh:
404
+ fh.write(json.dumps(project, indent=2) + "\n")
405
+ info(f"wrote {args.write_project}")
406
+ r = probe(output, role="output")
407
+ info(f"wrote {output} ({fmt_secs(r['duration'])}, {len(filled)} cuts, audio from input {a})")
408
+ extra = {"switch_mode": "energy", "min_shot": args.min_shot} if energy_mode else {}
409
+ emit(output, cuts=[[round(s, 3), round(e, 3), c] for s, e, c in rendered], **report, **extra)
410
+ return 0
411
+
412
+
413
+ if __name__ == "__main__":
414
+ sys.exit(main())