@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,282 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Cut away to clip B over clip A for a while, then come back -- A's timeline unchanged.
|
|
3
|
+
|
|
4
|
+
"Cut to the product shot from 0:12 to 0:16, keep my voice underneath" is the
|
|
5
|
+
classic B-roll instruction. A plays as it is; during each window B's picture is
|
|
6
|
+
shown instead (scaled/padded to A's frame like join.py normalises), and A resumes
|
|
7
|
+
at its own time when the window ends. This is a cutaway, not a splice: the output
|
|
8
|
+
is exactly as long as A, and A is re-encoded once.
|
|
9
|
+
|
|
10
|
+
--insert/--at come in pairs, once per cutaway; --duration (or --end) and --from
|
|
11
|
+
(where in B to start) are per cutaway too and default to 4 s and 0. --audio says
|
|
12
|
+
what plays under a cutaway: `a` (default, A's own audio untouched, stream-copied),
|
|
13
|
+
`b` (B's audio replaces A's inside the window), or `mix` (both).
|
|
14
|
+
|
|
15
|
+
Examples:
|
|
16
|
+
python3 broll.py talk.mp4 --insert product.mp4 --at 12 --duration 4
|
|
17
|
+
python3 broll.py talk.mp4 --insert shot1.mp4 --at 12 --end 16 --insert shot2.mp4 --at 40 --from 2
|
|
18
|
+
python3 broll.py talk.mp4 --insert demo.mp4 --at 30 --duration 8 --audio mix
|
|
19
|
+
"""
|
|
20
|
+
import argparse
|
|
21
|
+
import math
|
|
22
|
+
import sys
|
|
23
|
+
from typing import Any, Dict, List
|
|
24
|
+
|
|
25
|
+
from _common.decision import (av_trim, conform_output_t, conform_to_length, frame_durations, frame_rate, frame_window,
|
|
26
|
+
grid_at_or_after, on_frame, silence_filter, stream_starts, window_expr, windowed_overlay_x)
|
|
27
|
+
from _common import STATE, add_common, aac_args, apply_common, cfr_args, cfr_at_input, as_limited, default_output, die, draws_chroma, drawn_chain, emit, ffmpeg_base, info, time_arg, mix_color_chains, overlay_format, probe, run, validate_color, video_args, X264_PRESETS, fmt_secs
|
|
28
|
+
from _common.emit import note, record_fallback
|
|
29
|
+
from _common.probe import display_size, is_still_input, square_pixels, square_pixels_note, still_loop_args
|
|
30
|
+
from _common.emit import input_length
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
MIX_RATE = 48000 # every layer of a b/mix sound is resampled to it before the mix
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def main() -> int:
|
|
37
|
+
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
38
|
+
ap.add_argument("input", help="the A-roll (its timeline and length are kept)")
|
|
39
|
+
ap.add_argument("-o", "--output", help="output file (default: <name>_broll.<ext>)")
|
|
40
|
+
ap.add_argument("--insert", "--broll", action="append", required=True, metavar="B", help="B-roll clip (repeat with --at for several cutaways)")
|
|
41
|
+
ap.add_argument("--at", "--start", action="append", required=True, metavar="TIME", help="where in A the cutaway starts (seconds or mm:ss); one per --insert")
|
|
42
|
+
ap.add_argument("--duration", action="append", metavar="T", help="cutaway length (default 4); one per --insert, or omit")
|
|
43
|
+
ap.add_argument("--end", action="append", metavar="TIME", help="where in A the cutaway ends, instead of --duration")
|
|
44
|
+
ap.add_argument("--from", dest="from_", action="append", metavar="TIME", help="where in B to start from (default 0); one per --insert, or omit")
|
|
45
|
+
ap.add_argument("--audio", choices=["a", "b", "mix"], default="a", help="under a cutaway: A's audio (default), B's audio, or both mixed")
|
|
46
|
+
ap.add_argument("--pad-color", default="black", help="pad colour when B's aspect differs from A's (default black)")
|
|
47
|
+
ap.set_defaults(crf=18) # --quality's default (the --crf alias was removed in 2.0)
|
|
48
|
+
ap.add_argument("--preset", default="medium", choices=X264_PRESETS, help="x264 preset")
|
|
49
|
+
add_common(ap)
|
|
50
|
+
args = ap.parse_args()
|
|
51
|
+
apply_common(args)
|
|
52
|
+
validate_color(args.pad_color, "--pad-color")
|
|
53
|
+
|
|
54
|
+
n = len(args.insert)
|
|
55
|
+
if len(args.at) != n:
|
|
56
|
+
die(f"{n} --insert but {len(args.at)} --at: give one --at per --insert")
|
|
57
|
+
for name, values in (("--duration", args.duration), ("--end", args.end), ("--from", args.from_)):
|
|
58
|
+
if values and len(values) not in (1, n):
|
|
59
|
+
die(f"{name} given {len(values)} times for {n} cutaways: give it once per --insert, or once for all, or not at all")
|
|
60
|
+
if args.duration and args.end:
|
|
61
|
+
die("--duration and --end exclude each other")
|
|
62
|
+
|
|
63
|
+
meta_a = probe(args.input)
|
|
64
|
+
if not meta_a.get("video"):
|
|
65
|
+
die("A-roll has no video stream")
|
|
66
|
+
dur_a = input_length(meta_a)
|
|
67
|
+
# the cutaway is scaled onto the frame ffmpeg has already rotated, not the stored one, and
|
|
68
|
+
# onto a non-square-pixel A-roll squared at its display aspect (#411)
|
|
69
|
+
w, h = display_size(meta_a["video"])
|
|
70
|
+
a_chain = square_pixels(meta_a["video"])
|
|
71
|
+
if a_chain:
|
|
72
|
+
note(square_pixels_note(meta_a["video"], "the A-roll"))
|
|
73
|
+
if (w % 2 or h % 2) and w and h:
|
|
74
|
+
# an odd-sized A-roll cannot be encoded 4:2:0 at its own size, and the run-time even-scale
|
|
75
|
+
# retry does not reach a filter_complex: through 3.1.3 this failed as kind "ffmpeg" (#411)
|
|
76
|
+
ew, eh = max(2, w - w % 2), max(2, h - h % 2) # never 0, which scale reads as "keep" (#416 review)
|
|
77
|
+
record_fallback(f"the A-roll is {w}x{h}, which 4:2:0 cannot hold: scaled to {ew}x{eh}",
|
|
78
|
+
"odd_dimensions_scaled_even", output=args.output or default_output(args.input, "broll"), scale=f"scale={ew}:{eh}")
|
|
79
|
+
a_chain = (a_chain + "," if a_chain else "") + f"scale={ew}:{eh},setsar=1"
|
|
80
|
+
w, h = ew, eh
|
|
81
|
+
fps = meta_a["video"].get("fps") or 30.0
|
|
82
|
+
# the A-roll's frame grid, when it has one (frame_window): its exact rate and where it starts
|
|
83
|
+
grid = frame_window(0.0, None, meta_a) is not None
|
|
84
|
+
rate_a, v0a = frame_rate(meta_a), stream_starts(meta_a)[0]
|
|
85
|
+
fps_filter = frame_durations(meta_a, rate_a) # fps=30000/1001; a whole rate reads as it did (fps=25)
|
|
86
|
+
fps_filter = fps_filter[:-2] if fps_filter.endswith("/1") else fps_filter
|
|
87
|
+
has_audio_a = bool(meta_a.get("audio"))
|
|
88
|
+
|
|
89
|
+
def per(values: List[str], i: int, default: str) -> str:
|
|
90
|
+
if not values:
|
|
91
|
+
return default
|
|
92
|
+
return values[i] if len(values) == n else values[0]
|
|
93
|
+
|
|
94
|
+
cutaways: List[Dict[str, Any]] = []
|
|
95
|
+
for i, path in enumerate(args.insert):
|
|
96
|
+
meta_b = probe(path)
|
|
97
|
+
if not meta_b.get("video"):
|
|
98
|
+
die(f"{path} has no video stream")
|
|
99
|
+
at = time_arg(args.at[i], "--at", fps, source=meta_a)
|
|
100
|
+
start_b = time_arg(per(args.from_, i, "0"), "--from", fps, source=meta_b)
|
|
101
|
+
if args.end:
|
|
102
|
+
end = time_arg(per(args.end, i, "0"), "--end", fps, source=meta_a)
|
|
103
|
+
length = end - at
|
|
104
|
+
else:
|
|
105
|
+
length = time_arg(per(args.duration, i, "4"), "--duration", fps, source=meta_a)
|
|
106
|
+
if length <= 0:
|
|
107
|
+
die(f"cutaway {i + 1}: length must be > 0 (at {at:g}s, got {length:g}s)")
|
|
108
|
+
if dur_a and at >= dur_a:
|
|
109
|
+
die(f"cutaway {i + 1}: --at {at:g}s is past the end of the A-roll ({dur_a:.3f}s)")
|
|
110
|
+
if dur_a and at + length > dur_a + 0.01:
|
|
111
|
+
die(f"cutaway {i + 1}: {at:g}s + {length:g}s runs past the end of the A-roll ({dur_a:.3f}s)")
|
|
112
|
+
# a still has no material to run out of: it is looped for the window. image2 gives some (a
|
|
113
|
+
# TGA) a duration of one frame, which this refused as "only -0.460s from 0.5s" (review of #532)
|
|
114
|
+
dur_b = None if is_still_input(meta_b) else input_length(meta_b)
|
|
115
|
+
if dur_b and start_b + length > dur_b + 0.01 and not STATE.dry_run:
|
|
116
|
+
die(f"cutaway {i + 1}: {path} has only {dur_b - start_b:.3f}s from {start_b:g}s, {length:g}s asked for")
|
|
117
|
+
# the cutaway in whole frames: `first` is B's first frame at or after --from, `on` the
|
|
118
|
+
# A-roll's first frame at or after --at, and `span` runs to its first at or after the end
|
|
119
|
+
v0b, rate_b = stream_starts(meta_b)[0], frame_rate(meta_b)
|
|
120
|
+
first = max(v0b, grid_at_or_after(start_b, v0b, rate_b))
|
|
121
|
+
on = span = None
|
|
122
|
+
if grid:
|
|
123
|
+
on = grid_at_or_after(on_frame(at, v0a, rate_a), v0a, rate_a) # a millisecond time is its frame (#653)
|
|
124
|
+
span = grid_at_or_after(on_frame(at + length, v0a, rate_a), v0a, rate_a) - on
|
|
125
|
+
if round(span * rate_a) < 1:
|
|
126
|
+
die(f"cutaway {i + 1}: no frame of the A-roll starts between {at:g}s and {at + length:g}s "
|
|
127
|
+
f"(its frames are {1 / rate_a:.4f}s apart): nothing would be shown")
|
|
128
|
+
cutaways.append({"path": path, "at": at, "length": length, "from": start_b, "has_audio": bool(meta_b.get("audio")), "meta": meta_b,
|
|
129
|
+
"first": first, "rate": rate_b, "on": on, "span": span})
|
|
130
|
+
# overlap is a property of the windows in time, not of the order they were given in: compared
|
|
131
|
+
# against the one given before it, a later window listed first was called overlapping (A179)
|
|
132
|
+
order = sorted(range(len(cutaways)), key=lambda k: cutaways[k]["at"])
|
|
133
|
+
for prev, k in zip(order, order[1:]):
|
|
134
|
+
end_prev = cutaways[prev]["at"] + cutaways[prev]["length"]
|
|
135
|
+
if cutaways[k]["at"] < end_prev:
|
|
136
|
+
die(f"cutaway {k + 1} at {cutaways[k]['at']:g}s overlaps cutaway {prev + 1} "
|
|
137
|
+
f"({cutaways[prev]['at']:g}s to {end_prev:g}s)")
|
|
138
|
+
if args.audio != "a" and not all(c["has_audio"] for c in cutaways):
|
|
139
|
+
die("--audio b/mix needs audio on every B-roll clip")
|
|
140
|
+
|
|
141
|
+
output = args.output or default_output(args.input, "broll")
|
|
142
|
+
cmd = ffmpeg_base() + ["-i", args.input]
|
|
143
|
+
for c in cutaways:
|
|
144
|
+
# a still B-roll is one frame to a plain -i: it showed for one frame of the cutaway and A
|
|
145
|
+
# came back under it (#510). Looped, it lasts the window it is trimmed to. The bound is past
|
|
146
|
+
# the trim's end, which runs from B's first frame at or after --from on the loop's own
|
|
147
|
+
# grid for the window's whole frames: --from + --duration cut that frame off a short window
|
|
148
|
+
# (--from 0.041 --duration 0.033 needs the frame at 0.08, review of #532). A frame of B
|
|
149
|
+
# past it costs nothing: the trim drops it.
|
|
150
|
+
if is_still_input(c["meta"]):
|
|
151
|
+
frame_b = 1 / c["rate"] if c["rate"] else 0.04
|
|
152
|
+
cmd += still_loop_args(c["path"], max(c["from"], c["first"]) + max(c["length"], c["span"] or 0) + 2 * frame_b)
|
|
153
|
+
cmd += ["-i", c["path"]]
|
|
154
|
+
|
|
155
|
+
# Picture: each B window is trimmed, normalised to A's frame and fps, shifted to start at its
|
|
156
|
+
# --at time, and overlaid on A; outside the window the overlay is placed off the picture and
|
|
157
|
+
# A shows through unchanged, so A's timeline is never touched.
|
|
158
|
+
parts: List[str] = []
|
|
159
|
+
cur = "[0:v]"
|
|
160
|
+
metas = [meta_a] + [c["meta"] for c in cutaways]
|
|
161
|
+
convert = mix_color_chains(metas, meta_a, draws_colour=draws_chroma([args.pad_color], meta_a))
|
|
162
|
+
if convert[0] or a_chain:
|
|
163
|
+
parts.append(f"[0:v]{convert[0]}{a_chain or 'null'}[a709]")
|
|
164
|
+
cur = "[a709]"
|
|
165
|
+
pad = f"pad={w}:{h}:(ow-iw)/2:(oh-ih)/2:color="
|
|
166
|
+
for i, c in enumerate(cutaways):
|
|
167
|
+
geo = (f"scale={w}:{h}:force_original_aspect_ratio=decrease,"
|
|
168
|
+
+ drawn_chain(pad + args.pad_color, as_limited(c["meta"]), [args.pad_color], pad + "black", line_meta=meta_a,
|
|
169
|
+
tag=f"pad{i}", labelled=True))
|
|
170
|
+
b_sq = (square_pixels(c["meta"]["video"]) + ",") if square_pixels(c["meta"]["video"]) else ""
|
|
171
|
+
pix = 'yuv420p10le' if (meta_a.get('video') or {}).get('bt2020_or_hdr') else 'yuv420p'
|
|
172
|
+
if c["on"] is None:
|
|
173
|
+
# no grid to count the A-roll's frames on (a dry run's pending A-roll, a variable
|
|
174
|
+
# rate): the window as it was written before, to the millisecond
|
|
175
|
+
parts.append(f"[{i + 1}:v]trim=start={c['from']:.3f}:duration={c['length']:.3f},setpts=PTS-STARTPTS+{c['at']:.3f}/TB,"
|
|
176
|
+
f"{convert[i + 1]}{b_sq}{geo},setsar=1,fps={fps:g},format={pix}[b{i}]")
|
|
177
|
+
window = window_expr(c["at"], c["at"] + c["length"], None)
|
|
178
|
+
else:
|
|
179
|
+
# The window is whole frames of the A-roll: from its first frame at or after --at to
|
|
180
|
+
# the frame before its first at or after the end. B is cut half a frame of its own
|
|
181
|
+
# before its first frame at or after --from, for as long as the window lasts, and
|
|
182
|
+
# that frame is put on the tick of the `fps` grid at or before the window's first
|
|
183
|
+
# frame, at the A-roll's exact rate (30000/1001, not probe()'s 29.97: frame 37
|
|
184
|
+
# counted at 29.97 comes 1.2 microseconds after the A-roll's and was shown a frame on)
|
|
185
|
+
# The cut never ends before B's first frame: a window shorter than half a frame of B
|
|
186
|
+
# (one 60 fps frame of the A-roll under a 24 fps cutaway) cut that frame off too
|
|
187
|
+
half_b = 0.5 / c["rate"] if c["rate"] else 0.0
|
|
188
|
+
parts.append(f"[{i + 1}:v]trim=start={max(0.0, c['first'] - half_b):.6f}:end={max(c['first'] + c['span'], c['first'] + 2 * half_b) - half_b:.6f},"
|
|
189
|
+
f"setpts=PTS-STARTPTS+{math.floor(c['on'] * rate_a + 1e-6) / rate_a:.6f}/TB,"
|
|
190
|
+
f"{convert[i + 1]}{b_sq}{geo},setsar=1,{fps_filter},format={pix}[b{i}]")
|
|
191
|
+
window = window_expr(c["on"], c["on"] + c["span"], meta_a, half_open=True)
|
|
192
|
+
# The window is in the cutaway's position: overlay's enable is evaluated on B's frames
|
|
193
|
+
# too. B's last frame is held when B ends (eof_action=repeat) and the position takes it
|
|
194
|
+
# off the picture: with eof_action=pass the window's last frame depended on where B's
|
|
195
|
+
# end fell against it, and an A-roll whose picture starts 13 ms late lost that frame.
|
|
196
|
+
parts.append(f"{cur}[b{i}]overlay={windowed_overlay_x(0, window)}:0{overlay_format(meta_a)}:eof_action=repeat[v{i}]")
|
|
197
|
+
cur = f"[v{i}]"
|
|
198
|
+
vout = cur
|
|
199
|
+
|
|
200
|
+
# Audio: `a` stream-copies A's track; `b`/`mix` build A (muted inside the windows for `b`)
|
|
201
|
+
# plus each B window delayed to its --at time.
|
|
202
|
+
aout = None
|
|
203
|
+
if has_audio_a or args.audio != "a":
|
|
204
|
+
if args.audio == "a":
|
|
205
|
+
aout = "0:a:0" if has_audio_a else None
|
|
206
|
+
else:
|
|
207
|
+
layers: List[str] = []
|
|
208
|
+
# the cutaway's sound follows its picture: it starts with the window's first frame and
|
|
209
|
+
# lasts as long as the window, counted in samples of the mix (without a frame grid:
|
|
210
|
+
# --at and the length asked)
|
|
211
|
+
for c in cutaways:
|
|
212
|
+
c["s0"] = round((c["at"] if c["on"] is None else c["on"]) * MIX_RATE)
|
|
213
|
+
c["sn"] = round((c["length"] if c["on"] is None else c["span"]) * MIX_RATE)
|
|
214
|
+
# a multichannel A-roll keeps its layout: 5.1 was folded to stereo with `verified: true`
|
|
215
|
+
# and nothing said (#470); B is up-mixed to it. Mono and stereo are mixed in stereo
|
|
216
|
+
aa = meta_a.get("audio") or {}
|
|
217
|
+
layout = "stereo"
|
|
218
|
+
if has_audio_a and (aa.get("channels") or 0) > 2:
|
|
219
|
+
layout = aa["channel_layout"] if aa.get("channel_layout") not in (None, "", "unknown") else f"{aa['channels']}c"
|
|
220
|
+
if has_audio_a:
|
|
221
|
+
# `b` mutes the A-roll over exactly the samples B's sound takes, on the A-roll's
|
|
222
|
+
# own clock: aeval's `t` is each sample's time, and the bounds sit half a sample
|
|
223
|
+
# outside the first and the last. `volume=0:enable='between(t,...)'` is evaluated
|
|
224
|
+
# once per audio frame and muted 48128-96255 where 48000-95999 was asked
|
|
225
|
+
# (1024-sample frames; FFmpeg 6.1.1)
|
|
226
|
+
gate = ""
|
|
227
|
+
if args.audio == "b":
|
|
228
|
+
gate = ",aeval='val(ch)*not(" + "+".join(
|
|
229
|
+
f"between(t,{(c['s0'] - 0.5) / MIX_RATE:.9f},{(c['s0'] + c['sn'] - 0.5) / MIX_RATE:.9f})" for c in cutaways) + ")':c=same"
|
|
230
|
+
parts.append(f"[0:a:0]aformat=sample_rates=48000:channel_layouts={layout}{gate}[a0]")
|
|
231
|
+
layers.append("[a0]")
|
|
232
|
+
for i, c in enumerate(cutaways):
|
|
233
|
+
# B's sound is shifted by the same constant as its picture, whose first frame (the
|
|
234
|
+
# first at or after --from) lands on the window's first frame; rebasing the sound
|
|
235
|
+
# to its own first sample moved a track that starts 0.3 s late 0.279 s early (#409)
|
|
236
|
+
first, length = c["first"], c["length"] if c["on"] is None else c["span"]
|
|
237
|
+
# the delay is to the sample of the mix's rate: `int(at * 1000)` cut 1.001 to
|
|
238
|
+
# 1000 ms and wrote 1.2346 s as 1234 ms, the cutaway's sound 48 and 29 samples
|
|
239
|
+
# early. A whole millisecond keeps the text it had, rounded (silence_filter)
|
|
240
|
+
lead = c["s0"] / MIX_RATE
|
|
241
|
+
delay = silence_filter(MIX_RATE, lead=lead)
|
|
242
|
+
if "S:" not in delay:
|
|
243
|
+
delay = f"adelay={round(lead * 1000)}|{round(lead * 1000)}"
|
|
244
|
+
# under `b` the layer is as many samples as the gate mutes, padded or cut
|
|
245
|
+
exact = f"apad=whole_len={c['sn']},atrim=end_sample={c['sn']}," if args.audio == "b" else ""
|
|
246
|
+
parts.append(f"[{i + 1}:a:0]{av_trim(first, first + length)[1]},"
|
|
247
|
+
f"aformat=sample_rates=48000:channel_layouts={layout},{exact}{delay}[ab{i}]")
|
|
248
|
+
layers.append(f"[ab{i}]")
|
|
249
|
+
# the mix ends with the A-roll, to the sample (#493): every layer is 48 kHz, so the count
|
|
250
|
+
# is in that rate. `atrim=duration={:.3f}` and `-t {:.3f}` cut it to the millisecond. A
|
|
251
|
+
# dry run's pending A-roll has no length to count, and keeps the old filter.
|
|
252
|
+
tail = conform_to_length(dur_a, MIX_RATE) if dur_a > 0 else f"atrim=duration={dur_a:.3f}"
|
|
253
|
+
parts.append(f"{''.join(layers)}amix=inputs={len(layers)}:normalize=0:dropout_transition=0,{tail}[aout]")
|
|
254
|
+
aout = "[aout]"
|
|
255
|
+
|
|
256
|
+
# a VFR A-roll is conformed by the fps filter as it is decoded, at the rate cfr_args() delivers:
|
|
257
|
+
# -fps_mode cfr alone let a frame run up to two frames late against the sound (#512)
|
|
258
|
+
graph = cfr_at_input(";".join(parts), meta_a)
|
|
259
|
+
cmd += ["-filter_complex", graph, "-map", vout]
|
|
260
|
+
if aout:
|
|
261
|
+
cmd += ["-map", aout]
|
|
262
|
+
cmd += video_args(meta_a, args.crf, args.preset, convert_matrix=False) + cfr_args(meta_a, None)
|
|
263
|
+
if aout == "0:a:0":
|
|
264
|
+
cmd += ["-c:a", "copy"]
|
|
265
|
+
elif aout:
|
|
266
|
+
cmd += aac_args()
|
|
267
|
+
else:
|
|
268
|
+
cmd += ["-an"]
|
|
269
|
+
cmd += ["-t", conform_output_t(dur_a, MIX_RATE) if aout == "[aout]" and dur_a > 0 else f"{dur_a:.3f}", output]
|
|
270
|
+
run(cmd)
|
|
271
|
+
|
|
272
|
+
result = probe(output, role="output")
|
|
273
|
+
if not STATE.dry_run and dur_a and abs((result.get("duration") or 0.0) - dur_a) > max(0.1, 1.5 / fps):
|
|
274
|
+
die(f"output is {fmt_secs(result.get('duration'))} but the A-roll is {dur_a:.3f}s -- a cutaway must not change the length", kind="output")
|
|
275
|
+
info(f"wrote {output} ({result.get('duration', 0):.3f}s, {len(cutaways)} cutaway(s), audio={args.audio})")
|
|
276
|
+
emit(output, cutaways=[{"insert": c["path"], "at": c["at"], "end": c["at"] + c["length"], "from": c["from"]} for c in cutaways], audio=args.audio,
|
|
277
|
+
dropped_non_av_streams=bool(meta_a.get("subtitle_streams") or meta_a.get("data_streams")))
|
|
278
|
+
return 0
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
if __name__ == "__main__":
|
|
282
|
+
sys.exit(main())
|