@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,91 @@
1
+ #!/usr/bin/env python3
2
+ """Crop a video to an exact pixel rectangle.
3
+
4
+ {x, y, width, height} are literal pixel offsets and dimensions in the SOURCE
5
+ frame, not aspect-ratio-relative -- for cropping to a target aspect ratio
6
+ (e.g. 16:9 -> 9:16) use fit.py --fit crop instead, which computes the
7
+ rectangle for you and lets you steer it with --crop-x/--crop-y. This tool is
8
+ for when the caller already knows the exact rectangle (a face-detection box,
9
+ a saved crop from a previous edit, a hand-picked region).
10
+
11
+ The rectangle must lie entirely inside the source frame after accounting for
12
+ any display rotation, and --width/--height must be even (required for 4:2:0
13
+ chroma subsampling, the pixel format every encoder here uses) -- given values
14
+ are validated and refused, never silently rounded, since a caller-specified
15
+ rectangle should do exactly what was asked or fail loudly. An odd --x/--y is
16
+ taken as given (the crop starts on that pixel), not moved to the chroma grid.
17
+
18
+ Examples:
19
+ python3 crop.py input.mp4 --x 100 --y 0 --width 1080 --height 1920
20
+ python3 crop.py input.mp4 --x 0 --y 140 --width 1920 --height 800 -o cropped.mp4
21
+ """
22
+ import argparse
23
+ import sys
24
+
25
+ from _common import add_common, apply_common, aac_args, cfr_args, with_cfr, default_output, die, emit, ffmpeg_base, info, probe, run_keeping_subtitles, video_args, X264_PRESETS, fmt_secs
26
+ from _common.probe import display_size, probed_maps, square_pixels, square_pixels_note
27
+ from _common.emit import note
28
+
29
+
30
+ def main() -> int:
31
+ ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
32
+ ap.add_argument("input")
33
+ ap.add_argument("-o", "--output", help="output file (default: <name>_crop.<ext>)")
34
+ ap.add_argument("--x", type=int, required=True, help="left edge of the crop rectangle, in source pixels")
35
+ ap.add_argument("--y", type=int, required=True, help="top edge of the crop rectangle, in source pixels")
36
+ ap.add_argument("--width", type=int, required=True, help="crop width in px (must be even); a size WxH is --width W --height H")
37
+ ap.add_argument("--height", type=int, required=True, help="crop height in px (must be even)")
38
+ ap.set_defaults(crf=18) # --quality's default (the --crf alias was removed in 2.0)
39
+ ap.add_argument("--preset", default="medium", choices=X264_PRESETS, help="x264 preset")
40
+ ap.add_argument("--fps", type=float, help="force a constant output frame rate (recommended for VFR sources)")
41
+ add_common(ap)
42
+ args = ap.parse_args()
43
+ apply_common(args)
44
+ if args.fps is not None and args.fps <= 0:
45
+ die(f"--fps must be positive, got {args.fps:g}")
46
+
47
+ if args.x < 0 or args.y < 0:
48
+ die(f"--x/--y must be >= 0, got x={args.x} y={args.y}")
49
+ if args.width <= 0 or args.height <= 0:
50
+ die(f"--width/--height must be > 0, got width={args.width} height={args.height}")
51
+ if args.width % 2 or args.height % 2:
52
+ die(f"--width/--height must be even (4:2:0 chroma), got width={args.width} height={args.height}")
53
+
54
+ meta = probe(args.input)
55
+ if not meta.get("video"):
56
+ die("input has no video stream")
57
+ # the rectangle is in the displayed frame cropdetect.py reports: rotation applied, and a
58
+ # non-square-pixel source squared at its display aspect first (#411)
59
+ sw, sh = display_size(meta["video"])
60
+ if args.x + args.width > sw or args.y + args.height > sh:
61
+ die(f"crop rectangle ({args.x},{args.y},{args.width}x{args.height}) exceeds the source frame ({sw}x{sh})")
62
+ has_audio = bool(meta.get("audio"))
63
+
64
+ output = args.output or default_output(args.input, "crop")
65
+ # exact=1: without it crop rounds an odd --x/--y down to the chroma grid of a 4:2:0 frame,
66
+ # and the rectangle written was one pixel left of / above the one asked for (A170's sibling, A157)
67
+ vf = [f"crop={args.width}:{args.height}:{args.x}:{args.y}:exact=1", "setsar=1"]
68
+ if square_pixels(meta["video"]):
69
+ vf.insert(0, square_pixels(meta["video"]))
70
+ note(square_pixels_note(meta["video"]))
71
+ # the picture the rectangle was checked against, not the largest one default selection takes
72
+ cmd = ffmpeg_base() + ["-i", args.input] + probed_maps(meta) + ["-vf", with_cfr(",".join(vf), meta, args.fps)]
73
+ cmd += video_args(meta, args.crf, args.preset)
74
+ cmd += cfr_args(meta, args.fps)
75
+ if has_audio:
76
+ cmd += aac_args()
77
+ else:
78
+ cmd += ["-an"]
79
+ # the crop keeps the timeline, so the subtitle/data tracks are copied as fit.py and color.py copy
80
+ # them, and dropped (said) only where the container refuses them (#520)
81
+ dropped_streams = run_keeping_subtitles(cmd, output)
82
+
83
+ result = probe(output, role="output")
84
+ v = result["video"]
85
+ info(f"wrote {output} ({fmt_secs(result['duration'])}, {v['width']}x{v['height']})")
86
+ emit(output, dropped_non_av_streams=dropped_streams)
87
+ return 0
88
+
89
+
90
+ if __name__ == "__main__":
91
+ sys.exit(main())
@@ -0,0 +1,214 @@
1
+ #!/usr/bin/env python3
2
+ """Measure black letterbox/pillarbox bars and report the crop rectangle that removes them.
3
+
4
+ Wraps FFmpeg's cropdetect filter: it samples frames, finds the largest
5
+ non-black rectangle common to (recent) frames, and reports it. This is a
6
+ measurement only -- it writes no file. Feed the reported {x, y, width,
7
+ height} to crop.py to actually remove the bars:
8
+
9
+ python3 cropdetect.py input.mp4
10
+ python3 crop.py input.mp4 --x 0 --y 140 --width 1920 --height 800
11
+
12
+ Distinct from fit.py --fit crop, which crops to a *target aspect ratio* it
13
+ computes itself (no black-bar detection involved) -- this tool instead
14
+ measures bars that are already baked into the source picture and tells you
15
+ where they are; it does not decide whether removing them is wanted (a
16
+ source with genuine letterboxed content, e.g. a scope-ratio film in a 16:9
17
+ frame, will "detect" that letterboxing as bars to strip, which is correct
18
+ for restoring the original frame but wrong if the letterboxing is part of
19
+ the intended presentation -- look at the frame before cropping it away).
20
+
21
+ --seconds controls how much of the file is sampled (default 10s, spread
22
+ across the file by --samples windows so a single black scene near the start
23
+ doesn't skew the result). Detected values fluctuate slightly frame to frame
24
+ even on a static border; the reported rectangle is the most common one seen.
25
+
26
+ Examples:
27
+ python3 cropdetect.py input.mp4
28
+ python3 cropdetect.py input.mp4 --seconds 30 --limit 0.15
29
+ """
30
+ import argparse
31
+ import re
32
+ import sys
33
+ from collections import Counter
34
+ from typing import Dict, List, Optional, Tuple
35
+
36
+ from _common import add_common, apply_common, die, emit, info, print_json, probe, require_tool, run_analysis, decode_gray_frames
37
+ from _common.emit import note, warn
38
+ from _common.probe import PROBED_VIDEO, display_size, square_pixels, square_pixels_note
39
+
40
+ MOTION_CENTRE_FPS = 2.0
41
+ MOTION_CENTRE_W, MOTION_CENTRE_H = 64, 36
42
+
43
+ CROP_RE = re.compile(r"crop=(\d+):(\d+):(\d+):(\d+)")
44
+
45
+
46
+ def round_rect(rect: Tuple[int, int, int, int], round_to: int, full: Tuple[int, int]) -> Tuple[int, int, int, int]:
47
+ """One measured rectangle (w, h, x, y) as it is reported: the whole frame when the picture
48
+ reaches every edge (cropdetect's own round=2 reading of an odd side is one pixel short of it),
49
+ else rounded down to a multiple of `round_to` and re-centred the way cropdetect's round option
50
+ does it. Rounding inside the filter made a bar-free 1920x1080 read 1920x1072 at the default 16
51
+ (#403): 1080 is not a multiple of 16, and the rounded size was then compared with the source's."""
52
+ w, h, x, y = rect
53
+ fw, fh = full
54
+ if fw and fh and x == 0 and y == 0 and w >= fw - fw % 2 and h >= fh - fh % 2:
55
+ return fw, fh, 0, 0
56
+ # the filter's own reading of its round option: 1 is 16, an odd value is doubled
57
+ round_to = 16 if round_to <= 1 else round_to * 2 if round_to % 2 else round_to
58
+ shrink_w, shrink_h = w % round_to, h % round_to
59
+ return w - shrink_w, h - shrink_h, x + ((shrink_w // 2 + 1) & ~1), y + ((shrink_h // 2 + 1) & ~1)
60
+
61
+
62
+ def detect(path: str, seconds: float, samples: int, limit: float, round_to: int, duration: float,
63
+ failed: "Optional[List[Dict]]" = None, square: str = "", full: Tuple[int, int] = (0, 0)) -> List[Tuple[int, int, int, int]]:
64
+ """Crop rectangles from `samples` windows spread over the file. A window ffmpeg cannot decode
65
+ is skipped, and appended to `failed` as {start, seconds, error} when the caller passes a list,
66
+ so the result can say how many of the readings it stands on. `square` is the source's
67
+ square_pixels() scale, run first so the rectangle is in the frame crop.py crops (#411).
68
+ `full` is that frame's size: the filter measures at round=2 and round_rect() rounds each
69
+ reading, so a picture that fills the frame is reported as the frame."""
70
+ ffmpeg = require_tool("ffmpeg")
71
+ per_window = max(0.5, seconds / max(1, samples))
72
+ rects: List[Tuple[int, int, int, int]] = []
73
+ failures: List[List[str]] = []
74
+ for i in range(samples):
75
+ start = 0.0 if duration <= 0 else (duration - per_window) * i / max(1, samples - 1) if samples > 1 else 0.0
76
+ start = max(0.0, start)
77
+ cmd = [ffmpeg, "-hide_banner", "-nostdin", "-ss", f"{start:.3f}", "-i", path, "-t", f"{per_window:.3f}",
78
+ "-map", f"0:{PROBED_VIDEO}", "-vf", (square + "," if square else "") + f"cropdetect=limit={limit:g}:round=2:reset=1", "-f", "null", "-"]
79
+ proc = run_analysis(cmd, check=False)
80
+ if proc.returncode != 0:
81
+ # One window ffmpeg cannot decode (a damaged stretch) is skipped; the other windows
82
+ # still measure. Only when every window fails is there nothing to report.
83
+ failures.append(proc.stderr.strip().splitlines()[-1:] or ["?"])
84
+ if failed is not None:
85
+ failed.append({"start": round(start, 3), "seconds": round(per_window, 3), "error": failures[-1][0][:300]})
86
+ continue
87
+ for m in CROP_RE.finditer(proc.stderr):
88
+ rects.append(round_rect((int(m.group(1)), int(m.group(2)), int(m.group(3)), int(m.group(4))), round_to, full))
89
+ if failures and len(failures) == samples:
90
+ die(f"cropdetect could not decode any of the {samples} sampled windows: {failures[-1][0][:300]}", kind="ffmpeg")
91
+ return rects
92
+
93
+
94
+ def motion_centre(path: str, seconds: float, samples: int, duration: float, sw: int, sh: int) -> List[Dict]:
95
+ """Per-second motion centroid: {time, x, y, x_frac, y_frac} -- a report-only measurement,
96
+ the same sampled-window approach as detect() above. x/y are pixel coordinates in the SOURCE
97
+ frame (consistent with the --round crop rectangle this tool already reports in source
98
+ pixels); x_frac/y_frac are the same position as a 0..1 fraction of source_width/height, for a
99
+ caller that wants to reframe without first knowing the source size. This never picks a
100
+ subject -- it reports where in the frame the measured pixel motion was concentrated, which is
101
+ not the same thing as where the interesting subject is (a moving background behind a still
102
+ speaker centres the motion on the background)."""
103
+ per_window = max(0.5, seconds / max(1, samples))
104
+ cell = 8 # NxN diff grid at decode resolution
105
+ cw, ch = MOTION_CENTRE_W / cell, MOTION_CENTRE_H / cell
106
+ out: List[Dict] = []
107
+ for i in range(samples):
108
+ start = 0.0 if duration <= 0 else (duration - per_window) * i / max(1, samples - 1) if samples > 1 else 0.0
109
+ start = max(0.0, start)
110
+ frames = decode_gray_frames(path, MOTION_CENTRE_FPS, MOTION_CENTRE_W, MOTION_CENTRE_H,
111
+ start=start, seconds=per_window, check=False)
112
+ for k in range(len(frames) - 1):
113
+ prev, cur = frames[k], frames[k + 1]
114
+ wsum = wx = wy = 0.0
115
+ for gy in range(cell):
116
+ for gx in range(cell):
117
+ x0, x1 = int(gx * cw), int((gx + 1) * cw)
118
+ y0, y1 = int(gy * ch), int((gy + 1) * ch)
119
+ diff = 0
120
+ for y in range(y0, y1):
121
+ row = y * MOTION_CENTRE_W
122
+ for x in range(x0, x1):
123
+ diff += abs(prev[row + x] - cur[row + x])
124
+ cx = (gx + 0.5) / cell
125
+ cy = (gy + 0.5) / cell
126
+ wsum += diff
127
+ wx += diff * cx
128
+ wy += diff * cy
129
+ t = start + (k + 1) / MOTION_CENTRE_FPS
130
+ if wsum <= 0:
131
+ out.append({"time": round(t, 2), "x": None, "y": None, "x_frac": None, "y_frac": None, "motion": 0.0})
132
+ continue
133
+ xf, yf = wx / wsum, wy / wsum
134
+ out.append({"time": round(t, 2), "x": round(xf * sw), "y": round(yf * sh),
135
+ "x_frac": round(xf, 3), "y_frac": round(yf, 3), "motion": round(wsum / (MOTION_CENTRE_W * MOTION_CENTRE_H), 2)})
136
+ out.sort(key=lambda r: r["time"])
137
+ return out
138
+
139
+
140
+ def main() -> int:
141
+ ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
142
+ ap.add_argument("input")
143
+ ap.add_argument("--duration", "--seconds", dest="seconds", type=float, default=10.0, help="total duration in seconds of the footage sampled across the file (default 10)")
144
+ ap.add_argument("--samples", type=int, default=5, help="number of windows spread across the file, 1..100 (default 5)")
145
+ ap.add_argument("--limit", type=float, default=0.0941176, help="black-pixel threshold, 0..1 (default ~0.094, cropdetect's own default)")
146
+ ap.add_argument("--round", type=int, default=16, dest="round_to", help="a detected crop's width/height are rounded down to a multiple of this (default 16); a picture that reaches every edge is reported as the whole frame, unrounded")
147
+ ap.add_argument("--motion-centre", action="store_true",
148
+ help="report the motion centroid per second, sampled the same way as the crop "
149
+ "detection above (report only -- this tool never picks a reframe, it hands "
150
+ "the calling agent numbers to reframe with)")
151
+ add_common(ap)
152
+ args = ap.parse_args()
153
+ apply_common(args)
154
+
155
+ if args.seconds <= 0:
156
+ die(f"--seconds must be > 0, got {args.seconds:g}")
157
+ if args.round_to <= 0:
158
+ die(f"--round must be > 0, got {args.round_to}")
159
+
160
+ meta = probe(args.input)
161
+ if not meta.get("video"):
162
+ die("input has no video stream")
163
+ # cropdetect and the grey decode both see the frame after ffmpeg applies rotation, so the
164
+ # rectangle and the motion points are in that frame. Reporting the stored size made a
165
+ # 176x320 crop look taller than a 320x180 source. A non-square-pixel source is measured
166
+ # squared at its display aspect, the frame crop.py then crops (#411).
167
+ sw, sh = display_size(meta["video"])
168
+ if square_pixels_note(meta["video"]):
169
+ note(square_pixels_note(meta["video"]))
170
+ duration = meta.get("duration") or 0.0
171
+
172
+ failed: List[Dict] = []
173
+ # A164: cropdetect reads a limit below 1 as a fraction of the top code and 1 or more as the
174
+ # code itself, so --limit 1, the top of the documented 0..1 range, was read as code 1 (nearly
175
+ # nothing is black) where 0.999 reads as nearly everything. The top of the range is written
176
+ # as the top code of the source's bit depth (255 for 8 bits, 1023 for 10).
177
+ limit = args.limit if args.limit < 1 else float((1 << int(meta["video"].get("bit_depth") or 8)) - 1)
178
+ rects = detect(args.input, args.seconds, args.samples, limit, args.round_to, duration, failed,
179
+ square_pixels(meta["video"]), (sw, sh))
180
+ # windows_failed: a window ffmpeg could not decode was skipped without a word, so a
181
+ # crop measured on one window of five read as well-founded as one measured on all five
182
+ result: Dict = {"file": args.input, "source_width": sw, "source_height": sh,
183
+ "windows": args.samples, "windows_failed": len(failed)}
184
+ if failed:
185
+ warn(f"cropdetect could not decode {len(failed)} of {args.samples} sampled windows; the crop rests on the other "
186
+ f"{args.samples - len(failed)}: {failed[-1]['error']}", "cropdetect_windows_failed",
187
+ failed=len(failed), windows=args.samples, starts=[f["start"] for f in failed])
188
+ if not rects:
189
+ result["crop"] = None
190
+ info("no crop bars detected (cropdetect produced no readings -- try --limit higher, or the source may already be full-frame)")
191
+ else:
192
+ w, h, x, y = Counter(rects).most_common(1)[0][0]
193
+ result["crop"] = {"width": w, "height": h, "x": x, "y": y}
194
+ result["confidence"] = round(Counter(rects).most_common(1)[0][1] / len(rects), 3)
195
+ if (w, h) == (sw, sh):
196
+ info(f"no bars detected: full {sw}x{sh} frame is already content")
197
+ else:
198
+ info(f"detected crop={w}:{h}:{x}:{y} (source {sw}x{sh}, confidence {result['confidence']:.0%}) -- "
199
+ f"crop.py {args.input} --x {x} --y {y} --width {w} --height {h}")
200
+
201
+ if args.motion_centre:
202
+ centre = motion_centre(args.input, args.seconds, args.samples, duration, sw, sh)
203
+ result["motion_centre"] = centre
204
+ info(f"--motion-centre: {len(centre)} measured points")
205
+
206
+ if args.json:
207
+ emit(None, **result)
208
+ else:
209
+ print_json(result)
210
+ return 0
211
+
212
+
213
+ if __name__ == "__main__":
214
+ sys.exit(main())