@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,121 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Add black video / silent audio at the start and/or end of a clip.
|
|
3
|
+
|
|
4
|
+
Distinct from fit.py --fit pad, which pads the FRAME (letterbox/pillarbox
|
|
5
|
+
bars around each existing frame to reach a target aspect ratio) -- this
|
|
6
|
+
tool pads the TIMELINE (extra seconds of solid colour and silence before
|
|
7
|
+
and/or after the clip's existing content). Common uses: a beat of black
|
|
8
|
+
before a title card starts, room for a fade-in, aligning a clip to a fixed
|
|
9
|
+
slot length.
|
|
10
|
+
|
|
11
|
+
Examples:
|
|
12
|
+
python3 pad.py clip.mp4 --start 1.5 # 1.5s of black+silence before the clip
|
|
13
|
+
python3 pad.py clip.mp4 --end 2 # 2s of black+silence after the clip
|
|
14
|
+
python3 pad.py clip.mp4 --start 1 --end 1 --color 0x101010
|
|
15
|
+
"""
|
|
16
|
+
import argparse
|
|
17
|
+
import sys
|
|
18
|
+
|
|
19
|
+
from _common.emit import note, record_fallback
|
|
20
|
+
from _common.decision import cfr_filter, delivered_rate, silence_filter, tpad_length
|
|
21
|
+
from _common.runner import declare_time_map, with_mapped_chapters
|
|
22
|
+
from _common import add_common, apply_common, aac_args, cfr_args, default_output, die, drawn_chain, emit, EVEN_SCALE, ffmpeg_base, info, probe, run_keeping_subtitles, validate_color, video_args, X264_PRESETS, time_arg, fmt_secs, run
|
|
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>_pad.<ext>)")
|
|
29
|
+
ap.add_argument("--start", default="0", help="padding to add before the clip: seconds or mm:ss (default 0)")
|
|
30
|
+
ap.add_argument("--end", default="0", help="padding to add after the clip: seconds or mm:ss (default 0)")
|
|
31
|
+
ap.add_argument("--color", default="black", help="padding colour (default black)")
|
|
32
|
+
ap.set_defaults(crf=18) # --quality's default (the --crf alias was removed in 2.0)
|
|
33
|
+
ap.add_argument("--preset", default="medium", choices=X264_PRESETS, help="x264 preset")
|
|
34
|
+
add_common(ap)
|
|
35
|
+
args = ap.parse_args()
|
|
36
|
+
apply_common(args)
|
|
37
|
+
|
|
38
|
+
args.start = time_arg(args.start, "--start")
|
|
39
|
+
args.end = time_arg(args.end, "--end")
|
|
40
|
+
if args.start < 0 or args.end < 0:
|
|
41
|
+
die(f"--start/--end must be >= 0, got start={args.start:g} end={args.end:g}")
|
|
42
|
+
if args.start == 0 and args.end == 0:
|
|
43
|
+
die("--start and/or --end must be > 0 (nothing to pad)")
|
|
44
|
+
validate_color(args.color, "--color")
|
|
45
|
+
|
|
46
|
+
meta = probe(args.input)
|
|
47
|
+
if not meta.get("video"):
|
|
48
|
+
die("input has no video stream")
|
|
49
|
+
has_audio = bool(meta.get("audio"))
|
|
50
|
+
output = args.output or default_output(args.input, "pad")
|
|
51
|
+
|
|
52
|
+
tpad = f"tpad=start_duration={args.start:.3f}:stop_duration={args.end:.3f}:color="
|
|
53
|
+
lead = tpad_length(args.start, meta)
|
|
54
|
+
# A VFR source is conformed first, by the fps filter ahead of the drawing (after a drawn
|
|
55
|
+
# chain's maskedmerge it lost the last frame, #512), and the padding ahead of the clip is whole
|
|
56
|
+
# frames of the delivered rate, which the sound waits as long as (#538). After tpad the filter
|
|
57
|
+
# ended a slot early: tpad's start pad passes its input's end on without the pad, so the
|
|
58
|
+
# filter ended the picture at its last frame's start (134 frames of 135 for --start 1 on a
|
|
59
|
+
# 27 fps average clip). Ahead of a pad counted by time the padding was rounded to the grid on
|
|
60
|
+
# top of the frames' own rounding (37 ms late, #512); counted in its frames and the sound
|
|
61
|
+
# delayed by them, it moves the conformed picture and its sound alike.
|
|
62
|
+
conform = cfr_filter(meta)
|
|
63
|
+
if conform:
|
|
64
|
+
rate = delivered_rate(meta)
|
|
65
|
+
frames = round(args.start * rate)
|
|
66
|
+
tpad, lead = f"tpad=start={frames}:stop_duration={args.end:.3f}:color=", frames / rate
|
|
67
|
+
# a --color with chroma lands in the BT.709 the output is tagged with (tpad's own YUV is BT.601
|
|
68
|
+
# before FFmpeg 7.1, and for an untagged picture after it); black is the same under every matrix
|
|
69
|
+
vf = drawn_chain(tpad + args.color, meta, [args.color], tpad + "black")
|
|
70
|
+
if conform:
|
|
71
|
+
vf = f"{conform},{vf}"
|
|
72
|
+
cmd = ffmpeg_base() + ["-i", args.input]
|
|
73
|
+
if has_audio:
|
|
74
|
+
# One -filter_complex, not a -vf and an -af: the ffmpeg scheduler of Ubuntu 26.04's 8.0.1 and
|
|
75
|
+
# conda-forge's 7.1.1 (not Debian's 7.1.5 or 8.1) deadlocks with no CPU use when one demuxer feeds two simple
|
|
76
|
+
# graphs and the audio one both delays its input and pads the tail. One graph reading both
|
|
77
|
+
# streams runs on 5.1-8.1 alike. run() only adds an even scale to a -vf, so add it here.
|
|
78
|
+
v = meta["video"]
|
|
79
|
+
even = EVEN_SCALE + "," if (v.get("width") or 0) % 2 or (v.get("height") or 0) % 2 else ""
|
|
80
|
+
if even:
|
|
81
|
+
# A239: the runner's retry records this when it adds the scale; here it is added up
|
|
82
|
+
# front (one -filter_complex), so the record is made here, as broll and stabilize do
|
|
83
|
+
record_fallback(f"{args.input} is {v.get('width')}x{v.get('height')}: scaled to even dimensions first",
|
|
84
|
+
"odd_dimensions_scaled_even", output=output, scale=EVEN_SCALE)
|
|
85
|
+
# The sound is delayed by what the picture is: tpad puts whole frames ahead of the clip
|
|
86
|
+
# (--start 0.23425 at 25 fps: 6 frames, 0.240 s), and a delay of --start itself moved the
|
|
87
|
+
# sound 5.75 ms ahead of its picture (tpad_length). The silence after the clip moves
|
|
88
|
+
# nothing and is --end as asked. Either is counted in samples when it is not a whole
|
|
89
|
+
# millisecond (silence_filter).
|
|
90
|
+
if abs(lead - args.start) > 1e-9:
|
|
91
|
+
note(f"--start {args.start:g}: the picture can only be padded by whole frames, {lead:.6f} s here; "
|
|
92
|
+
f"the sound is delayed by the same {lead:.6f} s so the clip keeps its sync")
|
|
93
|
+
af = silence_filter(meta["audio"].get("sample_rate"), lead, args.end)
|
|
94
|
+
cmd += ["-filter_complex", f"[0:v:0]{even}{vf}[v];[0:a:0]{af}[a]", "-map", "[v]", "-map", "[a]"]
|
|
95
|
+
else:
|
|
96
|
+
cmd += ["-vf", vf, "-map", "0:v:0"]
|
|
97
|
+
cmd += video_args(meta, args.crf, args.preset)
|
|
98
|
+
cmd += cfr_args(meta)
|
|
99
|
+
if has_audio:
|
|
100
|
+
cmd += aac_args()
|
|
101
|
+
else:
|
|
102
|
+
cmd += ["-an"]
|
|
103
|
+
if args.start > 0:
|
|
104
|
+
cmd = with_mapped_chapters(cmd, meta, lambda t: t + lead, None) # chapters move with the picture (#470)
|
|
105
|
+
# a stream-copied subtitle track keeps its timestamps and would fire --start seconds early
|
|
106
|
+
# (sweep F3); drop it and say so, as freeze --mode insert and fit --method speed do
|
|
107
|
+
run(cmd + [output])
|
|
108
|
+
dropped_streams = bool(meta.get("subtitle_streams") or meta.get("data_streams"))
|
|
109
|
+
else:
|
|
110
|
+
declare_time_map("clipped") # only a tail is added: every chapter keeps its time
|
|
111
|
+
dropped_streams = run_keeping_subtitles(cmd, output)
|
|
112
|
+
|
|
113
|
+
result = probe(output, role="output")
|
|
114
|
+
v = result["video"]
|
|
115
|
+
info(f"wrote {output} ({fmt_secs(result['duration'])}, {v['width']}x{v['height']}, +{args.start:g}s start / +{args.end:g}s end)")
|
|
116
|
+
emit(output, dropped_non_av_streams=dropped_streams)
|
|
117
|
+
return 0
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
if __name__ == "__main__":
|
|
121
|
+
sys.exit(main())
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Inspect a media file and print a compact JSON summary.
|
|
3
|
+
|
|
4
|
+
Reports duration, fps (and whether variable frame rate is suspected), resolution,
|
|
5
|
+
codecs, pixel format / color space, audio channels and sample rate.
|
|
6
|
+
|
|
7
|
+
Examples:
|
|
8
|
+
python3 probe.py input.mp4
|
|
9
|
+
python3 probe.py a.mp4 b.mov --compact
|
|
10
|
+
python3 probe.py input.mp4 --field duration
|
|
11
|
+
python3 probe.py input.mp4 --keyframes-near 12.4,47 --keyframe-window 5
|
|
12
|
+
|
|
13
|
+
--keyframes-near T[,T...] adds `keyframes`: for each time, the video keyframes within
|
|
14
|
+
--keyframe-window seconds of it, and the nearest one at or before it and at or after it -- the
|
|
15
|
+
points a stream copy can start at, and where cut.py --smart's re-encode around a cut ends.
|
|
16
|
+
"""
|
|
17
|
+
import argparse
|
|
18
|
+
import json
|
|
19
|
+
import math
|
|
20
|
+
import sys
|
|
21
|
+
|
|
22
|
+
from _common import STATE, add_common, analyze_levels, apply_common, die, keyframe_times, print_json, probe, time_arg
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def keyframe_candidates(result: dict, times: list, window: float) -> list:
|
|
26
|
+
"""For each time (seconds from the file's start), the keyframes within `window` of it and the
|
|
27
|
+
nearest of those at or before / at or after it (null when none is within the window), on the
|
|
28
|
+
same clock (the file's start_time subtracted). The picture is the stream probe() reports (`V`:
|
|
29
|
+
not a cover picture). A failed read is an error, not an empty neighbourhood."""
|
|
30
|
+
origin = float(result.get("start_time") or 0.0)
|
|
31
|
+
out = []
|
|
32
|
+
for t in times:
|
|
33
|
+
# keyframe_times() reads past hi (an interval's end is exclusive), so one on the edge is kept
|
|
34
|
+
read = keyframe_times(result["file"], origin + t - window, origin + t + window, "V:0")
|
|
35
|
+
if read is None:
|
|
36
|
+
die(f"ffprobe could not read the keyframes of {result['file']} around {t:g}s", kind="ffmpeg")
|
|
37
|
+
# the read starts at the keyframe at or before the window, which may lie outside it
|
|
38
|
+
keys = [k for k in (round(k - origin, 6) for k in read) if t - window - 1e-6 <= k <= t + window + 1e-6]
|
|
39
|
+
before = [k for k in keys if k <= t + 1e-6]
|
|
40
|
+
after = [k for k in keys if k >= t - 1e-6]
|
|
41
|
+
out.append({"at": t, "window": window, "keyframes": keys, "before": before[-1] if before else None,
|
|
42
|
+
"after": after[0] if after else None})
|
|
43
|
+
return out
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def main() -> int:
|
|
47
|
+
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
48
|
+
ap.add_argument("inputs", nargs="+", help="media file(s) to inspect")
|
|
49
|
+
ap.add_argument("--compact", action="store_true", help="one human-readable line per file instead of JSON")
|
|
50
|
+
ap.add_argument("--field", help="print only this top-level field (e.g. duration) or dotted path (video.fps)")
|
|
51
|
+
ap.add_argument("--analyze", action="store_true", help="also sample picture levels (first 20 s) and flag Log-looking footage")
|
|
52
|
+
ap.add_argument("--keyframes-near", metavar="T[,T...]",
|
|
53
|
+
help="also list the video keyframes around these times (seconds, mm:ss or hh:mm:ss.ms): the ones within "
|
|
54
|
+
"--keyframe-window and the nearest before and after each, as `keyframes`")
|
|
55
|
+
ap.add_argument("--keyframe-window", type=float, default=5.0, metavar="S",
|
|
56
|
+
help="--keyframes-near: seconds either side of each time to read (default 5)")
|
|
57
|
+
add_common(ap) # --json / --dry-run / --fast / --progress accepted for uniformity; output is JSON already
|
|
58
|
+
args = ap.parse_args()
|
|
59
|
+
apply_common(args)
|
|
60
|
+
|
|
61
|
+
if not math.isfinite(args.keyframe_window) or args.keyframe_window <= 0:
|
|
62
|
+
die(f"--keyframe-window must be a positive, finite number of seconds, got {args.keyframe_window:g}")
|
|
63
|
+
if args.keyframes_near is not None and not any(t.strip() for t in args.keyframes_near.split(",")):
|
|
64
|
+
die("--keyframes-near takes one or more times (e.g. 12.4,47), got none")
|
|
65
|
+
results = [probe(p) for p in args.inputs]
|
|
66
|
+
for result in results:
|
|
67
|
+
if result.get("dry_run"):
|
|
68
|
+
# The shared probe's zero-valued stub supports planning arithmetic. It carries
|
|
69
|
+
# no measurements to publish through the CLI or MCP.
|
|
70
|
+
for key in ("duration", "size_bytes", "video", "audio", "subtitle_streams", "data_streams"):
|
|
71
|
+
result[key] = None
|
|
72
|
+
if args.keyframes_near:
|
|
73
|
+
for r in results:
|
|
74
|
+
fps = (r.get("video") or {}).get("fps")
|
|
75
|
+
times = [time_arg(t.strip(), "--keyframes-near", fps) for t in args.keyframes_near.split(",") if t.strip()]
|
|
76
|
+
if any(not math.isfinite(t) or t < 0 for t in times):
|
|
77
|
+
die("--keyframes-near takes finite times at or after 0")
|
|
78
|
+
if r.get("dry_run"):
|
|
79
|
+
continue
|
|
80
|
+
r["keyframes"] = keyframe_candidates(r, times, args.keyframe_window) if r.get("video") else []
|
|
81
|
+
if args.analyze:
|
|
82
|
+
for r in results:
|
|
83
|
+
if r.get("video"):
|
|
84
|
+
r["levels"] = analyze_levels(r["file"])
|
|
85
|
+
transfer = r["video"].get("color_transfer")
|
|
86
|
+
if r["video"].get("hdr") and "error" not in r["levels"]:
|
|
87
|
+
# the guess is "flat and desaturated, yet tagged SDR": a PQ/HLG stream is not
|
|
88
|
+
# tagged SDR, and its code values were read as if they were (#403)
|
|
89
|
+
r["levels"]["looks_like_log"] = None
|
|
90
|
+
r["levels"]["reason"] = "not_measured: the stream is tagged HDR (%s), and the Log guess is made for an SDR-tagged picture" % (transfer or r["video"].get("hdr_format") or "HDR")
|
|
91
|
+
r["levels"]["note"] = ("the stream is tagged HDR (%s): these are its code values on an 8-bit scale, not display-referred SDR levels, "
|
|
92
|
+
"and whether it looks like Log was not judged" % (transfer or r["video"].get("hdr_format") or "HDR"))
|
|
93
|
+
|
|
94
|
+
if args.field:
|
|
95
|
+
for r in results:
|
|
96
|
+
cur = r
|
|
97
|
+
for key in args.field.split("."):
|
|
98
|
+
cur = cur.get(key) if isinstance(cur, dict) else None
|
|
99
|
+
# a string as itself; anything else as JSON (true, null, {"codec": ...}), not Python's
|
|
100
|
+
# repr (True, None, {'codec': ...}), which no caller can parse (through 3.8.8, A123).
|
|
101
|
+
# Under --json (or --json-brief, which implies it) a missing field is null and a string
|
|
102
|
+
# is quoted: every line is JSON. Without either a missing field is an empty line, as it
|
|
103
|
+
# always was, so `[ -z "$(probe.py f --field x)" ]` keeps working
|
|
104
|
+
if isinstance(cur, str) and not STATE.json:
|
|
105
|
+
print(cur)
|
|
106
|
+
elif cur is None and not STATE.json:
|
|
107
|
+
print("")
|
|
108
|
+
else:
|
|
109
|
+
print(json.dumps(cur, ensure_ascii=False))
|
|
110
|
+
return 0
|
|
111
|
+
|
|
112
|
+
if args.compact:
|
|
113
|
+
for r in results:
|
|
114
|
+
if r.get("dry_run"):
|
|
115
|
+
print(f"{r['file']}: not measured (pending input)")
|
|
116
|
+
continue
|
|
117
|
+
v, a = r.get("video") or {}, r.get("audio") or {}
|
|
118
|
+
dur = r.get("duration")
|
|
119
|
+
line = f"{r['file']}: {dur:.3f}s" if dur is not None else f"{r['file']}: ?s"
|
|
120
|
+
if v:
|
|
121
|
+
line += f" | {v.get('width')}x{v.get('height')} @ {v.get('fps')}fps {v.get('codec')} {v.get('pix_fmt')}"
|
|
122
|
+
if v.get("variable_frame_rate_suspected"):
|
|
123
|
+
line += " (VFR?)"
|
|
124
|
+
if v.get("bt2020_or_hdr"): # hdr_format also names the BT.2020 SDR case
|
|
125
|
+
line += f" [{v.get('hdr_format')}]"
|
|
126
|
+
if r.get("levels", {}).get("looks_like_log"):
|
|
127
|
+
line += " [Log?]"
|
|
128
|
+
else:
|
|
129
|
+
line += " | no video"
|
|
130
|
+
if a:
|
|
131
|
+
line += f" | audio {a.get('codec')} {a.get('channels')}ch {a.get('sample_rate')}Hz"
|
|
132
|
+
else:
|
|
133
|
+
line += " | no audio"
|
|
134
|
+
for k in r.get("keyframes") or []:
|
|
135
|
+
before, after = ("-" if x is None else f"{x:g}" for x in (k["before"], k["after"]))
|
|
136
|
+
line += f" | keyframes near {k['at']:g}s: {before}/{after} ({len(k['keyframes'])} within {k['window']:g}s)"
|
|
137
|
+
print(line)
|
|
138
|
+
return 0
|
|
139
|
+
|
|
140
|
+
print_json(results[0] if len(results) == 1 else results)
|
|
141
|
+
return 0
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
if __name__ == "__main__":
|
|
145
|
+
sys.exit(main())
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Generate a small, low-bitrate proxy of a video: cheap for a machine to decode,
|
|
3
|
+
not meant for delivery. Intended for downstream AI analysis, preview or
|
|
4
|
+
editing-decision workflows that only need to look at (or feed a model) a
|
|
5
|
+
much smaller stand-in for the original.
|
|
6
|
+
|
|
7
|
+
Resizes to --width (default 640px, height follows the source aspect) or by
|
|
8
|
+
--scale factor, never wider than the source (a proxy is not upscaled) and
|
|
9
|
+
never under 2px, re-encodes at a proxy-grade --quality (default 30 - well above any
|
|
10
|
+
delivery preset's 18-24 in export.py, since a proxy trades visual quality for
|
|
11
|
+
size and speed), and always uses the fastest x264/x265 preset. Keeps the
|
|
12
|
+
source's own dynamic range (an HDR source proxies to HEVC10, same as every
|
|
13
|
+
other re-encoding tool here) rather than guessing whether SDR is wanted -
|
|
14
|
+
run color.py --to-sdr first if it is.
|
|
15
|
+
|
|
16
|
+
This tool only executes the spec it is given: it does not decide which asset
|
|
17
|
+
should be proxied, what resolution or bitrate is "right" for a given
|
|
18
|
+
downstream use, or what the proxy will be used for - those are the calling
|
|
19
|
+
agent's call.
|
|
20
|
+
|
|
21
|
+
Examples:
|
|
22
|
+
python3 proxy.py input.mov # 640px wide, CRF 30, keeps audio
|
|
23
|
+
python3 proxy.py input.mov --width 480 --no-audio # smaller, video-only
|
|
24
|
+
python3 proxy.py input.mov --scale 0.25 --fps 10 # quarter-size, 10fps (e.g. for a vision model)
|
|
25
|
+
"""
|
|
26
|
+
import argparse
|
|
27
|
+
import sys
|
|
28
|
+
|
|
29
|
+
from _common import add_common, apply_common, cfr_args, with_cfr, default_output, die, emit, ffmpeg_base, info, probe, run_keeping_subtitles, video_args, fmt_secs
|
|
30
|
+
from _common.emit import note
|
|
31
|
+
from _common.probe import display_size, square_pixels, square_pixels_note
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def even(n: float) -> int:
|
|
35
|
+
v = int(round(n))
|
|
36
|
+
return v if v % 2 == 0 else v + 1
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def main() -> int:
|
|
40
|
+
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
41
|
+
ap.add_argument("input")
|
|
42
|
+
ap.add_argument("-o", "--output", help="output file (default: <name>_proxy.<ext>)")
|
|
43
|
+
ap.add_argument("--width", type=int, default=640, help="output width in px, 1..16384, height follows the source aspect (default 640)")
|
|
44
|
+
ap.add_argument("--height", type=int, help="output height in px, 2..16384, instead of --width: the width follows the source aspect")
|
|
45
|
+
ap.add_argument("--scale", type=float, help="scale factor applied to the source dimensions instead of --width (0 < scale <= 1)")
|
|
46
|
+
ap.set_defaults(crf=30) # --quality's default (the --crf alias was removed in 2.0)
|
|
47
|
+
ap.add_argument("--fps", type=float, help="force a constant output frame rate")
|
|
48
|
+
ap.add_argument("--no-audio", action="store_true", help="drop audio entirely (default: keep it)")
|
|
49
|
+
add_common(ap)
|
|
50
|
+
args = ap.parse_args()
|
|
51
|
+
apply_common(args)
|
|
52
|
+
|
|
53
|
+
if args.scale is not None and not 0.0 < args.scale <= 1.0:
|
|
54
|
+
die(f"--scale must be > 0 and <= 1, got {args.scale}")
|
|
55
|
+
if args.fps is not None and args.fps <= 0:
|
|
56
|
+
die(f"--fps must be > 0, got {args.fps}")
|
|
57
|
+
|
|
58
|
+
meta = probe(args.input)
|
|
59
|
+
if not meta.get("video"):
|
|
60
|
+
die("input has no video stream")
|
|
61
|
+
# the displayed width: rotation applied, non-square pixels squared first (#411)
|
|
62
|
+
sw, sh = display_size(meta["video"])
|
|
63
|
+
square = square_pixels(meta["video"])
|
|
64
|
+
if square:
|
|
65
|
+
note(square_pixels_note(meta["video"]))
|
|
66
|
+
has_audio = bool(meta.get("audio")) and not args.no_audio
|
|
67
|
+
|
|
68
|
+
# A proxy is never wider than its source, and never under 2 px: through 3.8.8 the default
|
|
69
|
+
# --width 640 upscaled a smaller source, and a --scale that rounded to 0 became scale=0, which
|
|
70
|
+
# ffmpeg reads as "the input's width" (a full-size proxy, audit A162)
|
|
71
|
+
asked = even(sw * args.scale) if args.scale is not None else even(args.height * sw / sh) if args.height and sh else even(args.width)
|
|
72
|
+
ceiling = max(2, sw - sw % 2) if sw else asked
|
|
73
|
+
out_w = max(2, min(asked, ceiling))
|
|
74
|
+
if out_w != asked:
|
|
75
|
+
note(f"proxy width {out_w}px, not {asked}px: "
|
|
76
|
+
+ (f"the source is {sw}px wide and a proxy is not upscaled" if asked > ceiling else "2px is the smallest width"))
|
|
77
|
+
output = args.output or default_output(args.input, "proxy")
|
|
78
|
+
|
|
79
|
+
cmd = ffmpeg_base() + ["-i", args.input, "-vf", with_cfr((square + "," if square else "") + f"scale={out_w}:-2", meta, args.fps)]
|
|
80
|
+
cmd += video_args(meta, args.crf, "veryfast")
|
|
81
|
+
cmd += cfr_args(meta, args.fps)
|
|
82
|
+
cmd += ["-map", "0:v:0"] + (["-map", "0:a:0", "-c:a", "aac", "-b:a", "96k"] if has_audio else ["-an"])
|
|
83
|
+
dropped_streams = run_keeping_subtitles(cmd, output)
|
|
84
|
+
|
|
85
|
+
result = probe(output)
|
|
86
|
+
v = result["video"]
|
|
87
|
+
info(f"wrote {output} ({fmt_secs(result['duration'])}, {v['width']}x{v['height']}, {v['codec']}, crf {args.crf})")
|
|
88
|
+
emit(output, dropped_non_av_streams=dropped_streams)
|
|
89
|
+
return 0
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
if __name__ == "__main__":
|
|
93
|
+
sys.exit(main())
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Blur, pixelate, or interpolate away an exact pixel rectangle for the whole clip.
|
|
3
|
+
|
|
4
|
+
{x, y, width, height} are literal pixel offsets and dimensions in the SOURCE
|
|
5
|
+
frame, the same convention as crop.py -- this tool needs the rectangle
|
|
6
|
+
already known (a saved detection box, a hand-picked region); it does not
|
|
7
|
+
locate faces, plates, logos or burned-in text itself. The rest of the frame
|
|
8
|
+
is untouched.
|
|
9
|
+
|
|
10
|
+
--mode blur (default) applies a strong box blur inside the rectangle;
|
|
11
|
+
--mode pixelate mosaics it into large blocks -- the more recognisable,
|
|
12
|
+
unmistakably-redacted look often wanted for compliance/legal footage.
|
|
13
|
+
--mode delogo fills the rectangle from the picture around it (ffmpeg's
|
|
14
|
+
delogo filter): a fixed logo or burned-in line, not inpainting, and not a
|
|
15
|
+
region that moves. delogo reads a 1 px ring outside the box, so the box
|
|
16
|
+
cannot touch the frame edge, and it only interpolates 8-bit YUV (an HDR or
|
|
17
|
+
10-bit source is refused; color.py --to-sdr first).
|
|
18
|
+
The region stays one mode for the whole clip; for a region that only needs
|
|
19
|
+
covering part of the timeline, cut the clip into segments first (cut.py)
|
|
20
|
+
and redact only the relevant one.
|
|
21
|
+
|
|
22
|
+
Examples:
|
|
23
|
+
python3 redact.py interview.mp4 --x 820 --y 140 --width 240 --height 240
|
|
24
|
+
python3 redact.py dashcam.mp4 --x 0 --y 900 --width 400 --height 120 --mode pixelate --block-size 16
|
|
25
|
+
python3 redact.py branded.mp4 --x 40 --y 20 --width 180 --height 60 --mode delogo
|
|
26
|
+
"""
|
|
27
|
+
import argparse
|
|
28
|
+
import re
|
|
29
|
+
import sys
|
|
30
|
+
|
|
31
|
+
from _common import add_common, overlay_format, apply_common, aac_args, cfr_args, cfr_at_input, with_cfr, default_output, die, emit, ffmpeg_base, info, probe, run_keeping_subtitles, video_args, X264_PRESETS, fmt_secs
|
|
32
|
+
from _common.emit import note
|
|
33
|
+
from _common.probe import display_size, square_pixels, square_pixels_note
|
|
34
|
+
from _common.decision import boxblur_chroma_radius
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def main() -> int:
|
|
38
|
+
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
39
|
+
ap.add_argument("input")
|
|
40
|
+
ap.add_argument("-o", "--output", help="output file (default: <name>_redact.<ext>)")
|
|
41
|
+
ap.add_argument("--rect", metavar="X:Y:W:H", help="the rectangle in one value (left:top:width:height, in source pixels), instead of the four options below")
|
|
42
|
+
ap.add_argument("--x", type=int, help="left edge of the rectangle, in source pixels")
|
|
43
|
+
ap.add_argument("--y", type=int, help="top edge of the rectangle, in source pixels")
|
|
44
|
+
ap.add_argument("--width", type=int, help="rectangle width in px (must be even)")
|
|
45
|
+
ap.add_argument("--height", type=int, help="rectangle height in px (must be even)")
|
|
46
|
+
ap.add_argument("--mode", choices=["blur", "pixelate", "delogo"], default="blur",
|
|
47
|
+
help="blur (default), pixelate, or delogo (interpolate a fixed rectangle away; not inpainting, and not a moving region)")
|
|
48
|
+
ap.add_argument("--blur-strength", type=int, default=20, help="box-blur radius in px, --mode blur only (default 20)")
|
|
49
|
+
ap.add_argument("--block-size", type=int, default=12, help="mosaic block size in px, --mode pixelate only (default 12)")
|
|
50
|
+
ap.add_argument("--audio-stream", type=int, default=0,
|
|
51
|
+
help="which audio stream of the input to keep, 0-based in file order (default 0)")
|
|
52
|
+
ap.set_defaults(crf=18) # --quality's default (the --crf alias was removed in 2.0)
|
|
53
|
+
ap.add_argument("--preset", default="medium", choices=X264_PRESETS, help="x264 preset")
|
|
54
|
+
ap.add_argument("--fps", type=float, help="force a constant output frame rate (recommended for VFR sources)")
|
|
55
|
+
add_common(ap)
|
|
56
|
+
args = ap.parse_args()
|
|
57
|
+
apply_common(args)
|
|
58
|
+
if args.fps is not None and args.fps <= 0:
|
|
59
|
+
die(f"--fps must be positive, got {args.fps:g}")
|
|
60
|
+
|
|
61
|
+
if args.rect and re.fullmatch(r"\d+([:,x]\d+){3}", args.rect):
|
|
62
|
+
args.x, args.y, args.width, args.height = (int(n) for n in re.split("[:,x]", args.rect))
|
|
63
|
+
if None in (args.x, args.y, args.width, args.height):
|
|
64
|
+
die("give the rectangle as --rect X:Y:W:H (four whole numbers) or as --x --y --width --height")
|
|
65
|
+
if args.x < 0 or args.y < 0:
|
|
66
|
+
die(f"--x/--y must be >= 0, got x={args.x} y={args.y}")
|
|
67
|
+
if args.width <= 0 or args.height <= 0:
|
|
68
|
+
die(f"--width/--height must be > 0, got width={args.width} height={args.height}")
|
|
69
|
+
if args.width % 2 or args.height % 2:
|
|
70
|
+
die(f"--width/--height must be even (4:2:0 chroma), got width={args.width} height={args.height}")
|
|
71
|
+
if args.blur_strength <= 0:
|
|
72
|
+
die(f"--blur-strength must be > 0, got {args.blur_strength}")
|
|
73
|
+
if args.block_size <= 1:
|
|
74
|
+
die(f"--block-size must be > 1, got {args.block_size}")
|
|
75
|
+
|
|
76
|
+
meta = probe(args.input)
|
|
77
|
+
if not meta.get("video"):
|
|
78
|
+
die("input has no video stream")
|
|
79
|
+
# the rectangle is in the displayed frame: rotation applied, and a non-square-pixel source
|
|
80
|
+
# squared at its display aspect first (#411), the frame look.py and cropdetect.py show
|
|
81
|
+
sw, sh = display_size(meta["video"])
|
|
82
|
+
square = square_pixels(meta["video"])
|
|
83
|
+
if square:
|
|
84
|
+
note(square_pixels_note(meta["video"]))
|
|
85
|
+
if args.x + args.width > sw or args.y + args.height > sh:
|
|
86
|
+
die(f"redaction rectangle ({args.x},{args.y},{args.width}x{args.height}) exceeds the source frame ({sw}x{sh})")
|
|
87
|
+
if args.mode == "delogo":
|
|
88
|
+
# delogo's band is fixed at 1 px (the option was removed; 5.1 through current all
|
|
89
|
+
# expand the box by that ring and refuse it when the ring leaves the frame).
|
|
90
|
+
vinfo = meta["video"]
|
|
91
|
+
if vinfo.get("bt2020_or_hdr") or (vinfo.get("bit_depth") or 8) > 8:
|
|
92
|
+
die(f"--mode delogo interpolates 8-bit YUV only (this source is {vinfo.get('pix_fmt') or 'not 8-bit'}); "
|
|
93
|
+
"color.py --to-sdr first")
|
|
94
|
+
if args.x < 1 or args.y < 1 or args.x + args.width >= sw or args.y + args.height >= sh:
|
|
95
|
+
die(f"--mode delogo needs a 1 px ring of picture around the rectangle "
|
|
96
|
+
f"({args.x},{args.y},{args.width}x{args.height} in {sw}x{sh}); "
|
|
97
|
+
"a logo on the frame edge is out of range")
|
|
98
|
+
has_audio = bool(meta.get("audio"))
|
|
99
|
+
audio_streams = meta.get("audio_streams") or []
|
|
100
|
+
if audio_streams and not (0 <= args.audio_stream < len(audio_streams)):
|
|
101
|
+
die(f"--audio-stream {args.audio_stream}: input has {len(audio_streams)} audio stream(s), 0..{len(audio_streams) - 1}")
|
|
102
|
+
if args.audio_stream and not audio_streams:
|
|
103
|
+
die("--audio-stream needs an input with audio streams")
|
|
104
|
+
|
|
105
|
+
output = args.output or default_output(args.input, "redact")
|
|
106
|
+
if args.mode == "delogo":
|
|
107
|
+
cmd = ffmpeg_base() + ["-i", args.input, "-vf",
|
|
108
|
+
with_cfr((square + "," if square else "") + f"delogo=x={args.x}:y={args.y}:w={args.width}:h={args.height}",
|
|
109
|
+
meta, args.fps),
|
|
110
|
+
"-map", "0:v:0"]
|
|
111
|
+
else:
|
|
112
|
+
# exact=1: crop rounds an odd x/y down to the chroma grid of a 4:2:0 frame otherwise, and
|
|
113
|
+
# overlay always does, so an odd rectangle was taken from and put back one pixel up and
|
|
114
|
+
# left (its last column and row left as they were, one outside it changed: A170). The
|
|
115
|
+
# patch is taken exactly, given a transparent first column/row where x/y is odd, and put
|
|
116
|
+
# at the even position before it: the luma inside the rectangle is replaced, the luma
|
|
117
|
+
# outside is not (the chroma pair on an odd edge is shared, so it is half mixed)
|
|
118
|
+
crop = f"crop={args.width}:{args.height}:{args.x}:{args.y}:exact=1"
|
|
119
|
+
ox, oy = args.x % 2, args.y % 2
|
|
120
|
+
if args.mode == "blur":
|
|
121
|
+
# boxblur refuses a radius above half the plane: the chroma planes of 4:2:0 are half-size,
|
|
122
|
+
# so they get their own (halved) radius; a 30 px region with the default 20 used to fail
|
|
123
|
+
radius = max(1, min(args.blur_strength, min(args.width, args.height) // 2 - 1))
|
|
124
|
+
# at least 1 wherever the chroma plane can hold it: radius // 2 alone was 0 at
|
|
125
|
+
# --blur-strength 1, which left colour-only detail readable (review of #521). (FFmpeg
|
|
126
|
+
# 7.1 refuses a chroma radius of 1 on a 2 px chroma plane, a 4 px wide region; 6.1
|
|
127
|
+
# took it.) 0 is only a plane too small to blur: the luma still is
|
|
128
|
+
# On the chroma planes' own size, which boxblur measures: a 4:1:1 or 4:1:0 source's
|
|
129
|
+
# quarter-width planes failed at the 4:2:0 bound (a 30x30 region: "radius 7, must be
|
|
130
|
+
# <= 3", #527's sweep). On 4:2:0 the radius is the one it was
|
|
131
|
+
chroma = boxblur_chroma_radius(max(1, radius // 2))
|
|
132
|
+
region = f"{crop},boxblur={radius}:{radius}:{chroma}:{radius}"
|
|
133
|
+
else:
|
|
134
|
+
region = f"{crop},scale={max(1, args.width // args.block_size)}:{max(1, args.height // args.block_size)}:flags=neighbor,scale={args.width}:{args.height}:flags=neighbor"
|
|
135
|
+
if ox or oy:
|
|
136
|
+
deep = overlay_format(meta)
|
|
137
|
+
region += (f",format=yuva444p{'10le' if deep else ''},"
|
|
138
|
+
f"pad={args.width + 2 * ox}:{args.height + 2 * oy}:{ox}:{oy}:color=black@0")
|
|
139
|
+
fc = (f"[0:v]{square + ',' if square else ''}split=2[base][region];[region]{region}[patched];"
|
|
140
|
+
f"[base][patched]overlay={args.x - ox}:{args.y - oy}{overlay_format(meta)}[out]")
|
|
141
|
+
# a VFR source (or --fps) is conformed by the fps filter as it is decoded (#512)
|
|
142
|
+
fc = cfr_at_input(fc, meta, args.fps)
|
|
143
|
+
cmd = ffmpeg_base() + ["-i", args.input, "-filter_complex", fc, "-map", "[out]"]
|
|
144
|
+
if has_audio:
|
|
145
|
+
cmd += ["-map", f"0:a:{args.audio_stream}?"]
|
|
146
|
+
cmd += video_args(meta, args.crf, args.preset)
|
|
147
|
+
cmd += cfr_args(meta, args.fps)
|
|
148
|
+
if has_audio:
|
|
149
|
+
cmd += aac_args()
|
|
150
|
+
else:
|
|
151
|
+
cmd += ["-an"]
|
|
152
|
+
dropped_streams = run_keeping_subtitles(cmd, output)
|
|
153
|
+
|
|
154
|
+
result = probe(output, role="output")
|
|
155
|
+
v = result["video"]
|
|
156
|
+
info(f"wrote {output} ({fmt_secs(result['duration'])}, {v['width']}x{v['height']}, {args.mode} at x={args.x} y={args.y} {args.width}x{args.height})")
|
|
157
|
+
emit(output, dropped_non_av_streams=dropped_streams)
|
|
158
|
+
return 0
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
if __name__ == "__main__":
|
|
162
|
+
sys.exit(main())
|