@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.
- package/README.md +62 -2
- package/cli.mjs +149 -0
- package/lib/dependencies.mjs +384 -0
- package/lib/run.mjs +114 -0
- package/lib/workspace.mjs +167 -0
- package/package.json +240 -3
- package/workspace/.agents/skills/cleoedits/SKILL.md +29 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/audiogram.json +41 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/facebook.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/linkedin.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/podcast.json +23 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/reels.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/shorts.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/tiktok.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/x.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/youtube-shorts.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/youtube.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/assets/LICENSE-SimpleIcons +30 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/assets/logos.json +1 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Anton-Regular.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/ArchivoBlack-Regular.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/InstrumentSerif-Italic.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Inter.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/LICENSE-PermanentMarker.txt +202 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Montserrat.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-Anton.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-ArchivoBlack.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-InstrumentSerif.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-Inter.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-Montserrat.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-PlayfairDisplay.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-Poppins.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-SpaceMono.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/PermanentMarker-Regular.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/PlayfairDisplay-Italic.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/PlayfairDisplay.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Poppins-Black.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Poppins-Bold.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Poppins-ExtraBold.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/SpaceMono-Bold.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/models/LICENSE-MediaPipe +218 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/models/LICENSE-YuNet +21 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/models/NOTICE.md +4 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/models/selfie_segmenter.tflite +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/models/yunet.onnx +0 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/LICENSE +21 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/audio-app-ui/STYLE.md +65 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/blueprint/STYLE.md +53 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/blueprint/index.html +328 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/blueprint/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/data-story/STYLE.md +65 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/data-story/index.html +575 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/design-app-ui/STYLE.md +68 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/editor-ui/STYLE.md +73 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/editorial-paper/STYLE.md +54 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/editorial-paper/index.html +189 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/editorial-paper/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/explainer-diagram/STYLE.md +64 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/explainer-diagram/index.html +620 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/graphite-ui/STYLE.md +55 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/graphite-ui/index.html +238 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/graphite-ui/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/growing-city/STYLE.md +66 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/growing-city/index.html +602 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/ink-line/STYLE.md +66 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/ink-line/index.html +777 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/midnight-grid/STYLE.md +56 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/midnight-grid/index.html +186 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/midnight-grid/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/motion-app-ui/STYLE.md +68 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/paper-cut/STYLE.md +56 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/paper-cut/index.html +244 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/paper-cut/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/paper-world/STYLE.md +67 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/paper-world/index.html +663 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/particle-field/STYLE.md +59 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/particle-field/index.html +395 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/poster-pop/STYLE.md +52 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/poster-pop/index.html +194 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/poster-pop/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/risograph/STYLE.md +58 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/risograph/index.html +242 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/risograph/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/swiss-grid/STYLE.md +53 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/swiss-grid/index.html +138 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/swiss-grid/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/swiss-kinetic/STYLE.md +63 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/swiss-kinetic/index.html +599 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/time-travel/STYLE.md +65 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/time-travel/index.html +1297 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/weather-widget/STYLE.md +69 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/weather-widget/index.html +674 -0
- package/workspace/.agents/skills/cleoedits/references/audio-clearervoice-elevenlabs.md +11 -0
- package/workspace/.agents/skills/cleoedits/references/ffmpeg-and-reels.md +15 -0
- package/workspace/.agents/skills/cleoedits/references/hyperframes-workflows.md +13 -0
- package/workspace/.agents/skills/cleoedits/references/kdenlive-cli-and-mcp.md +12 -0
- package/workspace/.agents/skills/cleoedits/references/motion-design-pipeline.md +7 -0
- package/workspace/.agents/skills/cleoedits/references/motion-taste-emil.md +5 -0
- package/workspace/.agents/skills/cleoedits/references/playwright-demo-capture.md +9 -0
- package/workspace/.agents/skills/cleoedits/references/remotion-workflows.md +13 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/LICENSE +21 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_ass_overlay.py +399 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/__init__.py +235 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/alpha.py +560 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/asr.py +1237 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/color.py +540 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/decision.py +2452 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/drawtext.py +290 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/emit.py +1309 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/emoji.py +518 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/fonts.py +875 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/pacing.py +263 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/pacing_edit.py +432 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/probe.py +1613 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/runner.py +3994 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/text.py +73 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/timeline.py +721 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/wrap.py +981 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_contract.py +2454 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_platforms.py +258 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_review.html +754 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_review.py +258 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_smartcut.py +450 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/audio.py +867 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/background.py +136 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/batch.py +1409 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/broll.py +282 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/caption.py +2207 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/check.py +815 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/color.py +695 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/crop.py +91 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/cropdetect.py +214 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/cut.py +2076 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/deinterlace.py +90 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/denoise.py +94 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/export.py +1033 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/fit.py +729 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/freeze.py +197 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/graphics.py +920 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/grid.py +235 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/insert.py +142 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/join.py +1083 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/look.py +475 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/loop.py +395 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/loudness.py +397 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/metadata.py +416 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/multicam.py +414 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/overlay.py +766 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/pad.py +121 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/probe.py +145 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/proxy.py +93 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/redact.py +162 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/render.py +2424 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/report.py +354 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/reverse.py +114 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/scenes.py +439 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/sequence.py +285 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/silence.py +945 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/speedramp.py +193 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/sphere.py +137 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/stabilize.py +141 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/straighten.py +120 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/sync.py +500 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/verify.py +411 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/waveform.py +502 -0
- package/workspace/.agents/skills/cleoedits/scripts/kdenlive_builder.py +284 -0
- package/workspace/.agents/skills/cleoedits/scripts/motion/LICENSE-claude-motion +21 -0
- package/workspace/.agents/skills/cleoedits/scripts/motion/LICENSE-motion-design +21 -0
- package/workspace/.agents/skills/cleoedits/scripts/motion/_media.py +43 -0
- package/workspace/.agents/skills/cleoedits/scripts/motion/pacing_check.py +90 -0
- package/workspace/.agents/skills/cleoedits/scripts/motion/storyboard.py +77 -0
- package/workspace/.agents/skills/cleoedits/scripts/reel_effects/LICENSE +26 -0
- package/workspace/.agents/skills/cleoedits/scripts/reel_effects/fx.py +2717 -0
- package/workspace/.agents/skills/cleoedits/scripts/reel_effects/logos.py +194 -0
- package/workspace/.agents/skills/cleoedits/scripts/reel_effects/sfx.py +105 -0
- package/workspace/.agents/skills/cleoedits/scripts/reel_effects/trim.py +99 -0
- package/workspace/.agents/skills/cleoedits/scripts/reel_effects/words.py +60 -0
- package/workspace/.claude/commands/blender-3d.md +12 -0
- package/workspace/.claude/commands/business-short-form-reels.md +12 -0
- package/workspace/.claude/commands/color-grade.md +12 -0
- package/workspace/.claude/commands/cutout-grid-reel.md +12 -0
- package/workspace/.claude/commands/depth-ui-reel.md +12 -0
- package/workspace/.claude/commands/explainer-panel-reel.md +12 -0
- package/workspace/.claude/commands/freeze-frame.md +12 -0
- package/workspace/.claude/commands/glass-graph.md +12 -0
- package/workspace/.claude/commands/over-the-shoulder.md +12 -0
- package/workspace/.claude/commands/personal-short-form-reels.md +12 -0
- package/workspace/.claude/commands/ranking-format.md +12 -0
- package/workspace/.claude/commands/relight.md +12 -0
- package/workspace/.claude/commands/reverse-engineer.md +12 -0
- package/workspace/.claude/commands/text-behind.md +12 -0
- package/workspace/.claude/commands/tier-list.md +12 -0
- package/workspace/.claude-plugin/plugin.json +8 -0
- package/workspace/.npmignore +15 -0
- package/workspace/AGENTS.md +30 -0
- package/workspace/README.md +63 -0
- package/workspace/assets/fonts/TikTokSans-OFL.txt +93 -0
- package/workspace/assets/fonts/TikTokSans-Variable.ttf +0 -0
- package/workspace/assets/luts/clean_warm.cube +4917 -0
- package/workspace/assets/luts/golden_hour.cube +4917 -0
- package/workspace/assets/luts/moody_dark.cube +4917 -0
- package/workspace/assets/luts/teal_orange.cube +4917 -0
- package/workspace/assets/sfx/NOTICE.txt +1 -0
- package/workspace/assets/sfx/click.wav +0 -0
- package/workspace/assets/sfx/pop.wav +0 -0
- package/workspace/assets/sfx/riser.wav +0 -0
- package/workspace/assets/sfx/whoosh.wav +0 -0
- package/workspace/generators/hyperframes/index.html +39 -0
- package/workspace/generators/hyperframes/package.json +15 -0
- package/workspace/generators/hyperframes/pnpm-lock.yaml +1181 -0
- package/workspace/generators/hyperframes/pnpm-workspace.yaml +10 -0
- package/workspace/generators/remotion/eslint.config.mjs +3 -0
- package/workspace/generators/remotion/package.json +36 -0
- package/workspace/generators/remotion/pnpm-lock.yaml +4179 -0
- package/workspace/generators/remotion/pnpm-workspace.yaml +10 -0
- package/workspace/generators/remotion/remotion.config.ts +13 -0
- package/workspace/generators/remotion/src/Root.tsx +52 -0
- package/workspace/generators/remotion/src/index.css +1 -0
- package/workspace/generators/remotion/src/index.ts +4 -0
- package/workspace/generators/remotion/tsconfig.json +15 -0
- package/workspace/pipeline/scripts/_codec.py +28 -0
- package/workspace/pipeline/scripts/ai_media_api.py +109 -0
- package/workspace/pipeline/scripts/blender_render.py +166 -0
- package/workspace/pipeline/scripts/composite.py +49 -0
- package/workspace/pipeline/scripts/melt.sh +68 -0
- package/workspace/pipeline/scripts/normalize_audio.py +39 -0
- package/workspace/pipeline/scripts/person_matte.py +216 -0
- package/workspace/pipeline/scripts/record_demo.py +69 -0
- package/workspace/pipeline/scripts/whisper_cut.py +98 -0
- package/workspace-manifest.json +908 -0
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Find scene changes and loud moments, and propose highlight candidates so the
|
|
3
|
+
agent can plan an edit or a digest without watching the whole file.
|
|
4
|
+
|
|
5
|
+
Scene cuts come from ffmpeg's scdet; energy peaks from a 0.5 s RMS envelope
|
|
6
|
+
of the audio. Highlight candidates are scenes ranked by --rank-by: "audio"
|
|
7
|
+
(default, loudest first) or "duration" (longest first). Both are proxies,
|
|
8
|
+
not a judgement of what matters: "audio" misses a quiet but important
|
|
9
|
+
moment (a confession, a punchline landing in silence) and can surface pure
|
|
10
|
+
crowd noise; "duration" just finds long unbroken takes. Neither replaces
|
|
11
|
+
watching the contact sheet (--sheet) before committing to a cut.
|
|
12
|
+
|
|
13
|
+
Examples:
|
|
14
|
+
python3 scenes.py talk.mp4 # scenes + peaks, JSON
|
|
15
|
+
python3 scenes.py event.mp4 --highlights 5 --target 60 # 5 candidate ranges summing to ~60 s
|
|
16
|
+
python3 scenes.py event.mp4 --highlights 4 --edl picks.txt # cut.py --segments compatible list
|
|
17
|
+
python3 scenes.py event.mp4 --sheet scenes.png # one thumbnail per scene
|
|
18
|
+
python3 scenes.py talk.mp4 --highlights 5 --rank-by duration # longest unbroken scenes, not loudest
|
|
19
|
+
"""
|
|
20
|
+
import argparse
|
|
21
|
+
import math
|
|
22
|
+
import sys
|
|
23
|
+
from typing import Dict, List, Optional, Tuple
|
|
24
|
+
|
|
25
|
+
# `detect_scenes` moved into _common/probe.py in 1.16.0 (see silence.py); the body is unchanged.
|
|
26
|
+
from _common import (guard_sidecar, detect_scenes, STATE, add_common, apply_common, beat_grid, default_font_file, die, emit,
|
|
27
|
+
ffmpeg_base, info, print_json, probe, run, decode_pcm_mono,
|
|
28
|
+
rms_envelope, BEAT_MIN_CONFIDENCE, decode_gray_frames, frame_flow, label_shot_flow)
|
|
29
|
+
from _common import drawtext_fontfile # noqa: E402
|
|
30
|
+
from _common import ffmpeg_filters, filter_missing_hint # noqa: E402
|
|
31
|
+
from _common.emit import note, record_fallback # noqa: E402
|
|
32
|
+
from _common.color import bt709_label_filter # noqa: E402
|
|
33
|
+
from _common.probe import PROBED_VIDEO, square_pixels # noqa: E402
|
|
34
|
+
from _common import dry_run_input_pending # noqa: E402
|
|
35
|
+
from _common.emit import input_length # noqa: E402
|
|
36
|
+
|
|
37
|
+
SHOT_FPS = 4.0 # frames/second sampled for --shots' flow estimate
|
|
38
|
+
SHOT_W, SHOT_H = 48, 27 # decode size for --shots (16:9-ish; enough blocks, still a few KB/shot)
|
|
39
|
+
SPEECH_STEP_S = 1.0 # --speech energy-ratio window
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def audio_envelope(path: str, step_s: float, *, rate: int = 8000,
|
|
44
|
+
samples: "Optional[List[float]]" = None) -> List[float]:
|
|
45
|
+
"""RMS level per step_s window, absolute (a loud scene scores higher); [] when the audio
|
|
46
|
+
cannot be decoded (the cut scoring then runs on the picture alone).
|
|
47
|
+
|
|
48
|
+
`samples` reuses PCM a caller already decoded rather than decoding the same file twice --
|
|
49
|
+
--beats needs a 10 ms envelope and the scene scoring a 0.5 s one, and 0.5 s is an integer
|
|
50
|
+
multiple of 10 ms, so both come from one pass.
|
|
51
|
+
"""
|
|
52
|
+
if samples is None:
|
|
53
|
+
samples = decode_pcm_mono(path, rate, check=False)
|
|
54
|
+
return rms_envelope(samples, int(rate * step_s))
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def parse_beat_range(text: str) -> "tuple":
|
|
58
|
+
"""`--beat-range 60-200` as (lo, hi) BPM."""
|
|
59
|
+
try:
|
|
60
|
+
lo, hi = (float(p) for p in str(text).replace(" ", "").split("-", 1))
|
|
61
|
+
except ValueError:
|
|
62
|
+
die(f"--beat-range: expected LO-HI in BPM (e.g. 60-200), got {text!r}", kind="input")
|
|
63
|
+
if not (0 < lo < hi):
|
|
64
|
+
die(f"--beat-range {text}: LO must be above 0 and below HI", kind="input")
|
|
65
|
+
return (lo, hi)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def shot_flow_label(path: str, start: float, end: float) -> Dict:
|
|
69
|
+
"""{start, end, label, flow_magnitude} for one shot: decode it at SHOT_FPS/SHOT_W x SHOT_H
|
|
70
|
+
and block-match consecutive frames (see _common.decision.frame_flow / label_shot_flow). A
|
|
71
|
+
shot under two sampled frames has nothing to compare and is reported static with
|
|
72
|
+
flow_magnitude 0 -- there is no motion measurement to make on a single frame."""
|
|
73
|
+
frames = decode_gray_frames(path, SHOT_FPS, SHOT_W, SHOT_H, start=start, seconds=max(0.0, end - start), check=False)
|
|
74
|
+
flows = [frame_flow(frames[i], frames[i + 1], SHOT_W, SHOT_H) for i in range(len(frames) - 1)]
|
|
75
|
+
label = label_shot_flow(flows)
|
|
76
|
+
return {"start": round(start, 3), "end": round(end, 3), "label": label["label"], "flow_magnitude": label["flow_magnitude"]}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def audio_peaks_db(samples: "List[float]", rate: int, step_s: float = 0.25) -> List[Dict]:
|
|
80
|
+
"""--audio-peaks: local maxima of the loudness envelope reported as measured dBFS, not the
|
|
81
|
+
unitless RMS scenes.py has always put in the (unconditional) `audio_peaks` key -- a
|
|
82
|
+
different unit needs a different key so the existing one keeps meaning what it always has."""
|
|
83
|
+
env = rms_envelope(samples, int(rate * step_s))
|
|
84
|
+
peaks = []
|
|
85
|
+
for i, val in enumerate(env):
|
|
86
|
+
if val <= 1e-6:
|
|
87
|
+
continue
|
|
88
|
+
if (i == 0 or env[i - 1] <= val) and (i == len(env) - 1 or env[i + 1] <= val):
|
|
89
|
+
level = round(20 * math.log10(val), 1)
|
|
90
|
+
peaks.append({"time": round(i * step_s, 2), "level": level})
|
|
91
|
+
return peaks
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def speech_music_ratio(samples: "List[float]", rate: int, step_s: float = SPEECH_STEP_S) -> List[Dict]:
|
|
95
|
+
"""--speech: a per-second zero-crossing-rate ratio, reported as a measured number, not a
|
|
96
|
+
speech/music label. Speech's rapid consonant transients drive the zero-crossing rate up and
|
|
97
|
+
make it jump window to window; sustained tones (music, a held note, room tone) cross zero at
|
|
98
|
+
a steadier rate. ratio = this window's ZCR / the file's median ZCR, so 1.0 is "typical for
|
|
99
|
+
this file" regardless of its overall noisiness -- a proxy, in the same spirit as scenes.py's
|
|
100
|
+
--rank-by, not a classifier: nothing here decides what is speech."""
|
|
101
|
+
step = max(1, int(rate * step_s))
|
|
102
|
+
zcrs: List[float] = []
|
|
103
|
+
for i in range(0, len(samples) - step + 1, step):
|
|
104
|
+
block = samples[i:i + step]
|
|
105
|
+
crossings = sum(1 for a, b in zip(block, block[1:]) if (a >= 0) != (b >= 0))
|
|
106
|
+
zcrs.append(crossings / max(1, len(block) - 1))
|
|
107
|
+
if not zcrs:
|
|
108
|
+
return []
|
|
109
|
+
med = sorted(zcrs)[len(zcrs) // 2] or 1e-9
|
|
110
|
+
return [{"time": round(i * step_s, 2), "speech_music_ratio": round(z / med, 3)} for i, z in enumerate(zcrs)]
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
# A --sheet picks one frame a scene with select. One expression summing a term a scene was refused
|
|
114
|
+
# by FFmpeg 7.1 and later at 3,000 scenes ("Error while parsing expression", ENOMEM) and taken by
|
|
115
|
+
# 6.1. No expression here grows with the scene count: the scenes are dealt round-robin to branches
|
|
116
|
+
# of at most SHEET_SELECT_TERMS terms, each summed as a balanced tree (at most
|
|
117
|
+
# ceil(log2(SHEET_SELECT_TERMS)) = 6 nested parentheses), and the branches' frames are merged back in
|
|
118
|
+
# time order by interleave. Round-robin keeps the branches level, so interleave holds about one
|
|
119
|
+
# thumbnail a branch.
|
|
120
|
+
SHEET_SELECT_TERMS = 64
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def _first_at(t: float) -> str:
|
|
124
|
+
"""The select term for the first frame at or after `t`. The starts are presentation times, so
|
|
125
|
+
the frame is chosen by its time, not by start x fps as a frame number -- on a
|
|
126
|
+
variable-frame-rate source that number is another frame (#411)."""
|
|
127
|
+
a = f"{max(0.0, t - 0.0006):.4f}"
|
|
128
|
+
return f"gte(t\\,{a})*(isnan(prev_t)+lt(prev_t\\,{a}))"
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def _balanced_sum(terms: List[str]) -> str:
|
|
132
|
+
if len(terms) == 1:
|
|
133
|
+
return terms[0]
|
|
134
|
+
mid = len(terms) // 2
|
|
135
|
+
return f"({_balanced_sum(terms[:mid])}+{_balanced_sum(terms[mid:])})"
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def sheet_graph(starts: List[float], src: str, thumb: str, tile: str) -> str:
|
|
139
|
+
"""The --sheet filter graph: exactly one frame a scene (the first at or after its start), each
|
|
140
|
+
made a thumbnail by `thumb`, laid out by `tile`, out as [sheet]."""
|
|
141
|
+
# no scene (a dry run whose input an earlier step has yet to write, a clip of under one scene):
|
|
142
|
+
# the sheet is its one tile, the first frame, as the 1x1 layout the caller sized for it
|
|
143
|
+
starts = starts or [0.0]
|
|
144
|
+
k = max(1, math.ceil(len(starts) / SHEET_SELECT_TERMS))
|
|
145
|
+
if k == 1:
|
|
146
|
+
return f"{src}select='{_balanced_sum([_first_at(t) for t in starts])}',{thumb},{tile}[sheet]"
|
|
147
|
+
parts = [f"{src}split={k}" + "".join(f"[s{j}]" for j in range(k))]
|
|
148
|
+
for j in range(k):
|
|
149
|
+
expr = _balanced_sum([_first_at(t) for t in starts[j::k]])
|
|
150
|
+
parts.append(f"[s{j}]select='{expr}',{thumb}[t{j}]")
|
|
151
|
+
parts.append("".join(f"[t{j}]" for j in range(k)) + f"interleave=nb_inputs={k},{tile}[sheet]")
|
|
152
|
+
return ";".join(parts)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def main() -> int:
|
|
156
|
+
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
157
|
+
ap.add_argument("input")
|
|
158
|
+
ap.add_argument("--threshold", type=float, default=8.0, help="minimum scdet score for a cut, 0..100 (default 8)")
|
|
159
|
+
ap.add_argument("--ratio", type=float, default=3.0, help="a cut must exceed this multiple of the neighbouring frames' median score (default 3; lower = more cuts)")
|
|
160
|
+
ap.add_argument("--min-scene", type=float, default=1.0, help="ignore cuts closer than this in seconds (default 1)")
|
|
161
|
+
ap.add_argument("--highlights", type=int, default=0, help="number of highlight ranges to propose")
|
|
162
|
+
ap.add_argument("--rank-by", choices=["audio", "duration"], default="audio",
|
|
163
|
+
help="how to rank scenes for --highlights: audio energy (default) or scene duration")
|
|
164
|
+
ap.add_argument("--target", type=float, help="with --highlights: total seconds the picks should add up to (trims long scenes)")
|
|
165
|
+
ap.add_argument("--max-scene", type=float, default=15.0, help="cap a highlight range at this many seconds (default 15)")
|
|
166
|
+
ap.add_argument("--edl", help="write highlight ranges as START-END lines (cut.py --segments format)")
|
|
167
|
+
ap.add_argument("--beats", action="store_true",
|
|
168
|
+
help="measure the music's beat grid (tempo, beat times, confidence) and report it; "
|
|
169
|
+
"a measurement, not a proposal -- no cut is made and no beat is invented")
|
|
170
|
+
ap.add_argument("--beat-step", type=float, default=0.01,
|
|
171
|
+
help="envelope resolution in seconds for the onset pass with --beats (default 0.01)")
|
|
172
|
+
ap.add_argument("--beat-range", default="60-200",
|
|
173
|
+
help="tempo search range in BPM for --beats (default 60-200)")
|
|
174
|
+
ap.add_argument("--min-confidence", type=float, default=BEAT_MIN_CONFIDENCE,
|
|
175
|
+
help="with --beats: below this confidence the grid is still reported, marked "
|
|
176
|
+
f"usable: false (default {BEAT_MIN_CONFIDENCE})")
|
|
177
|
+
ap.add_argument("--shots", action="store_true",
|
|
178
|
+
help="label each detected shot static / pan / motion by a measured optical-flow "
|
|
179
|
+
"proxy (lightweight block matching over sampled frames); reports flow_magnitude too")
|
|
180
|
+
ap.add_argument("--audio-peaks", action="store_true",
|
|
181
|
+
help="report loudness peaks as {time, level} in measured dBFS (separate from the "
|
|
182
|
+
"always-on `audio_peaks` RMS list used to pick --highlights)")
|
|
183
|
+
ap.add_argument("--speech", action="store_true",
|
|
184
|
+
help="report a per-second speech-vs-music energy ratio (zero-crossing-rate proxy, "
|
|
185
|
+
"a measurement, not a speech/music classification)")
|
|
186
|
+
ap.add_argument("--sheet", help="write a contact sheet PNG with the first frame of every scene")
|
|
187
|
+
ap.add_argument("--no-timecode", action="store_true", help="--sheet without the burnt-in timecode stamp (a way out if drawtext itself is unusable, see doctor)")
|
|
188
|
+
add_common(ap)
|
|
189
|
+
args = ap.parse_args()
|
|
190
|
+
apply_common(args)
|
|
191
|
+
if args.highlights < 0:
|
|
192
|
+
die(f"--highlights must be 0 or more (the number of ranges to propose), got {args.highlights}")
|
|
193
|
+
if not args.highlights:
|
|
194
|
+
# A145: these shape or write the --highlights picks; without it they were accepted and
|
|
195
|
+
# nothing was written (--edl FILE completed with no file)
|
|
196
|
+
for flag, given in (("--edl", args.edl is not None), ("--target", args.target is not None),
|
|
197
|
+
("--max-scene", args.max_scene != ap.get_default("max_scene"))):
|
|
198
|
+
if given:
|
|
199
|
+
die(f"{flag} applies to the ranges --highlights proposes, and --highlights was not given; "
|
|
200
|
+
"add --highlights N")
|
|
201
|
+
if args.target is not None and args.target <= 0:
|
|
202
|
+
die(f"--target must be more than 0 seconds, got {args.target:g}")
|
|
203
|
+
if args.max_scene <= 0:
|
|
204
|
+
die(f"--max-scene must be more than 0 seconds, got {args.max_scene:g}")
|
|
205
|
+
if args.highlights: # the EDL is written only with --highlights
|
|
206
|
+
guard_sidecar(args.edl, args.input, siblings=(args.sheet,))
|
|
207
|
+
|
|
208
|
+
meta = probe(args.input)
|
|
209
|
+
# Under --dry-run in a render.py/batch.py plan the input may be an earlier stage's output that
|
|
210
|
+
# was never written: every measurement is skipped (diagnostics.skipped measurement_input_pending)
|
|
211
|
+
# and the document keeps its shape with nothing measured, as loudness.py/cut.py do -- not an
|
|
212
|
+
# ffmpeg failure that stops the plan from being written.
|
|
213
|
+
pending = dry_run_input_pending(args.input)
|
|
214
|
+
# An audio-only file (WAV/FLAC/MP3 ...) is measured too (after 3.2.0): the beat grid, the loudness
|
|
215
|
+
# peaks and the speech ratio are measurements of the sound, and a music bed is usually
|
|
216
|
+
# delivered without a picture. It has no picture to cut, so it is one scene from 0 to its
|
|
217
|
+
# duration -- the same answer a video with no cut in it gets -- and the result says
|
|
218
|
+
# audio_only: true. What needs a picture (--sheet, --shots) is refused, not skipped.
|
|
219
|
+
audio_only = not meta.get("video")
|
|
220
|
+
if audio_only:
|
|
221
|
+
if not meta.get("audio"):
|
|
222
|
+
die("input has no video or audio stream")
|
|
223
|
+
picture_flags = [f for f, on in (("--sheet", args.sheet), ("--shots", args.shots)) if on]
|
|
224
|
+
if picture_flags:
|
|
225
|
+
die(f"{' and '.join(picture_flags)} need{'s' if len(picture_flags) == 1 else ''} a video stream; "
|
|
226
|
+
"this file is audio-only (input has no video stream). --beats, --audio-peaks, --speech "
|
|
227
|
+
"and --highlights measure the sound alone.", kind="input")
|
|
228
|
+
# Only parsed when it is going to be used: --beat-range is a --beats flag, and a run that
|
|
229
|
+
# never asked for beats should not be able to die on one.
|
|
230
|
+
beat_range = parse_beat_range(args.beat_range) if args.beats else (60.0, 200.0)
|
|
231
|
+
if args.beats:
|
|
232
|
+
if not meta.get("audio"):
|
|
233
|
+
die("--beats needs an audio stream; this file has none", kind="input")
|
|
234
|
+
if args.beat_step <= 0:
|
|
235
|
+
die("--beat-step must be greater than 0", kind="input")
|
|
236
|
+
dur = input_length(meta)
|
|
237
|
+
cuts = [0.0] if (audio_only or pending) else detect_scenes(args.input, args.threshold, args.min_scene, dur, args.ratio)
|
|
238
|
+
has_audio = bool(meta.get("audio")) and not pending
|
|
239
|
+
bounds = cuts + [dur]
|
|
240
|
+
step_s = 0.5
|
|
241
|
+
# With --beats the file is decoded once, at the finer rate, and both envelopes come from that
|
|
242
|
+
# one pass: the 0.5 s scene blocks are an exact multiple of the 10 ms onset blocks.
|
|
243
|
+
beat_rate = 22050
|
|
244
|
+
need_fine = args.beats or args.audio_peaks or args.speech
|
|
245
|
+
# --beats decodes with check=True: a decode that fails is an ffmpeg failure, not an empty
|
|
246
|
+
# envelope reported as "no steady pulse in this audio" (the scene scoring alone tolerates it
|
|
247
|
+
# and runs on the picture)
|
|
248
|
+
fine_samples = decode_pcm_mono(args.input, beat_rate, check=bool(args.beats)) if (need_fine and has_audio) else None
|
|
249
|
+
if fine_samples is not None:
|
|
250
|
+
env = audio_envelope(args.input, step_s, rate=beat_rate, samples=fine_samples)
|
|
251
|
+
else:
|
|
252
|
+
env = audio_envelope(args.input, step_s) if has_audio else []
|
|
253
|
+
|
|
254
|
+
scenes = []
|
|
255
|
+
for i in range(len(bounds) - 1):
|
|
256
|
+
s, e = bounds[i], bounds[i + 1]
|
|
257
|
+
if e - s <= 0.05:
|
|
258
|
+
continue
|
|
259
|
+
seg = env[int(s / step_s): max(int(s / step_s) + 1, int(e / step_s))] if env else []
|
|
260
|
+
energy = (sum(seg) / len(seg)) if seg else 0.0
|
|
261
|
+
peak = max(seg) if seg else 0.0
|
|
262
|
+
scenes.append({"index": len(scenes), "start": round(s, 3), "end": round(e, 3), "duration": round(e - s, 3),
|
|
263
|
+
"audio_rms": round(energy, 4), "audio_peak": round(peak, 4)})
|
|
264
|
+
peaks = []
|
|
265
|
+
if env:
|
|
266
|
+
thr = sorted(env)[int(len(env) * 0.9)] if len(env) > 10 else max(env)
|
|
267
|
+
for i, val in enumerate(env):
|
|
268
|
+
if val >= thr and val > 0.02 and (i == 0 or env[i - 1] < val) and (i == len(env) - 1 or env[i + 1] <= val):
|
|
269
|
+
peaks.append({"time": round(i * step_s, 2), "rms": round(val, 4)})
|
|
270
|
+
peaks = sorted(peaks, key=lambda p: -p["rms"])[:20]
|
|
271
|
+
peaks.sort(key=lambda p: p["time"])
|
|
272
|
+
|
|
273
|
+
result: Dict = {"file": args.input, "duration": round(dur, 3), "scene_count": len(scenes), "scenes": scenes, "audio_peaks": peaks}
|
|
274
|
+
if audio_only:
|
|
275
|
+
result["audio_only"] = True
|
|
276
|
+
info(f"{len(scenes)} scenes, {len(peaks)} audio peaks over {dur:.1f}s")
|
|
277
|
+
|
|
278
|
+
if args.shots:
|
|
279
|
+
shots = [shot_flow_label(args.input, s, e) for s, e in zip(bounds[:-1], bounds[1:]) if e - s > 0.05]
|
|
280
|
+
result["shots"] = shots
|
|
281
|
+
counts = {}
|
|
282
|
+
for sh in shots:
|
|
283
|
+
counts[sh["label"]] = counts.get(sh["label"], 0) + 1
|
|
284
|
+
info(f"--shots: {len(shots)} shots (" + ", ".join(f"{v} {k}" for k, v in sorted(counts.items())) + ")")
|
|
285
|
+
|
|
286
|
+
if args.audio_peaks:
|
|
287
|
+
if not has_audio:
|
|
288
|
+
result["audio_peaks_db"] = []
|
|
289
|
+
info("--audio-peaks: no audio stream, nothing to measure")
|
|
290
|
+
else:
|
|
291
|
+
db_samples = fine_samples if fine_samples is not None else decode_pcm_mono(args.input, 22050, check=False)
|
|
292
|
+
result["audio_peaks_db"] = audio_peaks_db(db_samples, 22050 if fine_samples is not None else 22050)
|
|
293
|
+
info(f"--audio-peaks: {len(result['audio_peaks_db'])} peaks")
|
|
294
|
+
|
|
295
|
+
if args.speech:
|
|
296
|
+
if not has_audio:
|
|
297
|
+
result["speech"] = []
|
|
298
|
+
info("--speech: no audio stream, nothing to measure")
|
|
299
|
+
else:
|
|
300
|
+
sp_samples = fine_samples if fine_samples is not None else decode_pcm_mono(args.input, 22050, check=False)
|
|
301
|
+
result["speech"] = speech_music_ratio(sp_samples, 22050)
|
|
302
|
+
info(f"--speech: {len(result['speech'])} one-second windows")
|
|
303
|
+
|
|
304
|
+
if args.beats:
|
|
305
|
+
# A beat grid is a measurement of the music's periodicity, not a statement about where a
|
|
306
|
+
# cut belongs. scenes.py reports what it measured, including a low confidence: reporting a
|
|
307
|
+
# weak measurement is honest, and only a tool that CHANGES a file refuses to act on one.
|
|
308
|
+
# The envelope's real step is a whole number of samples: 220 / 22050 = 9.977 ms for the
|
|
309
|
+
# default 10 ms. Timing the onsets as if it were 10 ms stretched every measured time by
|
|
310
|
+
# 0.23 % -- 68 ms by the end of a 30 s track, the "40-60 ms off" a click track showed --
|
|
311
|
+
# so the grid is timed (and step_s reported) at the step the envelope actually has.
|
|
312
|
+
beat_block = max(1, round(beat_rate * args.beat_step))
|
|
313
|
+
fine = rms_envelope(fine_samples or [], beat_block)
|
|
314
|
+
grid = beat_grid(fine, beat_block / beat_rate, bpm_range=beat_range,
|
|
315
|
+
min_confidence=args.min_confidence, duration=dur,
|
|
316
|
+
pcm=fine_samples, pcm_rate=beat_rate)
|
|
317
|
+
result["beats"] = grid["beats"]
|
|
318
|
+
result["beat_grid"] = {
|
|
319
|
+
# The regular grid AND the subset a measured onset supports. A tool that MOVES
|
|
320
|
+
# something (cut.py --snap beats) may only use the subset; scenes.py reports both,
|
|
321
|
+
# because here the regular grid is the measurement being made.
|
|
322
|
+
"supported_beats": grid["supported_beats"],
|
|
323
|
+
"tempo_bpm": grid["tempo_bpm"], "interval": grid["interval"],
|
|
324
|
+
"confidence": grid["confidence"], "phase": grid["phase"],
|
|
325
|
+
"onsets": len(grid["onsets"]), "supported": grid["supported"],
|
|
326
|
+
"unsupported": grid["unsupported"], "method": grid["method"],
|
|
327
|
+
"step_s": grid["step_s"], "range_bpm": grid["range_bpm"], "usable": grid["usable"],
|
|
328
|
+
# after 3.2.0, additive: how each onset was timed below the envelope step
|
|
329
|
+
# ("pcm-window-ratio": placed on the decoded samples; null: at the step)
|
|
330
|
+
"onset_refinement": grid["onset_refinement"],
|
|
331
|
+
}
|
|
332
|
+
if pending:
|
|
333
|
+
info("--beats: [dry-run] the input does not exist yet, nothing measured")
|
|
334
|
+
elif grid["tempo_bpm"] is None:
|
|
335
|
+
info(f"--beats: no steady pulse in this audio (confidence {grid['confidence']:.2f}) -- "
|
|
336
|
+
"speech, ambience or rubato has no tempo to measure")
|
|
337
|
+
else:
|
|
338
|
+
info(f"--beats: {grid['tempo_bpm']:.1f} BPM, {len(grid['beats'])} beats, confidence "
|
|
339
|
+
f"{grid['confidence']:.2f} ({grid['supported']} of {len(grid['beats'])} grid points "
|
|
340
|
+
f"have a measured onset)"
|
|
341
|
+
+ ("" if grid["usable"] else f" -- below --min-confidence {args.min_confidence}, usable: false"))
|
|
342
|
+
|
|
343
|
+
if args.highlights:
|
|
344
|
+
if args.rank_by == "duration":
|
|
345
|
+
rank_key = lambda sc: (-sc["duration"], sc["start"])
|
|
346
|
+
else:
|
|
347
|
+
rank_key = lambda sc: (-sc["audio_rms"], sc["start"])
|
|
348
|
+
ranked = sorted(scenes, key=rank_key)[: args.highlights]
|
|
349
|
+
picks: List[Tuple[float, float]] = []
|
|
350
|
+
empty: List[Tuple[float, float]] = []
|
|
351
|
+
budget = args.target if args.target else None
|
|
352
|
+
per = (budget / max(1, len(ranked))) if budget else args.max_scene
|
|
353
|
+
for sc in ranked:
|
|
354
|
+
length = min(sc["duration"], per, args.max_scene)
|
|
355
|
+
# take the loudest window inside the scene
|
|
356
|
+
best_s = sc["start"]
|
|
357
|
+
if env and length < sc["duration"]:
|
|
358
|
+
best, best_s = -1.0, sc["start"]
|
|
359
|
+
win = max(1, int(length / step_s))
|
|
360
|
+
# A139: a window starts at the scene's start or on the step grid after it, and
|
|
361
|
+
# ends inside the scene. The grid point at or before the start (floor) was a
|
|
362
|
+
# candidate, so a pick opened up to one step (0.5 s) early, on the previous shot
|
|
363
|
+
latest = sc["end"] - length
|
|
364
|
+
starts = [sc["start"]] + [i * step_s for i in range(math.ceil(sc["start"] / step_s - 1e-9),
|
|
365
|
+
math.floor(latest / step_s + 1e-9) + 1)
|
|
366
|
+
if sc["start"] < i * step_s <= latest]
|
|
367
|
+
for t in starts:
|
|
368
|
+
i = int(t / step_s + 1e-9)
|
|
369
|
+
val = sum(env[i:i + win])
|
|
370
|
+
if val > best:
|
|
371
|
+
best, best_s = val, t
|
|
372
|
+
# to the hundredth the result and the EDL are written in, inward: a start of 3.333
|
|
373
|
+
# written as 3.33 opened on the frame before the cut
|
|
374
|
+
pick_s = math.ceil(best_s * 100 - 1e-6) / 100
|
|
375
|
+
pick_e = math.floor(min(sc["end"], pick_s + length) * 100 + 1e-6) / 100
|
|
376
|
+
if pick_e <= pick_s:
|
|
377
|
+
# no hundredth fits inside it: written as 0.00-0.00 it was a range cut.py refuses
|
|
378
|
+
empty.append((sc["start"], sc["end"]))
|
|
379
|
+
continue
|
|
380
|
+
picks.append((pick_s, pick_e))
|
|
381
|
+
if empty and not picks:
|
|
382
|
+
die(f"--highlights found no range of at least 0.01 s, the precision the ranges are written in "
|
|
383
|
+
f"(each pick is at most {min(per, args.max_scene):g} s, or its scene is shorter)",
|
|
384
|
+
kind="input", hint="raise --target (or drop it), or lower --highlights")
|
|
385
|
+
for s, e in empty:
|
|
386
|
+
note(f"--highlights: the scene {s:.3f}-{e:.3f}s holds no range of at least 0.01 s and has no pick")
|
|
387
|
+
picks.sort()
|
|
388
|
+
result["highlights"] = [{"start": s, "end": e, "duration": round(e - s, 2)} for s, e in picks]
|
|
389
|
+
result["highlights_total"] = round(sum(e - s for s, e in picks), 2)
|
|
390
|
+
result["highlights_rank_by"] = args.rank_by
|
|
391
|
+
info(f"proposed {len(picks)} highlight ranges totalling {result['highlights_total']:.1f}s")
|
|
392
|
+
|
|
393
|
+
if args.sheet:
|
|
394
|
+
n = len(scenes)
|
|
395
|
+
cols = min(4, max(1, n))
|
|
396
|
+
rows = max(1, math.ceil(n / cols))
|
|
397
|
+
tile_w = 1280 // cols // 2 * 2
|
|
398
|
+
stamp = ""
|
|
399
|
+
if not args.no_timecode and ffmpeg_filters() and "drawtext" not in ffmpeg_filters():
|
|
400
|
+
# as look.py (#394): the sheet needs drawtext only for its stamps
|
|
401
|
+
args.no_timecode = True
|
|
402
|
+
record_fallback("this ffmpeg build has no drawtext filter, so the --sheet has no timecode stamps "
|
|
403
|
+
"(the same as --no-timecode)", "scenes_sheet_no_drawtext")
|
|
404
|
+
note("--sheet without timecode stamps: this ffmpeg build has no drawtext filter ("
|
|
405
|
+
+ filter_missing_hint("drawtext") + ")")
|
|
406
|
+
if not args.no_timecode:
|
|
407
|
+
default_font = default_font_file("DejaVu Sans")
|
|
408
|
+
font_prefix = f"{drawtext_fontfile(default_font)}:" if default_font else ""
|
|
409
|
+
stamp = f",drawtext=text='%{{pts\\:hms}}':{font_prefix}fontcolor=white:fontsize=h/14:box=1:boxcolor=black@0.55:boxborderw=4:x=6:y=6"
|
|
410
|
+
# an untagged source is labelled BT.709 (tags only), or the sheet's RGB read it as BT.601 (#410);
|
|
411
|
+
# a non-square-pixel source is squared at its display aspect (#411)
|
|
412
|
+
lab = bt709_label_filter(meta)
|
|
413
|
+
square = square_pixels(meta["video"])
|
|
414
|
+
thumb = (lab + "," if lab else "") + (square + "," if square else "") + f"scale={tile_w}:-2{stamp}"
|
|
415
|
+
graph = sheet_graph([sc["start"] for sc in scenes], f"[0:{PROBED_VIDEO}]", thumb,
|
|
416
|
+
f"tile={cols}x{rows}:padding=2:margin=2:color=0x202020")
|
|
417
|
+
run(ffmpeg_base() + ["-i", args.input, "-filter_complex", graph, "-map", "[sheet]", "-an",
|
|
418
|
+
"-frames:v", "1", "-fps_mode", "vfr", "-update", "1", args.sheet])
|
|
419
|
+
info(f"wrote {args.sheet}")
|
|
420
|
+
result["sheet"] = args.sheet
|
|
421
|
+
|
|
422
|
+
# after the sheet, as silence.py writes its EDL after the cut (#462 A41): a --sheet refused as an
|
|
423
|
+
# existing file, or failed, left the EDL behind, and the corrected retry was then refused for it
|
|
424
|
+
if args.highlights and args.edl:
|
|
425
|
+
if not STATE.dry_run: # the contract says --edl is not written under --dry-run
|
|
426
|
+
with open(args.edl, "w", encoding="utf-8") as fh:
|
|
427
|
+
for s, e in picks:
|
|
428
|
+
fh.write(f"{s:.2f}-{e:.2f}\n")
|
|
429
|
+
info(f"wrote {args.edl}")
|
|
430
|
+
|
|
431
|
+
if STATE.json: # --json-brief too: emit() is what adds the diagnostics (scenes_sheet_no_drawtext)
|
|
432
|
+
emit(None, **result)
|
|
433
|
+
else:
|
|
434
|
+
print_json(result)
|
|
435
|
+
return 0
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
if __name__ == "__main__":
|
|
439
|
+
sys.exit(main())
|