@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,285 @@
1
+ #!/usr/bin/env python3
2
+ """Turn a numbered image sequence into a video.
3
+
4
+ --pattern accepts either a printf-style numbered pattern (`frame_%04d.png`,
5
+ resolved relative to --dir) or a glob (`*.png`, matched and sorted
6
+ in natural name order) -- detected by whether the pattern contains a `%`. Either
7
+ way, the actual frame list is resolved and checked on disk before ffmpeg
8
+ runs (an empty match or a missing first frame is refused here, not
9
+ discovered from an opaque ffmpeg error), then fed to ffmpeg as an explicit
10
+ concat list -- not `-pattern_type glob`, which several real ffmpeg builds
11
+ (the Windows Chocolatey package, for one) compile without.
12
+
13
+ Examples:
14
+ python3 sequence.py --dir frames --pattern "frame_%04d.png" --fps 24 -o out.mp4
15
+ python3 sequence.py --dir frames --pattern "*.png" --fps 30 --start-number 1
16
+ """
17
+ import argparse
18
+ import hashlib
19
+ import json
20
+ import os
21
+ import re
22
+ import sys
23
+ import tempfile
24
+ from fractions import Fraction
25
+ from pathlib import Path
26
+
27
+ from _common import STATE, add_common, apply_common, default_output, die, emit, ffmpeg_base, fingerprint, info, probe, refuse_output_is_input, require_tool, run, video_args, X264_PRESETS, concat_list_line, fmt_secs
28
+ from _common.emit import note, refuse, warn
29
+ from _common.probe import display_size, square_pixels_note
30
+ from _common.runner import register_plan_input
31
+ from _common.timeline import TimelineError, exact_rate
32
+
33
+ SEQUENCE_PLAN_ENV = "FFMPEG_SKILL_REPLAY_SEQUENCE_FRAMES"
34
+
35
+
36
+ def even(n: float) -> int:
37
+ v = int(round(n))
38
+ return v if v % 2 == 0 else v + 1
39
+
40
+
41
+ def _concat_list_line(path: Path) -> str:
42
+ return concat_list_line(str(path))
43
+
44
+
45
+ def frame_durations(count: int, rate: Fraction) -> list:
46
+ """The concat-list duration of each of `count` frames at `rate`, in whole microseconds: frame
47
+ i lasts round(start(i+1)) - round(start(i)) with start(i) = i/rate, each position rounded
48
+ once, so the demuxer's running sum is frame i's exact start to within half a microsecond at
49
+ every frame (#474: 1/30 written 0.033333 fell 3.3e-7 s behind per frame, half a frame after
50
+ about 50,000 frames)."""
51
+ def at(i: int) -> int:
52
+ return round(i * 1_000_000 / rate)
53
+ return [at(i + 1) - at(i) for i in range(count)]
54
+
55
+
56
+ def concat_list(frames: list, rate: Fraction) -> str:
57
+ """The concat-demuxer list for `frames` (paths) shown one frame each at `rate`."""
58
+ lines = []
59
+ framerate = f"option framerate {rate.numerator}/{rate.denominator}"
60
+ for f, us in zip(frames, frame_durations(len(frames), rate)):
61
+ lines.append(_concat_list_line(f))
62
+ lines.append(framerate)
63
+ lines.append(f"duration {us // 1_000_000}.{us % 1_000_000:06d}")
64
+ lines.append(_concat_list_line(frames[-1])) # concat demuxer: last entry's duration is ignored, so repeat it
65
+ lines.append(framerate)
66
+ return "\n".join(lines)
67
+
68
+
69
+ def undecodable_frames(list_path: Path, frames: list, rate: Fraction) -> "list | None":
70
+ """The frames of the list that do not decode to a picture, in order; None when the check could
71
+ not be made (ffprobe failed). ffprobe decodes the same concat list the encode reads, so a frame
72
+ is what the encode would get: frame i is decoded at the i-th start the list gives it. Only the
73
+ first frame was probed, and a later one that was not an image (a text file named .png, a
74
+ truncated PNG) was left out by the decoder while the fps filter repeated its neighbour: the run
75
+ completed with that frame missing (#529)."""
76
+ proc = run([require_tool("ffprobe"), "-v", "error", "-f", "concat", "-safe", "0", "-i", str(list_path),
77
+ "-select_streams", "v:0", "-show_entries", "frame=best_effort_timestamp_time", "-of", "csv=p=0"],
78
+ quiet=True, check=False)
79
+ if proc.returncode != 0:
80
+ return None
81
+ decoded = set()
82
+ for line in proc.stdout.splitlines():
83
+ try:
84
+ decoded.add(round(float(line.strip().rstrip(",")) * rate))
85
+ except ValueError:
86
+ continue
87
+ if not decoded:
88
+ # the first frame was probed as an image, so it decodes: nothing read back is a check that
89
+ # did not happen, not every frame missing
90
+ return None
91
+ return [f for i, f in enumerate(frames) if i not in decoded]
92
+
93
+
94
+ def natural_key(name: str) -> list:
95
+ """img2 < img10: digit runs compare as numbers, the rest case-insensitively."""
96
+ return [int(t) if t.isdigit() else t.lower() for t in re.split(r"(\d+)", name)]
97
+
98
+
99
+ def _frames_after(directory: Path, pattern: str, index: int) -> list:
100
+ """Files in `directory` that match printf `pattern` with a number above `index`."""
101
+ m = re.search(r"%0?(\d*)d", pattern)
102
+ if not m:
103
+ return []
104
+ rx = re.compile("^" + re.escape(pattern[:m.start()]) + r"(\d+)" + re.escape(pattern[m.end():]) + "$")
105
+ found = []
106
+ for f in directory.iterdir():
107
+ hit = rx.match(f.name)
108
+ if hit and int(hit.group(1)) > index:
109
+ found.append((int(hit.group(1)), f))
110
+ return [f for _n, f in sorted(found)]
111
+
112
+
113
+ def argument_parser() -> argparse.ArgumentParser:
114
+ ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
115
+ ap.add_argument("--dir", required=True, help="directory containing the frames")
116
+ ap.add_argument("--pattern", required=True, help="printf pattern (frame_%%04d.png) or glob (*.png)")
117
+ ap.add_argument("-o", "--output", help="output file (default: <dir>_sequence.mp4)")
118
+ ap.add_argument("--fps", type=float, default=30.0, help="output frame rate, the framerate (default 30)")
119
+ ap.add_argument("--start-number", type=int, default=0, help="first frame index, for a printf pattern (default 0)")
120
+ ap.add_argument("--width", type=int, help="output width in px; with --height also given, both are used directly")
121
+ ap.add_argument("--height", type=int, help="output height in px; with --width also given, both are used directly")
122
+ ap.set_defaults(crf=18) # --quality's default (the --crf alias was removed in 2.0)
123
+ ap.add_argument("--preset", default="medium", choices=X264_PRESETS, help="x264 preset")
124
+ add_common(ap)
125
+ return ap
126
+
127
+
128
+ def frame_paths(directory: Path, pattern: str, start: int) -> "tuple[list[Path], int | None]":
129
+ """Select the frames the encoder sees. The next printf index marks the first gap."""
130
+ if "%" not in pattern:
131
+ # Natural order, with a deterministic tie-break for names like frame2 and frame02.
132
+ return sorted(directory.glob(pattern), key=lambda p: (natural_key(p.name), str(p))), None
133
+ frames = []
134
+ i = start
135
+ while (directory / (pattern % i)).exists():
136
+ frames.append(directory / (pattern % i))
137
+ i += 1
138
+ return frames, i
139
+
140
+
141
+ def frame_digest(records: list[dict]) -> str:
142
+ """Bind exact frame fingerprints in order with a compact value for the replay child."""
143
+ digest = hashlib.sha256()
144
+ for frame in records:
145
+ digest.update(json.dumps(frame, sort_keys=True).encode("ascii") + b"\n")
146
+ return digest.hexdigest()
147
+
148
+
149
+ def replay_frame_digest(argv: list[str]) -> "str | None":
150
+ """Check the current sequence without running a probe or an encode during replay's dry run."""
151
+ try:
152
+ args = argument_parser().parse_args(argv)
153
+ frames, _ = frame_paths(Path(args.dir), args.pattern, args.start_number)
154
+ paths = [f.resolve(strict=True) for f in frames]
155
+ return frame_digest([fingerprint(str(f), complete=True) for f in paths])
156
+ except (OSError, RuntimeError, TypeError, ValueError, SystemExit):
157
+ return None
158
+
159
+
160
+ def main() -> int:
161
+ args = argument_parser().parse_args()
162
+ apply_common(args)
163
+
164
+ if args.fps <= 0:
165
+ die("--fps must be > 0")
166
+ for flag, value in (("--width", args.width), ("--height", args.height)):
167
+ # A109: 0 read as "not given" and a negative size reached ffmpeg (kind ffmpeg)
168
+ if value is not None and value < 1:
169
+ die(f"{flag} must be a positive number of pixels, got {value}")
170
+ try:
171
+ rate = exact_rate(args.fps) # 29.97 is 30000/1001, as every other tool reads it
172
+ except TimelineError as exc:
173
+ die(f"--fps: {exc}")
174
+ directory = Path(args.dir)
175
+ expected = os.environ.get(SEQUENCE_PLAN_ENV)
176
+ if not directory.is_dir():
177
+ if expected:
178
+ refuse("input", "plan_inputs_changed", f"the planned frame directory is unavailable: {args.dir}")
179
+ die(f"--dir not found or not a directory: {args.dir}")
180
+ try:
181
+ frames, next_index = frame_paths(directory, args.pattern, args.start_number)
182
+ resolved = [f.resolve(strict=True) for f in frames]
183
+ for frame in resolved:
184
+ if not frame.is_file():
185
+ reason = "plan_inputs_changed" if expected else "media_path_not_a_file"
186
+ refuse("input", reason, f"{str(frame)!r} is not a regular image file", path=str(frame))
187
+ records = [fingerprint(str(f), complete=True) for f in resolved] if STATE.plan or expected else []
188
+ digest = frame_digest(records) if STATE.plan or expected else None
189
+ except (OSError, RuntimeError) as exc:
190
+ if expected:
191
+ refuse("input", "plan_inputs_changed", f"could not read the planned sequence: {exc}")
192
+ die(f"could not read the frame sequence: {exc}")
193
+ except (TypeError, ValueError):
194
+ die(f"bad frame pattern '{args.pattern}'")
195
+ if expected and digest != expected:
196
+ refuse("input", "plan_inputs_changed",
197
+ "the ordered sequence frames differ from what was planned; make a new plan",
198
+ expected_frame_digest=expected, actual_frame_digest=digest)
199
+ if next_index is None:
200
+ if not frames:
201
+ die(f"no files in {args.dir} match glob '{args.pattern}'")
202
+ info(f"found {len(frames)} frames matching '{args.pattern}'")
203
+ else:
204
+ if not frames:
205
+ die(f"first frame not found: {directory / (args.pattern % args.start_number)} (check --pattern / --start-number)")
206
+ info(f"found {len(frames)} consecutive frames from index {args.start_number}")
207
+ # 2.2.1: frames past a gap in the numbering (one render or export step that failed) used
208
+ # to be dropped silently, giving a shorter video; name the gap and what was left out
209
+ later = _frames_after(directory, args.pattern, next_index)
210
+ if later:
211
+ warn(f"frame {args.pattern % next_index} is missing; {len(later)} later frame(s) "
212
+ f"(from {later[0].name}) are NOT in the sequence -- fill the gap or rename them", "sequence_gap",
213
+ missing=args.pattern % next_index, frames_left_out=len(later), first_left_out=later[0].name)
214
+
215
+ # For --dir . or .., use the resolved name so the default is next to the frame folder.
216
+ named = directory if directory.name not in ("", ".", "..") else directory.resolve()
217
+ output = args.output or default_output(str(named).rstrip("/\\") or "sequence", "sequence", "mp4")
218
+ # Keep both the chosen entry names and their targets safe, including hard links.
219
+ sources = list(map(str, frames + resolved))
220
+ refuse_output_is_input(output, *sources)
221
+ if STATE.plan:
222
+ refuse_output_is_input(STATE.plan, *sources)
223
+ for frame in resolved:
224
+ register_plan_input(frame)
225
+ STATE.measured_plan_inputs.update((record["path"], record) for record in records)
226
+ STATE.sequence_frames_sha256 = digest
227
+
228
+ frame_meta = probe(str(resolved[0]))
229
+ if not frame_meta.get("video"):
230
+ die(f"{frames[0]} is not a readable image")
231
+ # the displayed frame: an EXIF rotation applied, non-square pixels squared (#411)
232
+ sw, sh = display_size(frame_meta["video"])
233
+ if square_pixels_note(frame_meta["video"], "the first frame"):
234
+ note(square_pixels_note(frame_meta["video"], "the first frame"))
235
+
236
+ if args.width and args.height:
237
+ out_w, out_h = even(args.width), even(args.height)
238
+ elif args.width:
239
+ out_w = even(args.width)
240
+ out_h = even(out_w * sh / sw)
241
+ elif args.height:
242
+ out_h = even(args.height)
243
+ out_w = even(out_h * sw / sh)
244
+ else:
245
+ out_w, out_h = even(sw), even(sh)
246
+
247
+ with tempfile.TemporaryDirectory(prefix="ffmpeg-skill-sequence-") as tmp:
248
+ list_path = Path(tmp) / "frames.txt"
249
+ if STATE.plan:
250
+ STATE.plan_generated_inputs.add(str(list_path))
251
+ list_path.write_text(concat_list(resolved, rate), encoding="utf-8")
252
+ # every frame decodes, or the run is refused before the encode (a dry run too: ffprobe runs
253
+ # under --dry-run, as every probe does), naming the frames that do not
254
+ bad = undecodable_frames(list_path, frames, rate)
255
+ if bad is None:
256
+ note("the frames could not be checked before the encode (ffprobe failed on the frame list); "
257
+ "a frame that does not decode would be left out of the video")
258
+ elif bad:
259
+ names = ", ".join(f.name for f in bad[:5]) + (f" and {len(bad) - 5} more" if len(bad) > 5 else "")
260
+ refuse("input", "still_unreadable",
261
+ f"{len(bad)} of {len(frames)} frames do not decode as an image ({names}); they would be "
262
+ "missing from the video. Replace or remove them",
263
+ path=str(bad[0]), frames=[str(f) for f in bad], frames_unreadable=len(bad), frames_total=len(frames))
264
+
265
+ cmd = ffmpeg_base() + ["-f", "concat", "-safe", "0", "-i", str(list_path)]
266
+ vf = [f"scale={out_w}:{out_h}", "setsar=1", f"fps={rate.numerator}/{rate.denominator}"]
267
+ cmd += ["-vf", ",".join(vf)]
268
+ # RGB (PNG) frames are converted to the BT.709 the line is tagged with (the first frame's probe)
269
+ cmd += video_args(None, args.crf, args.preset, source=frame_meta)
270
+ # The concat demuxer's trailing repeated-last-file trick (needed so the last real file's
271
+ # duration line takes effect) has been observed to produce an extra frame's worth of
272
+ # duration on some ffmpeg builds -- force the exact intended length rather than trust it.
273
+ total_us = sum(frame_durations(len(frames), rate))
274
+ cmd += ["-t", f"{total_us // 1_000_000}.{total_us % 1_000_000:06d}", "-an", output]
275
+ run(cmd)
276
+
277
+ result = probe(output, role="output")
278
+ v = result["video"]
279
+ info(f"wrote {output} ({fmt_secs(result['duration'])}, {v['width']}x{v['height']}, {v['fps']:g}fps)")
280
+ emit(output)
281
+ return 0
282
+
283
+
284
+ if __name__ == "__main__":
285
+ sys.exit(main())