@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,354 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Build a single-file HTML delivery report: what went in, what came out,
|
|
3
|
+
before/after contact sheets, loudness, compliance and the exact commands.
|
|
4
|
+
The agent hands this to the user instead of a wall of text.
|
|
5
|
+
|
|
6
|
+
Examples:
|
|
7
|
+
python3 report.py --before raw.mov --after final.mp4 -o report.html
|
|
8
|
+
python3 report.py --after final.mp4 --platform reels --title "Episode 12 — Reels cut" -o report.html
|
|
9
|
+
python3 report.py --before raw.mov --after final.mp4 --commands commands.txt --notes notes.md
|
|
10
|
+
python3 report.py --pack talk_pack.md -o pack.html # the social pack table as HTML
|
|
11
|
+
"""
|
|
12
|
+
import argparse
|
|
13
|
+
import base64
|
|
14
|
+
import html
|
|
15
|
+
import json
|
|
16
|
+
import os
|
|
17
|
+
import re
|
|
18
|
+
import sys
|
|
19
|
+
import tempfile
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
22
|
+
|
|
23
|
+
from _common import guard_sidecar, STATE, add_common, apply_common, child_args, die, emit, info, probe, read_text_or_die, run_tool
|
|
24
|
+
from _common.emit import record_skip, warn
|
|
25
|
+
from _common.runner import file_arg
|
|
26
|
+
|
|
27
|
+
HERE = Path(__file__).resolve().parent
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _child_failure(proc: Any, doc: Any) -> Dict[str, Any]:
|
|
31
|
+
"""Why a sibling tool produced nothing usable: its own error (kind, reason, message), or the
|
|
32
|
+
last stderr line and the exit code when it printed no failure document."""
|
|
33
|
+
err = (doc or {}).get("error") if isinstance(doc, dict) and isinstance(doc.get("error"), dict) else {}
|
|
34
|
+
out: Dict[str, Any] = {"exit_code": proc.returncode,
|
|
35
|
+
"message": str(err.get("message") or (proc.stderr.strip().splitlines() or ["?"])[-1])[:300]}
|
|
36
|
+
for k in ("kind", "reason"):
|
|
37
|
+
if err.get(k):
|
|
38
|
+
out[k] = err[k]
|
|
39
|
+
return out
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def sheet_b64(path: str, tiles: str = "4x2", width: int = 1200) -> "Tuple[Optional[str], Dict[str, Any]]":
|
|
43
|
+
"""(the contact sheet as base64, or None; why there is none)."""
|
|
44
|
+
if STATE.dry_run:
|
|
45
|
+
return None, {"reason": "dry_run", "message": "a dry run draws no contact sheet"}
|
|
46
|
+
with tempfile.TemporaryDirectory(prefix="ffskill_report_") as tmp:
|
|
47
|
+
png = os.path.join(tmp, "sheet.png")
|
|
48
|
+
proc = run_tool([str(HERE / "look.py"), file_arg(path), "--tiles", tiles, "--width", str(width), "-o", png, "--json"] + child_args())
|
|
49
|
+
try:
|
|
50
|
+
doc = json.loads(proc.stdout)
|
|
51
|
+
except ValueError:
|
|
52
|
+
doc = None
|
|
53
|
+
if proc.returncode != 0 or not os.path.exists(png):
|
|
54
|
+
return None, dict(_child_failure(proc, doc), reason=((doc or {}).get("error") or {}).get("reason") or "look_failed")
|
|
55
|
+
return base64.b64encode(Path(png).read_bytes()).decode("ascii"), {}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def loudness(path: str) -> "Tuple[Dict[str, Any], Dict[str, Any]]":
|
|
59
|
+
"""(lufs/tp/lra, or {}; why there is no measurement)."""
|
|
60
|
+
proc = run_tool([str(HERE / "loudness.py"), file_arg(path), "--measure-only"] + child_args())
|
|
61
|
+
try:
|
|
62
|
+
d = json.loads(proc.stdout)
|
|
63
|
+
except ValueError:
|
|
64
|
+
d = None
|
|
65
|
+
try:
|
|
66
|
+
return {"lufs": round(float(d["input_i"]), 1), "tp": round(float(d["input_tp"]), 1), "lra": round(float(d["input_lra"]), 1)}, {}
|
|
67
|
+
except (TypeError, ValueError, KeyError):
|
|
68
|
+
return {}, dict(_child_failure(proc, d), reason="loudness_not_measured")
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def check(path: str, platform: str) -> "Tuple[Optional[Dict[str, Any]], Dict[str, Any]]":
|
|
72
|
+
"""(check.py's document, or None when it could not run at all; why)."""
|
|
73
|
+
proc = run_tool([str(HERE / "check.py"), file_arg(path), "--platform", platform, "--json"] + child_args())
|
|
74
|
+
try:
|
|
75
|
+
doc = json.loads(proc.stdout)
|
|
76
|
+
except ValueError:
|
|
77
|
+
doc = None
|
|
78
|
+
if not isinstance(doc, dict) or "checks" not in doc:
|
|
79
|
+
# check.py could not run at all (missing ffmpeg, unreadable file): its failure document
|
|
80
|
+
# has no rows to render. A failed *verification* still carries its rows and is shown.
|
|
81
|
+
why = dict(_child_failure(proc, doc), reason=((doc or {}).get("error") or {}).get("reason") or "check_failed")
|
|
82
|
+
info(f"check.py could not run: {why['message'][:200]}")
|
|
83
|
+
return None, why
|
|
84
|
+
return doc, {}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def fmt_dur(sec: Optional[float]) -> str:
|
|
88
|
+
if sec is None:
|
|
89
|
+
return "?"
|
|
90
|
+
m, s = divmod(sec, 60)
|
|
91
|
+
h, m = divmod(int(m), 60)
|
|
92
|
+
return f"{h}:{m:02d}:{s:05.2f}" if h else f"{m}:{s:05.2f}"
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def media_rows(meta: Dict[str, Any], ld: Dict[str, Any]) -> List[List[str]]:
|
|
96
|
+
v, a = meta.get("video") or {}, meta.get("audio") or {}
|
|
97
|
+
rows = [
|
|
98
|
+
["Duration", fmt_dur(meta.get("duration"))],
|
|
99
|
+
["Size", f"{(meta.get('size_bytes') or 0) / 1024 / 1024:.1f} MB"],
|
|
100
|
+
["Video", f"{v.get('codec')} {v.get('width')}×{v.get('height')} @ {v.get('fps')} fps, {v.get('pix_fmt')}" if v else "none"],
|
|
101
|
+
["Colour", (f"{v.get('color_primaries')}/{v.get('color_transfer')}" + (f" — {v.get('hdr_format')}" if v.get("bt2020_or_hdr") else " (SDR)")) if v else "—"],
|
|
102
|
+
["Frame rate", ("variable (suspected)" if v.get("variable_frame_rate_suspected") else "constant") if v else "—"],
|
|
103
|
+
["Audio", f"{a.get('codec')} {a.get('channels')} ch {a.get('sample_rate')} Hz" if a else "none"],
|
|
104
|
+
]
|
|
105
|
+
if ld:
|
|
106
|
+
rows.append(["Loudness", f"{ld['lufs']} LUFS, TP {ld['tp']} dBTP, LRA {ld['lra']} LU"])
|
|
107
|
+
return rows
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
PACK_CSS = """
|
|
111
|
+
:root{--bg:#F4F6F8;--paper:#fff;--ink:#161B21;--ink2:#4B5661;--line:#D8DEE4;--ok:#2C8A5B;--bad:#B4362F}
|
|
112
|
+
@media (prefers-color-scheme:dark){:root{--bg:#111518;--paper:#191E23;--ink:#E8ECEF;--ink2:#AEB6BE;--line:#2A3138;--ok:#5CC38C;--bad:#F07A73}}
|
|
113
|
+
body{margin:0;background:var(--bg);color:var(--ink);font:15px/1.6 system-ui,-apple-system,"Segoe UI",Roboto,"Noto Sans JP",sans-serif}
|
|
114
|
+
.wrap{max-width:900px;margin:0 auto;padding:32px 20px 60px}
|
|
115
|
+
h1{font-size:24px;margin:0 0 16px}
|
|
116
|
+
table{border-collapse:collapse;width:100%;font-size:14px;background:var(--paper);border:1px solid var(--line);border-radius:6px;overflow:hidden}
|
|
117
|
+
th,td{text-align:left;padding:7px 10px;border-bottom:1px solid var(--line)}th{color:var(--ink2);font-weight:500}
|
|
118
|
+
td.pass{color:var(--ok);font-weight:600}td.bad{color:var(--bad);font-weight:600}
|
|
119
|
+
p.note{color:var(--ink2);font-size:13px}
|
|
120
|
+
.foot{color:var(--ink2);font-size:12px;margin-top:30px;border-top:1px solid var(--line);padding-top:10px}
|
|
121
|
+
"""
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def md_cells(line: str) -> List[str]:
|
|
125
|
+
"""The cells of one GFM table row, as render.py's md_cell() writes them: a '|' preceded by a
|
|
126
|
+
backslash is part of the cell, and a doubled backslash is one. Splitting on every '|' moved a
|
|
127
|
+
file name such as `a | b.mp4` into the next column (A263)."""
|
|
128
|
+
cells: List[str] = []
|
|
129
|
+
cur: List[str] = []
|
|
130
|
+
body = line.strip()
|
|
131
|
+
body = body[1:] if body.startswith("|") else body
|
|
132
|
+
i = 0
|
|
133
|
+
while i < len(body):
|
|
134
|
+
ch = body[i]
|
|
135
|
+
if ch == "\\" and i + 1 < len(body) and body[i + 1] in "\\|":
|
|
136
|
+
cur.append(body[i + 1])
|
|
137
|
+
i += 2
|
|
138
|
+
continue
|
|
139
|
+
if ch == "|":
|
|
140
|
+
cells.append("".join(cur).strip())
|
|
141
|
+
cur = []
|
|
142
|
+
else:
|
|
143
|
+
cur.append(ch)
|
|
144
|
+
i += 1
|
|
145
|
+
if "".join(cur).strip():
|
|
146
|
+
cells.append("".join(cur).strip())
|
|
147
|
+
return cells
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
# the columns of render.py's render_pack() table, in its order
|
|
151
|
+
PACK_HEADER = ["platform", "file", "size", "duration", "check"]
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def pack_report(args) -> int:
|
|
155
|
+
"""render.py --template all writes <stem>_pack.md: one row per destination. This renders the
|
|
156
|
+
same rows as HTML, so a pack can be handed over the way a single delivery report is -- no
|
|
157
|
+
re-measurement, because the pack table is what the renders actually produced."""
|
|
158
|
+
text = read_text_or_die(args.pack, "--pack")
|
|
159
|
+
rows: List[List[str]] = []
|
|
160
|
+
header: List[str] = []
|
|
161
|
+
delimiter: Optional[List[str]] = None
|
|
162
|
+
for line in text.split("\n"):
|
|
163
|
+
line = line.strip()
|
|
164
|
+
if not line.startswith("|"):
|
|
165
|
+
if header:
|
|
166
|
+
break # the table ended: a later table in the file is not the pack's
|
|
167
|
+
continue
|
|
168
|
+
cells = md_cells(line)
|
|
169
|
+
if not header:
|
|
170
|
+
header = cells
|
|
171
|
+
elif delimiter is None:
|
|
172
|
+
delimiter = cells # the line under the header, whatever it is: checked below
|
|
173
|
+
else:
|
|
174
|
+
# every later line is a row, a separator-like one too: `| | |` after a row was skipped
|
|
175
|
+
# as a delimiter and never counted (review of #532)
|
|
176
|
+
rows.append(cells)
|
|
177
|
+
# the table render.py --template all writes, and only that one: any Markdown table was taken
|
|
178
|
+
# and handed over as a pack report with `verified: true` (#510)
|
|
179
|
+
if header and header != PACK_HEADER:
|
|
180
|
+
die(f"{args.pack}: its table's columns are {' | '.join(header)}, not the pack table's "
|
|
181
|
+
f"({' | '.join(PACK_HEADER)}) that render.py --template all writes", kind="input")
|
|
182
|
+
# a header with a row under it and no delimiter line is no Markdown table (review of #532)
|
|
183
|
+
if header and delimiter is not None and not (
|
|
184
|
+
len(delimiter) == len(PACK_HEADER) and all(re.fullmatch(r":?-+:?", c) for c in delimiter)):
|
|
185
|
+
die(f"{args.pack}: the line under the pack table's header is not its delimiter row "
|
|
186
|
+
f"(|---|---|---|---|---|), so it is no Markdown table", kind="input")
|
|
187
|
+
bad = next((i for i, r in enumerate(rows) if len(r) != len(PACK_HEADER)), None)
|
|
188
|
+
if bad is not None:
|
|
189
|
+
die(f"{args.pack}: row {bad + 1} of the pack table has {len(rows[bad])} cells, not {len(PACK_HEADER)}", kind="input")
|
|
190
|
+
if not rows:
|
|
191
|
+
die(f"{args.pack}: no pack table found (expected the Markdown table render.py --template all writes)", kind="input")
|
|
192
|
+
title = args.title or f"Social pack — {Path(args.pack).stem.replace('_pack', '')}"
|
|
193
|
+
output = args.output or str(Path(args.pack).with_suffix(".html"))
|
|
194
|
+
guard_sidecar(output, args.pack)
|
|
195
|
+
head = "".join(f"<th>{html.escape(h)}</th>" for h in header)
|
|
196
|
+
body = ""
|
|
197
|
+
for r in rows:
|
|
198
|
+
cells = ""
|
|
199
|
+
for i, c in enumerate(r):
|
|
200
|
+
cls = ""
|
|
201
|
+
if header[i:i + 1] == ["check"]:
|
|
202
|
+
cls = " class='pass'" if c.lower() == "pass" else " class='bad'"
|
|
203
|
+
cells += f"<td{cls}>{html.escape(c)}</td>"
|
|
204
|
+
body += f"<tr>{cells}</tr>"
|
|
205
|
+
doc = ("<!doctype html><html><head><meta charset='utf-8'><meta name='viewport' content='width=device-width,initial-scale=1'>"
|
|
206
|
+
f"<title>{html.escape(title)}</title><style>{PACK_CSS}</style></head><body><div class='wrap'>"
|
|
207
|
+
f"<h1>{html.escape(title)}</h1><table><tr>{head}</tr>{body}</table>"
|
|
208
|
+
f"<p class='note'>{len(rows)} destination(s) from one edit.</p>"
|
|
209
|
+
"<p class='foot'>Generated by ffmpeg-skill · local FFmpeg, no cloud.</p></div></body></html>")
|
|
210
|
+
if STATE.dry_run:
|
|
211
|
+
info(f"wrote {output}")
|
|
212
|
+
else:
|
|
213
|
+
try:
|
|
214
|
+
Path(output).write_text(doc, encoding="utf-8")
|
|
215
|
+
except OSError as e:
|
|
216
|
+
die(f"cannot write {output}: {e}", kind="output")
|
|
217
|
+
info(f"wrote {output} ({os.path.getsize(output) / 1024:.0f} KB)")
|
|
218
|
+
emit(None, report=output, pack=[dict(zip(header, r)) for r in rows], check=None, verification_paths=(output,),
|
|
219
|
+
verification=([{"step": "exists", "ok": True}] if not STATE.dry_run else []))
|
|
220
|
+
if not args.json:
|
|
221
|
+
print(output)
|
|
222
|
+
return 0
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def main() -> int:
|
|
226
|
+
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
227
|
+
ap.add_argument("--after", help="the deliverable (required unless --pack is given)")
|
|
228
|
+
ap.add_argument("--pack", metavar="FILE", help="a social pack table written by render.py --template all (<stem>_pack.md): render it as HTML")
|
|
229
|
+
ap.add_argument("--before", help="the source (optional)")
|
|
230
|
+
ap.add_argument("-o", "--output", help="report path (default: <after>_report.html)")
|
|
231
|
+
ap.add_argument("--title", help="report title")
|
|
232
|
+
ap.add_argument("--platform", help="run check.py for this platform and include the table")
|
|
233
|
+
ap.add_argument("--commands", help="text file with the commands that were run (one per line)")
|
|
234
|
+
ap.add_argument("--notes", help="text/markdown file with notes to include verbatim")
|
|
235
|
+
ap.add_argument("--no-sheets", action="store_true", help="skip contact sheets (faster, smaller)")
|
|
236
|
+
add_common(ap)
|
|
237
|
+
args = ap.parse_args()
|
|
238
|
+
apply_common(args)
|
|
239
|
+
|
|
240
|
+
if args.pack:
|
|
241
|
+
return pack_report(args)
|
|
242
|
+
if not args.after:
|
|
243
|
+
die("--after is required (or --pack FILE for a social pack table)")
|
|
244
|
+
output = args.output or str(Path(args.after).with_name(Path(args.after).stem + "_report.html"))
|
|
245
|
+
guard_sidecar(output, args.after, args.before, args.commands, args.notes) # before any measurement
|
|
246
|
+
after = probe(args.after)
|
|
247
|
+
before = probe(args.before) if args.before else None
|
|
248
|
+
# every section the report would show is either in it or accounted for: a section that could
|
|
249
|
+
# not be built is a failing verification step (and a warning), never just absent from the page
|
|
250
|
+
verification: List[Dict[str, Any]] = []
|
|
251
|
+
|
|
252
|
+
def section(step: str, which: Optional[str], why: Dict[str, Any], what: str) -> None:
|
|
253
|
+
entry: Dict[str, Any] = {"step": step, "ok": not why}
|
|
254
|
+
if which:
|
|
255
|
+
entry["file"] = which
|
|
256
|
+
if why:
|
|
257
|
+
if why.get("reason") == "dry_run":
|
|
258
|
+
record_skip(f"{what}: {why['message']}", "report_section_dry_run", section=step, file=which)
|
|
259
|
+
return
|
|
260
|
+
entry.update({k: v for k, v in why.items() if k != "message"}, message=why.get("message"))
|
|
261
|
+
warn(f"the report has no {what}: {why.get('message')}", "report_section_missing", section=step, file=which,
|
|
262
|
+
reason=why.get("reason"))
|
|
263
|
+
verification.append(entry)
|
|
264
|
+
|
|
265
|
+
ld_after: Dict[str, Any] = {}
|
|
266
|
+
ld_before: Dict[str, Any] = {}
|
|
267
|
+
if after.get("audio"):
|
|
268
|
+
ld_after, why = loudness(args.after)
|
|
269
|
+
section("loudness", "after", why, "loudness for --after")
|
|
270
|
+
if before and before.get("audio"):
|
|
271
|
+
ld_before, why = loudness(args.before)
|
|
272
|
+
section("loudness", "before", why, "loudness for --before")
|
|
273
|
+
chk = None
|
|
274
|
+
if args.platform:
|
|
275
|
+
chk, why = check(args.after, args.platform)
|
|
276
|
+
section("compliance", None, why, f"{args.platform} compliance table")
|
|
277
|
+
if chk is not None and verification:
|
|
278
|
+
# ok: the table is in the report; passed: what the table says about the file
|
|
279
|
+
verification[-1].update(platform=args.platform, passed=bool(chk.get("ok")))
|
|
280
|
+
sheets: Dict[str, Optional[str]] = {}
|
|
281
|
+
if not args.no_sheets:
|
|
282
|
+
for which, path, meta in (("before", args.before, before), ("after", args.after, after)):
|
|
283
|
+
if meta and meta.get("video"):
|
|
284
|
+
sheets[which], why = sheet_b64(path)
|
|
285
|
+
section("contact_sheet", which, why, f"{which} contact sheet")
|
|
286
|
+
# one per line, split at "\n" only (a command may hold U+2028 or \f; splitlines() split it)
|
|
287
|
+
command_text = read_text_or_die(args.commands, "--commands") if args.commands else ""
|
|
288
|
+
commands = command_text.removesuffix("\n").split("\n") if command_text else []
|
|
289
|
+
notes = read_text_or_die(args.notes, "--notes") if args.notes else ""
|
|
290
|
+
title = args.title or f"Delivery report — {Path(args.after).name}"
|
|
291
|
+
|
|
292
|
+
def table(rows: List[List[str]]) -> str:
|
|
293
|
+
return "<table>" + "".join(f"<tr><th>{html.escape(k)}</th><td>{html.escape(str(v))}</td></tr>" for k, v in rows) + "</table>"
|
|
294
|
+
|
|
295
|
+
parts: List[str] = []
|
|
296
|
+
parts.append(f"<h1>{html.escape(title)}</h1>")
|
|
297
|
+
parts.append(f"<p class='meta'>{html.escape(os.path.abspath(args.after))}</p>")
|
|
298
|
+
cols = []
|
|
299
|
+
if before:
|
|
300
|
+
cols.append(f"<div class='col'><h2>Before</h2><p class='file'>{html.escape(Path(args.before).name)}</p>{table(media_rows(before, ld_before))}"
|
|
301
|
+
+ (f"<img src='data:image/png;base64,{sheets['before']}' alt='before contact sheet'>" if sheets.get("before") else "") + "</div>")
|
|
302
|
+
cols.append(f"<div class='col'><h2>After</h2><p class='file'>{html.escape(Path(args.after).name)}</p>{table(media_rows(after, ld_after))}"
|
|
303
|
+
+ (f"<img src='data:image/png;base64,{sheets['after']}' alt='after contact sheet'>" if sheets.get("after") else "") + "</div>")
|
|
304
|
+
parts.append("<div class='cols'>" + "".join(cols) + "</div>")
|
|
305
|
+
if chk:
|
|
306
|
+
rows = "".join(
|
|
307
|
+
f"<tr class='{r['status'].lower()}'><td class='st'>{r['status']}</td><td>{html.escape(r['check'])}</td><td>{html.escape(str(r['value']))}</td><td>{html.escape(str(r['expected']))}</td><td>{html.escape(r.get('fix') or '') if r['status'] != 'PASS' else ''}</td></tr>"
|
|
308
|
+
for r in chk["checks"])
|
|
309
|
+
verdict = "READY" if chk.get("ok") else f"{chk.get('failed')} FAIL"
|
|
310
|
+
parts.append(f"<h2>Compliance — {html.escape(args.platform)} <span class='verdict {'ok' if chk.get('ok') else 'bad'}'>{verdict}</span></h2>"
|
|
311
|
+
f"<table class='checks'><tr><th></th><th>check</th><th>value</th><th>expected</th><th>fix</th></tr>{rows}</table>")
|
|
312
|
+
if notes:
|
|
313
|
+
parts.append("<h2>Notes</h2><pre class='notes'>" + html.escape(notes) + "</pre>")
|
|
314
|
+
if commands:
|
|
315
|
+
parts.append("<h2>Commands</h2><pre class='cmd'>" + html.escape("\n".join(commands)) + "</pre>")
|
|
316
|
+
parts.append("<p class='foot'>Generated by ffmpeg-skill · local FFmpeg, no cloud.</p>")
|
|
317
|
+
|
|
318
|
+
css = """
|
|
319
|
+
:root{--bg:#F4F6F8;--paper:#fff;--ink:#161B21;--ink2:#4B5661;--line:#D8DEE4;--ok:#2C8A5B;--warn:#C48519;--bad:#B4362F;--accent:#1E6F8E}
|
|
320
|
+
@media (prefers-color-scheme:dark){:root{--bg:#111518;--paper:#191E23;--ink:#E8ECEF;--ink2:#AEB6BE;--line:#2A3138;--ok:#5CC38C;--warn:#E3A63C;--bad:#F07A73;--accent:#5FB2D4}}
|
|
321
|
+
body{margin:0;background:var(--bg);color:var(--ink);font:15px/1.6 system-ui,-apple-system,"Segoe UI",Roboto,"Noto Sans JP",sans-serif}
|
|
322
|
+
.wrap{max-width:1100px;margin:0 auto;padding:32px 20px 60px}
|
|
323
|
+
h1{font-size:26px;margin:0 0 4px}h2{font-size:18px;margin:28px 0 10px}
|
|
324
|
+
.meta{color:var(--ink2);font-size:13px;margin:0 0 20px;word-break:break-all}
|
|
325
|
+
.cols{display:grid;grid-template-columns:repeat(auto-fit,minmax(320px,1fr));gap:16px}
|
|
326
|
+
.col{background:var(--paper);border:1px solid var(--line);border-radius:6px;padding:14px 16px}
|
|
327
|
+
.col h2{margin-top:0}.file{color:var(--ink2);font-size:13px;margin:0 0 8px}
|
|
328
|
+
table{border-collapse:collapse;width:100%;font-size:14px}th,td{text-align:left;padding:6px 8px;border-bottom:1px solid var(--line);vertical-align:top}
|
|
329
|
+
th{color:var(--ink2);font-weight:500;width:34%}
|
|
330
|
+
img{max-width:100%;border-radius:4px;margin-top:12px;border:1px solid var(--line)}
|
|
331
|
+
.checks{background:var(--paper);border:1px solid var(--line);border-radius:6px;overflow:hidden}.checks th{width:auto}
|
|
332
|
+
.st{font-weight:700;font-family:ui-monospace,Menlo,monospace}tr.pass .st{color:var(--ok)}tr.warn .st{color:var(--warn)}tr.fail .st{color:var(--bad)}
|
|
333
|
+
.verdict{font-size:13px;padding:2px 8px;border-radius:3px;margin-left:8px;vertical-align:middle}.verdict.ok{background:var(--ok);color:#fff}.verdict.bad{background:var(--bad);color:#fff}
|
|
334
|
+
pre{background:var(--paper);border:1px solid var(--line);border-radius:6px;padding:12px 14px;overflow-x:auto;font-size:12.5px;line-height:1.5}
|
|
335
|
+
.foot{color:var(--ink2);font-size:12px;margin-top:36px;border-top:1px solid var(--line);padding-top:10px}
|
|
336
|
+
"""
|
|
337
|
+
doc = f"<!doctype html><html><head><meta charset='utf-8'><meta name='viewport' content='width=device-width,initial-scale=1'><title>{html.escape(title)}</title><style>{css}</style></head><body><div class='wrap'>{''.join(parts)}</div></body></html>"
|
|
338
|
+
if STATE.dry_run:
|
|
339
|
+
info(f"wrote {output}") # printed as "[dry-run] would write"; nothing is written
|
|
340
|
+
else:
|
|
341
|
+
try:
|
|
342
|
+
Path(output).write_text(doc, encoding="utf-8")
|
|
343
|
+
except OSError as e:
|
|
344
|
+
die(f"cannot write {output}: {e}", kind="output")
|
|
345
|
+
info(f"wrote {output} ({os.path.getsize(output) / 1024:.0f} KB)")
|
|
346
|
+
emit(None, report=output, check=chk, verification_paths=(output,),
|
|
347
|
+
verification=([{"step": "exists", "ok": True}] + verification if not STATE.dry_run else []))
|
|
348
|
+
if not args.json:
|
|
349
|
+
print(output)
|
|
350
|
+
return 0
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
if __name__ == "__main__":
|
|
354
|
+
sys.exit(main())
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Reverse a video (and its audio, unless dropped).
|
|
3
|
+
|
|
4
|
+
Uses ffmpeg's `reverse` (video) and `areverse` (audio) filters, which decode
|
|
5
|
+
and buffer the whole clip in memory -- long inputs cost real time and RAM,
|
|
6
|
+
which is why there is no length limit baked in here: it is the caller's job
|
|
7
|
+
to keep this to clips it makes sense to reverse (a few seconds to a couple of
|
|
8
|
+
minutes), not a workaround this tool applies for you.
|
|
9
|
+
|
|
10
|
+
Examples:
|
|
11
|
+
python3 reverse.py input.mp4
|
|
12
|
+
python3 reverse.py input.mp4 --no-audio -o backwards.mp4
|
|
13
|
+
"""
|
|
14
|
+
import argparse
|
|
15
|
+
import math
|
|
16
|
+
import sys
|
|
17
|
+
|
|
18
|
+
from _common.runner import with_mapped_chapters
|
|
19
|
+
from _common import add_common, apply_common, aac_args, cfr_args, cfr_filter, default_output, die, emit, ffmpeg_base, info, probe, run, video_args, X264_PRESETS, fmt_secs
|
|
20
|
+
from _common.emit import warn
|
|
21
|
+
from _common.decision import (HELD_FRAMES_WARN_BYTES, av_clip_length, av_trim, delivered_rate, frame_durations, frame_rate,
|
|
22
|
+
held_frames_bytes, stream_starts)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def main() -> int:
|
|
26
|
+
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
27
|
+
ap.add_argument("input")
|
|
28
|
+
ap.add_argument("-o", "--output", help="output file (default: <name>_reverse.<ext>)")
|
|
29
|
+
ap.add_argument("--no-audio", action="store_true", help="drop audio instead of reversing it")
|
|
30
|
+
ap.set_defaults(crf=18) # --quality's default (the --crf alias was removed in 2.0)
|
|
31
|
+
ap.add_argument("--preset", default="medium", choices=X264_PRESETS, help="x264 preset")
|
|
32
|
+
add_common(ap)
|
|
33
|
+
args = ap.parse_args()
|
|
34
|
+
apply_common(args)
|
|
35
|
+
|
|
36
|
+
meta = probe(args.input)
|
|
37
|
+
if not meta.get("video"):
|
|
38
|
+
die("input has no video stream")
|
|
39
|
+
has_audio = bool(meta.get("audio")) and not args.no_audio
|
|
40
|
+
|
|
41
|
+
output = args.output or default_output(args.input, "reverse")
|
|
42
|
+
# keyed on what is held (every decoded frame), not on the length alone (A174): the estimate
|
|
43
|
+
# loop.py --boomerang warns from, over the frames of the picture's length at its rate
|
|
44
|
+
v = meta["video"]
|
|
45
|
+
vdur = v.get("duration") or meta.get("duration") or 0.0
|
|
46
|
+
frames = v.get("nb_frames") or vdur * (frame_rate(meta) or v.get("fps") or 30.0)
|
|
47
|
+
held = held_frames_bytes(v, frames)
|
|
48
|
+
if held > HELD_FRAMES_WARN_BYTES:
|
|
49
|
+
warn(f"reverse holds about {held / 1024 ** 3:.1f} GiB of decoded frames in memory "
|
|
50
|
+
f"({vdur:.0f}s of {v['width']}x{v['height']}) -- cut the part to reverse first (cut.py) if RAM is tight",
|
|
51
|
+
"memory_heavy", duration=meta.get("duration"), bytes=held)
|
|
52
|
+
cmd = ffmpeg_base() + ["-i", args.input]
|
|
53
|
+
# A VFR source is put on the delivered grid before the reversal (#523). `reverse` hands its
|
|
54
|
+
# frames the forward timestamps in order, so a reversed VFR picture kept its gaps where they
|
|
55
|
+
# were in forward time: every flash of the 27 fps average clip came 0.19 s late against the
|
|
56
|
+
# reversed sound (0.23 s without sound). On a constant grid the reversed picture is the forward
|
|
57
|
+
# one mirrored. Each slot takes the last frame that starts before the slot ends (round=down),
|
|
58
|
+
# which is the frame the reversed slot opens on: the nearest frame to its start (the forward
|
|
59
|
+
# conform's choice) dropped a last frame that starts after the last slot's middle, and the
|
|
60
|
+
# reversal then opened on the frame before it. The conformed picture's time base is one frame,
|
|
61
|
+
# and a trim rescales its bound to it (a half-frame bound can round onto a frame and cut it:
|
|
62
|
+
# freeze.py), so a microsecond base follows.
|
|
63
|
+
reversed_conform = f"{cfr_filter(meta)}:round=down,settb=AVTB" if cfr_filter(meta) else ""
|
|
64
|
+
if has_audio:
|
|
65
|
+
# Both streams are reversed about one end (#409); each reversed about its own end put a sound
|
|
66
|
+
# 0.6 s longer than its picture 0.396 s off. As in a join, both start at the first frame (the
|
|
67
|
+
# sound shifted by the same constant, padded when it starts late) and end together, on the
|
|
68
|
+
# first frame time at or after the clip's one length (av_clip_length: the picture's, or the
|
|
69
|
+
# sound's when it runs more than a frame past it). The last frame is held and the sound
|
|
70
|
+
# padded with silence to that end; the end is a frame time because a copied cut's stated
|
|
71
|
+
# video length can run past its last frame (7.517 s for frames ending at 7.5). One graph for
|
|
72
|
+
# both streams, as pad.py's padding needs. areverse keeps its input's timestamps in order,
|
|
73
|
+
# so the reversed sound is retimed by its samples. The hold (tpad) runs before av_trim's
|
|
74
|
+
# setpts: from FFmpeg 7.0 setpts leaves its output's frame rate unknown and its frames'
|
|
75
|
+
# durations 0, so a tpad after it clones nothing (the picture stayed 0.6 s short on 7.1);
|
|
76
|
+
# the closing fps gives the frames their durations back (frame_durations).
|
|
77
|
+
# the rate the encoder line delivers (cfr_args: a VFR source is conformed to its average
|
|
78
|
+
# rate), so the graph's closing fps and the output's -r are one grid: the graph closed on
|
|
79
|
+
# r_frame_rate and -r then resampled it, 51 frames for 49 that ran 81 ms past the sound (A234)
|
|
80
|
+
# The trim that drops the hold's spare clones stays on the source's own grid (half a frame
|
|
81
|
+
# of r_frame_rate before the end): half a delivered frame cut a real last frame that sits
|
|
82
|
+
# nearer the end than that, and reverse then opened on the one before it.
|
|
83
|
+
rate = delivered_rate(meta) or frame_rate(meta) or meta["video"].get("fps") or 30.0
|
|
84
|
+
length = av_clip_length(meta, rate)
|
|
85
|
+
vlen = meta["video"].get("duration") or length
|
|
86
|
+
end = math.ceil(length * rate - 1e-6) / rate
|
|
87
|
+
vtrim, atrim = av_trim(stream_starts(meta)[0], None)
|
|
88
|
+
conform = f"{reversed_conform}," if reversed_conform else ""
|
|
89
|
+
cmd += ["-filter_complex",
|
|
90
|
+
f"[0:v:0]tpad=stop_mode=clone:stop_duration={max(0.0, end - vlen) + 2 / rate:.6f},{vtrim},"
|
|
91
|
+
f"{conform}trim=end={end - 0.5 / max(rate, frame_rate(meta) or rate):.6f},reverse,{frame_durations(meta, rate)}[v];"
|
|
92
|
+
f"[0:a:0]{atrim},apad=whole_dur={end:.6f},atrim=end={end:.6f},areverse,asetpts=N/SR/TB[a]",
|
|
93
|
+
"-map", "[v]", "-map", "[a]"]
|
|
94
|
+
else:
|
|
95
|
+
cmd += ["-vf", f"{reversed_conform},reverse" if reversed_conform else "reverse"]
|
|
96
|
+
cmd += video_args(meta, args.crf, args.preset)
|
|
97
|
+
cmd += cfr_args(meta)
|
|
98
|
+
if has_audio:
|
|
99
|
+
cmd += aac_args()
|
|
100
|
+
else:
|
|
101
|
+
cmd += ["-an"]
|
|
102
|
+
span = float(meta.get("duration") or vdur or 0.0)
|
|
103
|
+
cmd = with_mapped_chapters(cmd, meta, lambda t: span - t, span) # chapters mirrored with the picture (#470)
|
|
104
|
+
cmd.append(output)
|
|
105
|
+
run(cmd)
|
|
106
|
+
|
|
107
|
+
result = probe(output, role="output")
|
|
108
|
+
info(f"wrote {output} ({fmt_secs(result['duration'])}, {result['video']['width']}x{result['video']['height']})")
|
|
109
|
+
emit(output)
|
|
110
|
+
return 0
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
if __name__ == "__main__":
|
|
114
|
+
sys.exit(main())
|