@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,395 @@
1
+ #!/usr/bin/env python3
2
+ """Loop a clip a number of times, or to a target duration.
3
+
4
+ For a background loop, an ambient bed, or filling a fixed slot length with
5
+ a short clip. --times repeats the whole clip that many times back to back;
6
+ --duration instead loops (and, on the last repeat, trims) to hit an exact
7
+ target length. Audio loops along with the video when present. Without
8
+ --crossfade the loop point is not smoothed: a clip that doesn't already loop
9
+ cleanly shows a visible cut/pop at each repeat. --crossfade S makes the clip
10
+ loop first: its last S seconds fade into its first S (picture and sound), so
11
+ one repeat is S shorter than the clip and every seam continues the motion;
12
+ --times 1 then writes a single seamless loop file. Every run measures its
13
+ seam (the picture step and the sound level step where a repeat meets the
14
+ next) and reports it next to the steady frame-to-frame step, so a caller can
15
+ see whether the seam still jumps. --boomerang is the other way: it plays the clip
16
+ forward, then backward, so every repeat meets frames that match. Each
17
+ turnaround frame is shown once (frames 0..N-1, then N-2..1), so the motion
18
+ does not stall at either end. A boomerang is silent, because reversed sound
19
+ plays backwards; add a bed with audio.py. Like reverse.py, it holds the
20
+ decoded clip in memory.
21
+
22
+ Examples:
23
+ python3 loop.py bg_loop.mp4 --times 3
24
+ python3 loop.py texture.mp4 --duration 30
25
+ python3 loop.py wave.mp4 --boomerang --times 4
26
+ python3 loop.py smoke.mp4 --crossfade 1 --duration 60
27
+ """
28
+ import argparse
29
+ import json
30
+ import math
31
+ import os
32
+ import sys
33
+ import tempfile
34
+
35
+ from _common import STATE, concat_list_line, add_common, aac_args, apply_common, cfr_args, with_cfr, default_output, die, emit, ffmpeg_base, info, probe, refuse_output_is_input, require_filter, require_tool, run, video_args, X264_PRESETS, time_arg, fmt_secs
36
+ from _common.emit import warn
37
+ from _common.decision import HELD_FRAMES_WARN_BYTES, av_trim, held_frames_bytes, length_output_t, stream_starts
38
+ from _common.probe import decode_gray_frames, decode_pcm_mono
39
+ from _common.emit import input_length, own_length, refuse_still
40
+
41
+
42
+ # The loop filter's size is capped at 32767 frames, so one boomerang cycle (2N-2 frames) must fit.
43
+ LOOP_FILTER_MAX_FRAMES = 32767
44
+
45
+
46
+ def _boomerang_graph(meta, src_dur: float, times) -> str:
47
+ """Frames 0..N-1, then N-2..1, repeated: `times` round trips, or forever for --duration (-t ends it).
48
+
49
+ The backward half is the source minus frame 0, reversed, minus its first frame (N-1). The
50
+ forward half already shows both ends, so each turnaround appears once. That is unlike the
51
+ common split/reverse/concat recipe, which shows frame N-1 twice and, on every repeat, frame 0
52
+ twice. Trimming by frame index this way needs no frame count."""
53
+ v = meta["video"]
54
+ frames = v.get("nb_frames") or round((v.get("duration") or src_dur) * (v.get("fps") or 30.0))
55
+ if frames < 3:
56
+ die(f"--boomerang needs a clip of at least 3 frames, got {frames}")
57
+ cycle = 2 * frames - 2
58
+ if cycle > LOOP_FILTER_MAX_FRAMES:
59
+ die(f"--boomerang cycle is {cycle} frames; ffmpeg's loop filter holds at most {LOOP_FILTER_MAX_FRAMES} "
60
+ f"-- cut the clip shorter first (cut.py)")
61
+ # reverse holds the clip's decoded frames; split, trim and loop pass references to the same
62
+ # frames, so the peak is about one clip (measured: the same max RSS as a plain reverse)
63
+ held = held_frames_bytes(v, frames)
64
+ if held > HELD_FRAMES_WARN_BYTES:
65
+ warn(f"--boomerang holds about {held / 1024 ** 3:.1f} GiB of decoded frames in memory "
66
+ f"({frames} frames of {v['width']}x{v['height']}) -- cut the clip shorter first (cut.py) if RAM is tight",
67
+ "memory_heavy", bytes=int(held))
68
+ repeats = -1 if times is None else times - 1
69
+ # Retimed by frame index at the source's nominal rate: a VFR source's reversed half carries
70
+ # its gaps mirrored, and a CFR conform after the graph duplicated a frame against them (a
71
+ # turnaround shown twice), so the output is made constant-rate here and passed through as is.
72
+ # fps= after setpts drops or repeats nothing; it tells the encoder the rate, whose time base
73
+ # otherwise follows the source's r_frame_rate and rounds the new timestamps unevenly.
74
+ rate = _nominal_rate(v)
75
+ return ("[0:v]split[f][r];[f]setpts=PTS-STARTPTS[fw];"
76
+ "[r]trim=start_frame=1,reverse,trim=start_frame=1,setpts=PTS-STARTPTS[bw];"
77
+ f"[fw][bw]concat=n=2:v=1:a=0,loop=loop={repeats}:size={LOOP_FILTER_MAX_FRAMES},"
78
+ f"setpts=N/(({rate})*TB),fps={rate}[v]")
79
+
80
+
81
+ # Above this a "frame rate" is a time base (90000/1 from MPEG-TS, 1000/1 from Matroska), not a rate.
82
+ MAX_PLAUSIBLE_FPS = 240
83
+
84
+
85
+ def _fraction(text):
86
+ try:
87
+ num, _, den = (text or "").partition("/")
88
+ value = float(num) / float(den or 1)
89
+ except (ValueError, ZeroDivisionError):
90
+ return None
91
+ return value if 0 < value <= MAX_PLAUSIBLE_FPS else None
92
+
93
+
94
+ def _nominal_rate(v) -> str:
95
+ """The source's frame rate as an exact fraction: r_frame_rate when it is within 1% of the
96
+ average (an iPhone clip: 60/1 against 59.95 from a 1/600 time base), else the average; with
97
+ neither usable, frames over the video's duration, else 30."""
98
+ r, avg = v.get("r_frame_rate"), v.get("avg_frame_rate")
99
+ r_val, avg_val = _fraction(r), _fraction(avg)
100
+ if r_val and (not avg_val or abs(r_val - avg_val) <= 0.01 * avg_val):
101
+ return r
102
+ if avg_val:
103
+ return avg
104
+ counted = (v.get("nb_frames") or 0) / (v.get("duration") or float("inf"))
105
+ return f"{counted:g}" if 0 < counted <= MAX_PLAUSIBLE_FPS else "30"
106
+
107
+
108
+ def concat_first_frame(listfile: str) -> float:
109
+ """Where the first frame sits on the clock ffmpeg reads a concat list on: the list's first video
110
+ start minus its start_time. The concat demuxer counts an MP4's hidden AAC priming packet into its
111
+ start (-0.021 s) where the MP4 demuxer does not, so ffmpeg moves both streams 21 ms later, and a
112
+ frame-rate time base then rounded the picture's move to 33 ms (12 ms off). 0.0 when unmeasured."""
113
+ proc = run([require_tool("ffprobe"), "-v", "error", "-f", "concat", "-safe", "0", "-i", listfile,
114
+ "-select_streams", "v:0", "-show_entries", "stream=start_time:format=start_time", "-of", "json"],
115
+ quiet=True, check=False)
116
+ try:
117
+ doc = json.loads(proc.stdout or "")
118
+ return float(doc["streams"][0]["start_time"]) - float(doc["format"]["start_time"])
119
+ except (ValueError, KeyError, IndexError, TypeError):
120
+ return 0.0
121
+
122
+
123
+ def _frame_count(v, rate: float, src_dur: float) -> int:
124
+ return int(v.get("nb_frames") or round((v.get("duration") or src_dur) * rate))
125
+
126
+
127
+ def _conformed_frames(v, rate: float, src_dur: float) -> int:
128
+ """The frames the crossfade's graph sees: the picture after fps=RATE, which fills a gap in a
129
+ variable-rate stream and drops crowded frames, so its count follows the stream's length, not
130
+ the frames stored (299 stored frames over 10 s at 30 fps come out 300). The unit's trims and
131
+ its length are counted in these, or a repeat is a frame or more off the length planned."""
132
+ # the video stream's length, else Matroska's tag, else the container's (main() refuses a source
133
+ # without one): never the stored frame count, which is what fps= does not keep
134
+ d = own_length(v) or src_dur
135
+ return int(round(float(d) * rate))
136
+
137
+
138
+ def _seamless_unit_cmd(meta, src: str, unit: str, rate: str, frames: int, fade_frames: int, has_audio: bool) -> list:
139
+ """One repeat that loops on itself: the clip's last `fade_frames` fade into its first ones.
140
+
141
+ The tail (frames N-F..N-1) is laid over the head (frames 0..F-1) with xfade, so the repeat
142
+ starts on frame N-F, the frame the clip's own frame N-F-1 leads into: the repeat's end runs
143
+ straight on into its start. Frames F..N-F-1 follow unchanged; the repeat is N-F frames. The
144
+ sound does the same on the picture's clock (padded with silence to the picture's length
145
+ first, so a short or late sound cannot shorten the fade). Written lossless
146
+ (FFV1 + FLAC) to a temporary file the concat list then repeats, so the repeats cost one
147
+ lossy encode, as without --crossfade."""
148
+ fps = _fraction(rate) or 30.0
149
+ fade = fade_frames / fps
150
+ cut = (frames - fade_frames) / fps
151
+ length = frames / fps
152
+ # each branch re-states its rate after setpts: FFmpeg 7.x's setpts marks the frame rate
153
+ # unknown (1/0) and xfade refuses anything but a constant one (6.1 kept it)
154
+ graph = (f"[0:v:0]setpts=PTS-STARTPTS,fps={rate},split[vt][vb];"
155
+ f"[vt]trim=start_frame={frames - fade_frames}:end_frame={frames},setpts=PTS-STARTPTS,fps={rate}[t];"
156
+ f"[vb]trim=end_frame={frames - fade_frames},setpts=PTS-STARTPTS,fps={rate}[b];"
157
+ f"[t][b]xfade=transition=fade:duration={fade:.6f}:offset=0[v]")
158
+ maps = ["-map", "[v]"]
159
+ if has_audio:
160
+ # acrossfade writes nothing when its first input is exactly the fade long (FFmpeg 6.1 and
161
+ # 7.1, measured), so the fade is built by hand: tail faded out + head faded in, summed
162
+ # the sound is shifted by the picture's start, the constant setpts=PTS-STARTPTS takes off the
163
+ # picture: rebased to its own start (aresample's first_pts=0 alone), a picture that starts
164
+ # 0.2 s after its sound came out 200 ms behind it in every repeat (A168)
165
+ v0 = stream_starts(meta)[0]
166
+ graph += (f";[0:a:0]atrim=start={v0:.6f},asetpts=PTS-{v0:.6f}/TB,aresample=async=1:first_pts=0,"
167
+ f"apad,atrim=end={length:.6f},asplit=3[at][ah][ab];"
168
+ f"[at]atrim=start={cut:.6f},asetpts=PTS-STARTPTS,afade=t=out:d={fade:.6f}:curve=tri[ta];"
169
+ f"[ah]atrim=end={fade:.6f},asetpts=PTS-STARTPTS,afade=t=in:d={fade:.6f}:curve=tri[ha];"
170
+ f"[ta][ha]amix=inputs=2:normalize=0:duration=longest[xa];"
171
+ f"[ab]atrim=start={fade:.6f}:end={cut:.6f},asetpts=PTS-STARTPTS[ba];"
172
+ f"[xa][ba]concat=n=2:v=0:a=1[a]")
173
+ maps += ["-map", "[a]", "-c:a", "flac"]
174
+ else:
175
+ maps += ["-an"]
176
+ return ffmpeg_base() + ["-i", src, "-filter_complex", graph] + maps + ["-c:v", "ffv1", "-fps_mode", "passthrough", unit]
177
+
178
+
179
+ # Frames are compared at this size: enough to see a cut or a jump, a few KB per frame.
180
+ SEAM_W, SEAM_H = 64, 36
181
+
182
+
183
+ def _mean_step(a: bytes, b: bytes) -> float:
184
+ return sum(abs(x - y) for x, y in zip(a, b)) / max(1, len(a))
185
+
186
+
187
+ def _rms_db(block) -> "float | None":
188
+ if not block:
189
+ return None
190
+ rms = math.sqrt(sum(x * x for x in block) / len(block))
191
+ return 20 * math.log10(rms) if rms > 1e-6 else -120.0
192
+
193
+
194
+ def _measure_seam(output: str, unit: float, out_dur: float, fps: float, has_audio: bool) -> dict:
195
+ """The first seam of the written file, where repeat 1 meets repeat 2 (or, for a single repeat,
196
+ the file's last frame against its first, as a player looping it would show them).
197
+
198
+ video_step: the mean absolute luma difference (0-255, on a 64x36 grey copy) across the seam;
199
+ video_typical_step: the median of the same difference between the neighbouring frames, so a
200
+ caller can tell a seam that jumps (step far above typical) from a clip that is busy anyway.
201
+ audio_level_step_db: the RMS level 20 ms after the seam minus 20 ms before it."""
202
+ half = min(0.5, unit / 2)
203
+ if out_dur - unit > 1.5 / fps:
204
+ frames = decode_gray_frames(output, fps, SEAM_W, SEAM_H, start=unit - half, seconds=2 * half, check=False)
205
+ at = round(half * fps)
206
+ pair = (frames[at - 1], frames[at]) if 0 < at < len(frames) else None
207
+ where = "between_repeats"
208
+ else:
209
+ head = decode_gray_frames(output, fps, SEAM_W, SEAM_H, seconds=half, check=False)
210
+ tail = decode_gray_frames(output, fps, SEAM_W, SEAM_H, start=max(0.0, out_dur - half), check=False)
211
+ frames = tail + head
212
+ at = len(tail)
213
+ pair = (tail[-1], head[0]) if tail and head else None
214
+ where = "end_to_start"
215
+ seam = {"at": where, "time": round(unit, 3) if where == "between_repeats" else None}
216
+ if pair:
217
+ steps = [_mean_step(frames[i - 1], frames[i]) for i in range(1, len(frames)) if i != at]
218
+ seam["video_step"] = round(_mean_step(*pair), 2)
219
+ seam["video_typical_step"] = round(sorted(steps)[len(steps) // 2], 2) if steps else None
220
+ else:
221
+ seam["video_step"] = seam["video_typical_step"] = None
222
+ if has_audio:
223
+ rate, win = 48000, 0.02
224
+ if where == "between_repeats":
225
+ pcm = decode_pcm_mono(output, rate, seconds=2 * win, start=unit - win, check=False)
226
+ before, after = pcm[: int(rate * win)], pcm[int(rate * win):]
227
+ else:
228
+ after = decode_pcm_mono(output, rate, seconds=win, check=False)
229
+ before = decode_pcm_mono(output, rate, start=max(0.0, out_dur - win), check=False)
230
+ b, a = _rms_db(before), _rms_db(after)
231
+ seam["audio_level_step_db"] = round(a - b, 1) if a is not None and b is not None else None
232
+ return seam
233
+
234
+
235
+ def main() -> int:
236
+ ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
237
+ ap.add_argument("input")
238
+ ap.add_argument("-o", "--output", help="output file (default: <name>_loop.<ext>)")
239
+ group = ap.add_mutually_exclusive_group(required=True)
240
+ group.add_argument("--times", "--count", type=int, help="repeat the whole clip this many times (2 = original + 1 repeat)")
241
+ group.add_argument("--duration", help="loop (and trim the last repeat) to hit exactly this target duration (seconds or mm:ss)")
242
+ ap.add_argument("--boomerang", action="store_true",
243
+ help="play forward then backward (--times counts round trips; 1 is allowed); drops audio")
244
+ ap.add_argument("--crossfade", metavar="S",
245
+ help="fade the clip's last S seconds into its first S (picture and sound) so every seam is smooth; "
246
+ "one repeat is then S shorter than the clip, and --times 1 writes one seamless loop")
247
+ ap.set_defaults(crf=18) # --quality's default (the --crf alias was removed in 2.0)
248
+ ap.add_argument("--preset", default="medium", choices=X264_PRESETS, help="x264 preset")
249
+ add_common(ap)
250
+ args = ap.parse_args()
251
+ apply_common(args)
252
+
253
+ meta = probe(args.input)
254
+ if not meta.get("video"):
255
+ die("input has no video stream")
256
+ refuse_still(meta, args.input, "a loop repeats a clip's length, and a still has none") # #531
257
+ src_dur = input_length(meta) # no stated length: refused with the way out (#491)
258
+ if src_dur <= 0:
259
+ die("input has no measurable duration to loop")
260
+ has_audio = bool(meta.get("audio")) and not args.boomerang
261
+ notes = []
262
+ output = args.output or default_output(args.input, "loop")
263
+ # the concat list is the only -i, so run() never sees the source next to -o (#416 review)
264
+ refuse_output_is_input(output, args.input)
265
+
266
+ v = meta["video"]
267
+ rate = _nominal_rate(v)
268
+ fps = _fraction(rate) or 30.0
269
+ unit = src_dur # the length one repeat adds
270
+ fade_frames = 0
271
+ if args.crossfade is not None:
272
+ if args.boomerang:
273
+ die("--crossfade and --boomerang cannot be combined: a boomerang's turnarounds already meet matching frames")
274
+ frames = _conformed_frames(v, fps, src_dur)
275
+ require_filter("xfade", "--crossfade")
276
+ fade = time_arg(args.crossfade, "--crossfade", v.get("fps"))
277
+ if not math.isfinite(fade):
278
+ die(f"--crossfade must be a finite number of seconds, got {args.crossfade!r}")
279
+ fade_frames = round(fade * fps)
280
+ if fade_frames < 1:
281
+ die(f"--crossfade {args.crossfade!r} is shorter than one frame ({1 / fps:.3f}s at {fps:g} fps)")
282
+ if 2 * fade_frames > frames:
283
+ die(f"--crossfade ({fade_frames / fps:.3f}s) must be at most half the clip ({frames / fps:.3f}s): "
284
+ f"the fade lays the clip's end over its start, and the two must not overlap")
285
+ unit = (frames - fade_frames) / fps
286
+
287
+ if args.times is not None:
288
+ least = 1 if (args.boomerang or fade_frames) else 2
289
+ if args.times < least:
290
+ die(f"--times must be >= 1, got {args.times}" if least == 1 else
291
+ f"--times must be >= 2 (1 is just the original clip; with --crossfade, 1 writes one seamless loop), got {args.times}")
292
+ target = None
293
+ stream_loop = args.times - 1
294
+ else:
295
+ target = time_arg(args.duration, "--duration", v.get("fps"))
296
+ if target <= unit:
297
+ die(f"--duration ({target:g}s) must be longer than one repeat ({unit:.3f}s) -- use cut.py to trim instead")
298
+ stream_loop = math.ceil(target / unit) - 1
299
+
300
+ # a variable-rate source is conformed to the rate cfr_args() delivers, by the fps filter in the
301
+ # picture's chain (below) and the output's -fps_mode cfr -r; the fps stage for a sound that
302
+ # outlasts the picture is for a constant-rate clip only, so the two never meet
303
+ forced_rate = cfr_args(meta, fps if fade_frames and v.get("variable_frame_rate_suspected") else None)
304
+ if args.boomerang:
305
+ cmd = ffmpeg_base() + ["-i", args.input, "-filter_complex", _boomerang_graph(meta, src_dur, args.times), "-map", "[v]"]
306
+ if meta.get("audio"):
307
+ notes.append("audio dropped: a boomerang plays half its sound backwards -- add a bed with audio.py")
308
+ else:
309
+ # The concat demuxer reads the clip once per repeat and starts each repeat at the previous
310
+ # one's start plus the file's duration (#409): both streams keep their offset from the
311
+ # file's start in every repeat. -stream_loop took the repeat's length from its streams'
312
+ # spans without the last video frame, so a sound that starts 0.3 s late shortened every
313
+ # repeat by a frame and slid against the picture (346 frames for 360, 68 ms off).
314
+ # Both streams start at the first frame, shifted by one constant (av_trim), and the gap a
315
+ # late sound leaves at each repeat's start is filled with silence, at any length.
316
+ workdir = tempfile.TemporaryDirectory(prefix="ffskill_loop_")
317
+ listfile = os.path.join(workdir.name, "loop.txt")
318
+ repeat = os.path.abspath(args.input)
319
+ if fade_frames:
320
+ repeat = os.path.join(workdir.name, "unit.mkv")
321
+ run(_seamless_unit_cmd(meta, args.input, repeat, rate, _conformed_frames(v, fps, src_dur), fade_frames, has_audio))
322
+ with open(listfile, "w", encoding="utf-8") as fh:
323
+ fh.write((concat_list_line(repeat) + "\n") * (stream_loop + 1))
324
+ vtrim, atrim = av_trim(concat_first_frame(listfile), None, fill_gaps=True)
325
+ # the conform of a VFR source is the fps filter at the end of the picture's chain, at the
326
+ # rate cfr_args() below delivers (#512)
327
+ vtrim = with_cfr(vtrim, meta, fps if fade_frames and v.get("variable_frame_rate_suspected") else None)
328
+ cmd = ffmpeg_base() + ["-f", "concat", "-safe", "0", "-i", listfile]
329
+ v_end = stream_starts(meta)[0] + (v.get("duration") or 0.0)
330
+ if has_audio and not forced_rate and not fade_frames and src_dur - v_end > 0.5 / fps:
331
+ # A repeat is as long as the file, so where the sound outlasts the picture by more
332
+ # than half a frame the next repeat's first frame comes later than one frame after
333
+ # the last. What stood in that gap was left to the output's frame-rate handling:
334
+ # FFmpeg 6.1 repeated the last frame and showed the next repeat's first frame twice,
335
+ # from a frame before its time (a 1 s 25 fps clip with 1.23425 s of sound: frame 0 of
336
+ # the second repeat at 1.20 s and 1.24 s, its sound from 1.23425 s); FFmpeg 7.1 and 8
337
+ # held the last frame (50 packets for 56). The graph ends on the clip's own rate, so
338
+ # the gap is the last frame repeated and each later repeat's frames sit on the grid
339
+ # once. A clip without that gap has nothing to fill and keeps the command it had.
340
+ vtrim += f",fps={rate}"
341
+ if has_audio:
342
+ cmd += ["-filter_complex", f"[0:v:0]{vtrim}[v];[0:a:0]{atrim}[a]",
343
+ "-map", "[v]", "-map", "[a]"]
344
+ else:
345
+ cmd += ["-map", "0:v:0", "-vf", vtrim]
346
+ if target is not None:
347
+ # the sound ends at --duration to the sample, not to the millisecond (length_output_t)
348
+ cmd += ["-t", length_output_t(target, (meta.get("audio") or {}).get("sample_rate") if has_audio else None, runs_on=True)]
349
+ cmd += video_args(meta, args.crf, args.preset)
350
+ # a crossfade's repeat is already constant at `rate` (its graph's fps=): the loop keeps that rate,
351
+ # not a variable-rate source's average, which re-timed every repeat by a frame or two
352
+ cmd += ["-fps_mode", "passthrough"] if args.boomerang else forced_rate
353
+ if has_audio:
354
+ cmd += aac_args()
355
+ else:
356
+ cmd += ["-an"]
357
+ cmd.append(output)
358
+ try:
359
+ run(cmd)
360
+ finally:
361
+ if not args.boomerang:
362
+ workdir.cleanup()
363
+
364
+ extra = {"boomerang": args.boomerang}
365
+ if fade_frames:
366
+ extra["crossfade"] = round(fade_frames / fps, 6)
367
+ requested = target if target is not None else (
368
+ args.times * (2 * _frame_count(v, fps, src_dur) - 2) / fps if args.boomerang else args.times * unit)
369
+ if STATE.dry_run:
370
+ emit(output, expected_duration=round(requested, 3), **extra, **({"notes": notes} if notes else {}))
371
+ return 0
372
+ result = probe(output, role="output")
373
+ rv = result["video"]
374
+ out_dur = result.get("duration") or 0.0
375
+ # the length asked for (repeats x one repeat, or --duration), against the file: within a frame
376
+ # and a half, the slack the last repeat's trim and the encoder's final frame leave
377
+ tolerance = 1.5 / fps
378
+ verification = [{"step": "duration", "requested": round(requested, 3), "measured": round(out_dur, 3),
379
+ "tolerance": round(tolerance, 3), "ok": abs(out_dur - requested) <= tolerance}]
380
+ if not args.boomerang:
381
+ extra["seam"] = _measure_seam(output, unit, out_dur, fps, has_audio)
382
+ info(f"wrote {output} ({fmt_secs(result['duration'])}, {rv['width']}x{rv['height']}, source {src_dur:.3f}s "
383
+ f"{'boomeranged' if args.boomerang else 'looped'})")
384
+ for note in notes:
385
+ info(note)
386
+ # the streams the run must have written: a crossfade unit whose sound came out empty once left
387
+ # a silent loop that still said verified: true
388
+ emit(output, expected_duration=round(requested, 3), verification=verification,
389
+ expect_streams={"video": 1, "audio": 1 if has_audio else 0}, **extra,
390
+ **({"notes": notes} if notes else {}))
391
+ return 0
392
+
393
+
394
+ if __name__ == "__main__":
395
+ sys.exit(main())