@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,502 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Render an audio track as a waveform or spectrum visualization video.
|
|
3
|
+
|
|
4
|
+
Wraps FFmpeg's showwaves (--style waveform, the default) or showspectrum
|
|
5
|
+
(--style spectrum) source filter over the input's audio -- for a podcast
|
|
6
|
+
episode, a music release, or any clip that has no picture worth showing.
|
|
7
|
+
The rendered clip always carries the same audio it visualizes; the video is
|
|
8
|
+
generated fresh, there is no source picture involved.
|
|
9
|
+
|
|
10
|
+
--style waveform draws the amplitude over time; --style spectrum draws a
|
|
11
|
+
frequency-over-time heatmap instead, which reads more information out of
|
|
12
|
+
dense mixes at the cost of being less immediately readable to a general
|
|
13
|
+
audience. Both accept --width/--height and --split-channels (stereo drawn as
|
|
14
|
+
two separate lanes instead of summed to one); waveform additionally takes
|
|
15
|
+
--color and --waveform-mode (how each sample is drawn). The spectrum is drawn
|
|
16
|
+
in showspectrum's own colour map, so --color with --style spectrum is refused.
|
|
17
|
+
|
|
18
|
+
Examples:
|
|
19
|
+
python3 waveform.py podcast.wav -o waveform.mp4
|
|
20
|
+
python3 waveform.py track.wav --style spectrum --width 1920 --height 1080 -o spectrum.mp4
|
|
21
|
+
python3 waveform.py interview.mp4 --split-channels --color cyan|magenta
|
|
22
|
+
python3 waveform.py interview.mp4 --at 12.4 --at 35.1 --window 2 -o cuts.png
|
|
23
|
+
|
|
24
|
+
An *audiogram* is the same render over a picture: --image cover.png puts a
|
|
25
|
+
still behind the visualisation, --platform sizes the frame for a
|
|
26
|
+
destination, --srt burns the captions on afterwards (by running caption.py,
|
|
27
|
+
not by re-implementing the subtitle path) and --title draws one static
|
|
28
|
+
label through graphics.py. Nothing is ever fetched and no cover art is ever
|
|
29
|
+
invented: give an image or a colour.
|
|
30
|
+
|
|
31
|
+
python3 waveform.py ep.m4a --image cover.png --platform reels --position strip -o ep.mp4
|
|
32
|
+
python3 waveform.py ep.m4a --image cover.png --srt ep.srt --title "Episode 12" -o ep.mp4
|
|
33
|
+
"""
|
|
34
|
+
import argparse
|
|
35
|
+
import json
|
|
36
|
+
import math
|
|
37
|
+
import os
|
|
38
|
+
import sys
|
|
39
|
+
from pathlib import Path
|
|
40
|
+
|
|
41
|
+
from _platforms import PLATFORMS, PLATFORM_CHOICES, resolve as resolve_platform
|
|
42
|
+
from _common.probe import SILENT_PEAK_DBFS, refuse_not_a_still, square_pixels, square_pixels_note
|
|
43
|
+
from _common import still_input_args # noqa: E402
|
|
44
|
+
from _common import (add_common, apply_common, aac_args, color_hex, default_output, die, draws_chroma, emit, ffmpeg_base,
|
|
45
|
+
info, load_brand, pad_filters, probe, rgb_chain_to_bt709, run, STATE, validate_color, video_args, X264_PRESETS,
|
|
46
|
+
fmt_secs, child_args, run_tool, measured_level_dbfs, sibling_temp)
|
|
47
|
+
from _common import (default_font_file, drawtext_fontfile, input_length, refuse_existing_outputs,
|
|
48
|
+
refuse_output_is_input, require_filter, time_arg)
|
|
49
|
+
from _common.emit import absorb_stage_hw, note, refuse, warn
|
|
50
|
+
from _common.runner import absent_word, refuse_missing_components_first
|
|
51
|
+
from _common.decision import length_output_t
|
|
52
|
+
from _common.probe import AUDIO_MEDIA_EXT
|
|
53
|
+
|
|
54
|
+
WAVEFORM_MODES = ["point", "line", "p2p", "cline"]
|
|
55
|
+
# flags that shape the video output and mean nothing to --at's PNGs
|
|
56
|
+
WAVEFORM_VIDEO_ONLY = {"fps", "silence_threshold", "preset", "image_fit", "position", "vis_height", "opacity",
|
|
57
|
+
"fast", "codec", "quality", "hw", "no_hw"}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _waveform_stills(args, meta: dict, rate: int) -> int:
|
|
61
|
+
if (args.style != "waveform" or args.image or args.srt or args.text or args.title
|
|
62
|
+
or args.platform or args.background != "black" or args.waveform_mode != "line"
|
|
63
|
+
or args.on_silent != "warn"):
|
|
64
|
+
die("--at draws waveform PNGs; use the default waveform style and background, without audiogram or silence-check options")
|
|
65
|
+
if not 0 < args.window <= 30 or not math.isfinite(args.window):
|
|
66
|
+
die("--window must be a positive number of seconds up to 30")
|
|
67
|
+
if args.width < 240 or args.height < 64:
|
|
68
|
+
die("--at needs at least 240x64 pixels for the waveform and its label")
|
|
69
|
+
duration = input_length(meta)
|
|
70
|
+
if duration <= 0:
|
|
71
|
+
die("--at needs a source with a known positive duration")
|
|
72
|
+
if not rate:
|
|
73
|
+
die("--at needs a known sample rate for the selected audio stream")
|
|
74
|
+
marked = [time_arg(t, "--at", (meta.get("video") or {}).get("fps")) for t in args.at]
|
|
75
|
+
output = Path(args.output or default_output(args.input, "waveform_review", "png"))
|
|
76
|
+
if output.suffix.lower() != ".png":
|
|
77
|
+
die("--at writes PNG images; name a .png output")
|
|
78
|
+
rows = []
|
|
79
|
+
for index, time in enumerate(marked, start=1):
|
|
80
|
+
if not 0 <= time <= duration:
|
|
81
|
+
die(f"--at {time:g}: outside the input's 0–{duration:g}s timeline")
|
|
82
|
+
start = round(max(0.0, time - args.window / 2), 6)
|
|
83
|
+
end = round(min(duration, time + args.window / 2), 6)
|
|
84
|
+
length = round(end - start, 6)
|
|
85
|
+
# showwavespic uses fixed integer sample bins and puts the remainder in the final bin.
|
|
86
|
+
samples_per_column = round(length * rate) // args.width
|
|
87
|
+
if not samples_per_column:
|
|
88
|
+
die(f"--at {time:g}: window holds fewer samples than the image has columns; increase --window or reduce --width")
|
|
89
|
+
image = output if len(marked) == 1 else output.with_name(f"{output.stem}_{index:02d}.png")
|
|
90
|
+
marker = min(args.width - 1, round((time - start) * rate) // samples_per_column)
|
|
91
|
+
rows.append({"output": str(image), "time": round(time, 6), "start": start, "end": end,
|
|
92
|
+
"window_seconds": length, "marker_x": marker})
|
|
93
|
+
paths = [row["output"] for row in rows]
|
|
94
|
+
for out in paths:
|
|
95
|
+
refuse_output_is_input(out, args.input)
|
|
96
|
+
refuse_existing_outputs(paths)
|
|
97
|
+
require_filter("showwavespic", "rendering a still waveform")
|
|
98
|
+
require_filter("drawtext", "labeling a still waveform")
|
|
99
|
+
font = default_font_file("DejaVu Sans")
|
|
100
|
+
face = f"{drawtext_fontfile(font)}:" if font else ""
|
|
101
|
+
steps = []
|
|
102
|
+
for row in rows:
|
|
103
|
+
out, start, length = row["output"], row["start"], row["window_seconds"]
|
|
104
|
+
label = f"Cut {row['time']:.3f} s | Window {length:.3f} s"
|
|
105
|
+
chain = (
|
|
106
|
+
f"[0:a:{args.audio_stream}]aresample=async=1:first_pts=0,apad,atrim=end_sample={round(length * rate)},"
|
|
107
|
+
f"showwavespic=s={args.width}x{args.height - 32}:split_channels={int(args.split_channels)}:colors={args.color},"
|
|
108
|
+
"format=rgb24,pad=iw:ih+32:0:32:color=black,"
|
|
109
|
+
f"drawbox=x={row['marker_x']}:y=32:w=2:h=ih-32:c=0xFFAA44:t=fill,"
|
|
110
|
+
f"drawtext={face}text='{label}':fontsize=14:fontcolor=white:x=8:y=8[still]"
|
|
111
|
+
)
|
|
112
|
+
run(ffmpeg_base() + ["-ss", f"{start:.6f}", "-t", f"{length:.6f}", "-i", args.input,
|
|
113
|
+
"-filter_complex", chain, "-map", "[still]", "-frames:v", "1", "-update", "1", out])
|
|
114
|
+
if not STATE.dry_run:
|
|
115
|
+
video = probe(out, role="output").get("video") or {}
|
|
116
|
+
expected = [args.width, args.height]
|
|
117
|
+
measured = [video.get("width"), video.get("height")]
|
|
118
|
+
ok = video.get("codec") == "png" and measured == expected
|
|
119
|
+
steps.append({"step": "waveform_image", "output": out, "ok": ok,
|
|
120
|
+
"expected": expected, "measured": measured, "codec": video.get("codec")})
|
|
121
|
+
if not ok:
|
|
122
|
+
die(f"waveform image verification failed: {out}", kind="verification",
|
|
123
|
+
output=out, verification=steps, verified=False)
|
|
124
|
+
info(f"wrote {out} (cut {row['time']:.3f}s; window {start:.3f}–{row['end']:.3f}s)")
|
|
125
|
+
fields = {"planned_waveforms" if STATE.dry_run else "waveforms": rows}
|
|
126
|
+
emit(paths[0], outputs=paths, verification=steps, **fields)
|
|
127
|
+
return 0
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def main() -> int:
|
|
131
|
+
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
132
|
+
ap.add_argument("input")
|
|
133
|
+
ap.add_argument("-o", "--output", help="output video, or a .png path with --at")
|
|
134
|
+
ap.add_argument("--at", action="append", metavar="TIME", help="write a waveform PNG around this time (repeat for several points)")
|
|
135
|
+
ap.add_argument("--window", type=float, default=None, metavar="SECONDS", help="total waveform time around each --at (default 2, up to 30)")
|
|
136
|
+
ap.add_argument("--style", choices=["waveform", "spectrum"], default="waveform", help="waveform (default) or spectrum visualization")
|
|
137
|
+
ap.add_argument("--width", type=int, default=1920, help="output width in px, 2..16384, must be even (default 1920)")
|
|
138
|
+
ap.add_argument("--height", type=int, default=1080, help="output height in px, 2..16384, must be even (default 1080)")
|
|
139
|
+
ap.add_argument("--fps", type=float, default=25.0, help="output frame rate (default 25)")
|
|
140
|
+
ap.add_argument("--color", default="lime", help="--style waveform only: channel colour(s), pipe-separated per channel, e.g. 'lime' or 'cyan|magenta' (default lime)")
|
|
141
|
+
ap.add_argument("--background", default="black", help="background colour (default black)")
|
|
142
|
+
ap.add_argument("--waveform-mode", choices=WAVEFORM_MODES, default="line", help="--style waveform only: how each sample is drawn (default line)")
|
|
143
|
+
ap.add_argument("--split-channels", action="store_true", help="draw each channel in its own lane instead of summing to one")
|
|
144
|
+
ap.add_argument("--audio-stream", type=int, default=0,
|
|
145
|
+
help="which audio stream of the input to render, 0-based in file order (default 0)")
|
|
146
|
+
ap.add_argument("--on-silent", choices=["warn", "fail"], default="warn",
|
|
147
|
+
help="input audio whose peak is at or below --silence-threshold (the render would be a flat "
|
|
148
|
+
"line): warn (default: render it, report `silent: true`) or fail (refuse before ffmpeg runs)")
|
|
149
|
+
ap.add_argument("--silence-threshold", type=float, default=SILENT_PEAK_DBFS, metavar="DBFS",
|
|
150
|
+
help="peak level in dBFS at or below which the input counts as silent (default -50)")
|
|
151
|
+
ag = ap.add_argument_group("audiogram (1.16)",
|
|
152
|
+
"The visualisation over a picture, for an episode that has no video. The image is a "
|
|
153
|
+
"local file you give: this skill has no network access and never invents cover art.")
|
|
154
|
+
ag.add_argument("--image", help="still image or brand plate to put behind the visualisation (a local file; scaled to cover the frame and centre-cropped)")
|
|
155
|
+
ag.add_argument("--image-fit", choices=["cover", "contain", "blur"], default="cover",
|
|
156
|
+
help="how a still of the wrong aspect fills the frame: cover (default, crop the overflow), contain (bars in --background), blur (bars are a blurred copy, as fit.py)")
|
|
157
|
+
ag.add_argument("--position", choices=["bottom", "centre", "center", "top", "strip"], default="strip",
|
|
158
|
+
help="where the visualisation sits over the plate (default strip: a band of --vis-height along the bottom, the podcast-audiogram convention)")
|
|
159
|
+
ag.add_argument("--vis-height", type=float, default=0.35,
|
|
160
|
+
help="height of the visualisation band as a fraction of the frame (default 0.35)")
|
|
161
|
+
ag.add_argument("--opacity", type=float, default=1.0, help="visualisation alpha over the plate, 0..1 (default 1)")
|
|
162
|
+
ag.add_argument("--platform", choices=PLATFORM_CHOICES, default=None,
|
|
163
|
+
help="take the frame size and fps from this destination instead of --width/--height/--fps")
|
|
164
|
+
ag.add_argument("--srt", help="burn these captions into the render afterwards, by running caption.py (never re-implemented here)")
|
|
165
|
+
ag.add_argument("--text", help="plain cue file to burn, same as caption.py --text")
|
|
166
|
+
ag.add_argument("--title", help="one static label drawn over the plate, through graphics.py's sticker template")
|
|
167
|
+
ag.add_argument("--brand", help="brand.json: --color / --background / font defaults")
|
|
168
|
+
ap.set_defaults(crf=18) # --quality's default (the --crf alias was removed in 2.0)
|
|
169
|
+
ap.add_argument("--preset", default="medium", choices=X264_PRESETS, help="x264 preset")
|
|
170
|
+
add_common(ap)
|
|
171
|
+
args = ap.parse_args()
|
|
172
|
+
apply_common(args)
|
|
173
|
+
|
|
174
|
+
args.platform = resolve_platform(args.platform)
|
|
175
|
+
if args.platform:
|
|
176
|
+
frame = PLATFORMS[args.platform].get("frame")
|
|
177
|
+
if not frame:
|
|
178
|
+
die(f"--platform {args.platform}: that destination has no frame (it is an audio spec); "
|
|
179
|
+
"give --width/--height, or name a destination that has a picture", kind="input")
|
|
180
|
+
args.width, args.height = frame["w"], frame["h"]
|
|
181
|
+
args.fps = float(PLATFORMS[args.platform].get("fps") or args.fps)
|
|
182
|
+
info(f"--platform {args.platform}: {args.width}x{args.height} @ {args.fps:g}fps")
|
|
183
|
+
if args.style == "spectrum" and args.color != ap.get_default("color"):
|
|
184
|
+
# A144: showspectrum takes no colour, so the flag was accepted and the heatmap drawn in
|
|
185
|
+
# its own colour map (a brand's primary colour is a default and is not refused)
|
|
186
|
+
die(f"--color {args.color} colours the waveform's channels; --style spectrum is drawn in showspectrum's own "
|
|
187
|
+
"colour map and takes no colour", hint="drop --color, or use --style waveform")
|
|
188
|
+
if args.style == "spectrum" and args.waveform_mode != ap.get_default("waveform_mode"):
|
|
189
|
+
die(f"--waveform-mode {args.waveform_mode} is how --style waveform draws each sample; --style spectrum has no "
|
|
190
|
+
"such mode", hint="drop --waveform-mode, or use --style waveform")
|
|
191
|
+
brand = load_brand(args.brand) if args.brand else None
|
|
192
|
+
if brand:
|
|
193
|
+
bc = brand.get("colors") or {}
|
|
194
|
+
# read as caption.py, graphics.py and overlay.py read a brand colour (#535): a brand file
|
|
195
|
+
# writes six hex digits with or without # or 0x
|
|
196
|
+
if args.color == "lime" and bc.get("primary"):
|
|
197
|
+
args.color = color_hex(bc["primary"])
|
|
198
|
+
if args.background == "black" and bc.get("background"):
|
|
199
|
+
args.background = color_hex(bc["background"])
|
|
200
|
+
if args.image:
|
|
201
|
+
if "://" in args.image:
|
|
202
|
+
die("--image must be a readable local file; this skill has no network access, so save "
|
|
203
|
+
"the image locally and pass its path", kind="input")
|
|
204
|
+
if not os.path.exists(args.image):
|
|
205
|
+
die(f"--image file {absent_word(args.image)}: {args.image}", kind="input")
|
|
206
|
+
# read under --dry-run too (the file exists, checked above): a plate the real run refuses
|
|
207
|
+
# is refused by the plan (#404: a dry run completed on a video given as --image)
|
|
208
|
+
plate = probe(args.image, role="input")
|
|
209
|
+
if not (plate.get("video") or {}).get("width"):
|
|
210
|
+
die(f"--image is not an image ffmpeg can decode: {args.image}", kind="input")
|
|
211
|
+
refuse_not_a_still(args.image, plate, "--image",
|
|
212
|
+
"`look.py FILE --at T` writes one frame of a video as a PNG")
|
|
213
|
+
if args.background != "black":
|
|
214
|
+
die("--image and a non-default --background exclude each other: the plate is either "
|
|
215
|
+
"the picture or the colour", kind="input")
|
|
216
|
+
if not 0.0 <= args.opacity <= 1.0:
|
|
217
|
+
die(f"--opacity must be between 0 and 1, got {args.opacity:g}")
|
|
218
|
+
if not 0.0 < args.vis_height <= 1.0:
|
|
219
|
+
die(f"--vis-height must be between 0 and 1, got {args.vis_height:g}")
|
|
220
|
+
if args.srt and args.text:
|
|
221
|
+
die("--srt and --text exclude each other (both name the cues to burn)")
|
|
222
|
+
# caption.py would refuse a missing cue file too, but only after the visualisation had been
|
|
223
|
+
# encoded: check it here, before any encode, and name the flag the caller gave
|
|
224
|
+
for flag, path in (("--srt", args.srt), ("--text", args.text)):
|
|
225
|
+
if path and not os.path.isfile(path):
|
|
226
|
+
die(f"{flag} file {absent_word(path)}: {path}", kind="input")
|
|
227
|
+
|
|
228
|
+
if args.width % 2 or args.height % 2:
|
|
229
|
+
die(f"--width/--height must be even (4:2:0 chroma), got width={args.width} height={args.height}")
|
|
230
|
+
for token in args.color.split("|"):
|
|
231
|
+
validate_color(token, "--color")
|
|
232
|
+
validate_color(args.background, "--background")
|
|
233
|
+
if args.fps <= 0:
|
|
234
|
+
die(f"--fps must be > 0, got {args.fps:g}")
|
|
235
|
+
|
|
236
|
+
meta = probe(args.input)
|
|
237
|
+
if not meta.get("audio"):
|
|
238
|
+
die("input has no audio stream")
|
|
239
|
+
audio_streams = meta.get("audio_streams") or [meta["audio"]]
|
|
240
|
+
if not (0 <= args.audio_stream < len(audio_streams)):
|
|
241
|
+
die(f"--audio-stream {args.audio_stream}: input has {len(audio_streams)} audio stream(s), 0..{len(audio_streams) - 1}")
|
|
242
|
+
if args.at:
|
|
243
|
+
# a video-only flag would be accepted and ignored: refused by name (a flag the tool cannot
|
|
244
|
+
# honour is refused, docs/design-decisions.md)
|
|
245
|
+
video_only = [a for a in ap._actions if a.option_strings and a.dest in WAVEFORM_VIDEO_ONLY
|
|
246
|
+
and getattr(args, a.dest) != a.default
|
|
247
|
+
and not (a.dest == "preset" and args.fast)] # --fast sets the preset itself
|
|
248
|
+
if video_only:
|
|
249
|
+
die(f"--at draws waveform PNGs; {', '.join(a.option_strings[-1] for a in video_only)} "
|
|
250
|
+
"only applies to the video output")
|
|
251
|
+
args.window = 2.0 if args.window is None else args.window
|
|
252
|
+
return _waveform_stills(args, meta, audio_streams[args.audio_stream].get("sample_rate") or 0)
|
|
253
|
+
if args.window is not None:
|
|
254
|
+
die("--window needs --at")
|
|
255
|
+
if args.silence_threshold >= 0:
|
|
256
|
+
die(f"--silence-threshold is a peak level in dBFS and must be negative, got {args.silence_threshold:g}")
|
|
257
|
+
# A137: the output always holds a picture, so an audio input's extension is not the default:
|
|
258
|
+
# talk.wav made talk_waveform.wav, which the WAV muxer refused (kind ffmpeg), and talk.m4a an
|
|
259
|
+
# H.264 video named .m4a
|
|
260
|
+
in_ext = os.path.splitext(args.input)[1].lower()
|
|
261
|
+
output = args.output or default_output(args.input, "waveform", "mp4" if in_ext in AUDIO_MEDIA_EXT else None)
|
|
262
|
+
# every audio-only extension this skill reads, not only those it writes (is_audio_output():
|
|
263
|
+
# .aif, .aiff, .caf and .wma are not there, and passed this to fail in ffmpeg, or in a dry run not at all)
|
|
264
|
+
if os.path.splitext(output)[1].lower() in AUDIO_MEDIA_EXT:
|
|
265
|
+
# the reason every tool that writes a picture gives (runner._check_picture_into_audio_extension,
|
|
266
|
+
# #539), from here because it comes before the measuring passes: the level measurement
|
|
267
|
+
# below runs ffmpeg over the whole input, and a silent input stopped there first (#554 review)
|
|
268
|
+
refuse("input", "output_extension_audio_only",
|
|
269
|
+
f"{output}: waveform.py writes a video, and {os.path.splitext(output)[1].lower()} holds sound only; "
|
|
270
|
+
"name a video file (.mp4, .mov, .mkv)",
|
|
271
|
+
output=output, extension=os.path.splitext(output)[1].lower(), encoders=[])
|
|
272
|
+
# silent input draws a flat line that used to be reported as verified; a writing tool's dry
|
|
273
|
+
# run runs no ffmpeg (docs/contract.md), so only the real run measures
|
|
274
|
+
silent_peak = None
|
|
275
|
+
if not STATE.dry_run:
|
|
276
|
+
level = measured_level_dbfs(args.input, seconds=None, audio_stream=args.audio_stream)
|
|
277
|
+
if level is not None and level["peak_dbfs"] <= args.silence_threshold:
|
|
278
|
+
silent_peak = level["peak_dbfs"]
|
|
279
|
+
if args.on_silent == "fail":
|
|
280
|
+
die(f"{args.input} is silent (audio stream {args.audio_stream} peaks at {silent_peak:g} dBFS, at or below "
|
|
281
|
+
f"--silence-threshold {args.silence_threshold:g}): the visualisation would be a flat line",
|
|
282
|
+
kind="input", hint="check the audio, or pass --on-silent warn to render it anyway")
|
|
283
|
+
|
|
284
|
+
# The visualisation's own band. Without --image/--position it fills the frame, which is what
|
|
285
|
+
# every 1.15 command line did, so the graph below is byte-identical when no new flag is given.
|
|
286
|
+
vis_h = args.height
|
|
287
|
+
vis_y = 0
|
|
288
|
+
if args.image:
|
|
289
|
+
vis_h = max(2, int(round(args.height * args.vis_height)) // 2 * 2)
|
|
290
|
+
pos = "centre" if args.position == "center" else args.position
|
|
291
|
+
vis_y = {"top": 0, "centre": (args.height - vis_h) // 2,
|
|
292
|
+
"bottom": args.height - vis_h, "strip": args.height - vis_h}[pos]
|
|
293
|
+
|
|
294
|
+
if args.style == "waveform":
|
|
295
|
+
vf = (f"showwaves=s={args.width}x{vis_h}:mode={args.waveform_mode}:rate={args.fps:g}:"
|
|
296
|
+
f"split_channels={1 if args.split_channels else 0}:colors={args.color}")
|
|
297
|
+
else:
|
|
298
|
+
vf = f"showspectrum=s={args.width}x{vis_h}:mode={'separate' if args.split_channels else 'combined'}:fps={args.fps:g}"
|
|
299
|
+
if args.image:
|
|
300
|
+
# One filter_complex, one encode: the still gets a timeline with -loop 1, is scaled to the
|
|
301
|
+
# frame by --image-fit, and the visualisation is overlaid on it at --opacity.
|
|
302
|
+
if args.image_fit == "cover":
|
|
303
|
+
plate = (f"scale={args.width}:{args.height}:force_original_aspect_ratio=increase,"
|
|
304
|
+
f"crop={args.width}:{args.height},setsar=1")
|
|
305
|
+
else:
|
|
306
|
+
plate = pad_filters(args.width, args.height,
|
|
307
|
+
"blur" if args.image_fit == "blur" else "color",
|
|
308
|
+
args.background, 20)
|
|
309
|
+
# a non-square-pixel still is squared at its display aspect before it is fitted (#411)
|
|
310
|
+
plate_v = probe(args.image, role="input").get("video") if not STATE.dry_run else None
|
|
311
|
+
plate_sq = square_pixels(plate_v)
|
|
312
|
+
if plate_sq:
|
|
313
|
+
note(square_pixels_note(plate_v, "--image"))
|
|
314
|
+
graph = f"[1:v]{plate_sq + ',' if plate_sq else ''}{plate},format=rgba[plate];[0:a:{args.audio_stream}]{vf},format=rgba"
|
|
315
|
+
if args.opacity < 1.0:
|
|
316
|
+
graph += f",colorchannelmixer=aa={args.opacity:g}"
|
|
317
|
+
# the composite is RGBA (the plate is): converted to the BT.709 the output is tagged with,
|
|
318
|
+
# not by the encoder's BT.601 default
|
|
319
|
+
graph += f"[vis];[plate][vis]overlay=x=(W-w)/2:y={vis_y}:format=auto{rgb_chain_to_bt709(None, 'yuv420p')}[v]"
|
|
320
|
+
vf = graph
|
|
321
|
+
else:
|
|
322
|
+
# showwaves/showspectrum paint the visualization on a transparent-black canvas; composite
|
|
323
|
+
# it over an explicit solid background instead of assuming that canvas already matches
|
|
324
|
+
# --background.
|
|
325
|
+
bg, vis = f"color=c={args.background}:s={args.width}x{args.height}:r={args.fps:g}", vf
|
|
326
|
+
if draws_chroma([args.background] + (args.color.split("|") if args.style == "waveform" else []), None):
|
|
327
|
+
# the background and the RGBA waves are converted to the BT.709 the output is tagged
|
|
328
|
+
# with (the encoder line's own RGB-to-YUV step used BT.601); the spectrum is YUV of its
|
|
329
|
+
# own and only gets the label the background carries, so 7.1+'s overlay converts neither
|
|
330
|
+
bg += ",format=rgb24" + rgb_chain_to_bt709(None, "yuv420p")
|
|
331
|
+
vis += rgb_chain_to_bt709(None, "yuva420p") if args.style == "waveform" else ",setparams=colorspace=bt709"
|
|
332
|
+
vf = f"{bg}[bg];[0:a:{args.audio_stream}]{vis}[vis];[bg][vis]overlay=format=auto"
|
|
333
|
+
|
|
334
|
+
render = output
|
|
335
|
+
if args.title or args.srt or args.text:
|
|
336
|
+
# the visualisation is rendered first and the label/captions are drawn on it by the tools
|
|
337
|
+
# that own those code paths, so neither is re-implemented here
|
|
338
|
+
# hidden, pid-named siblings (#408): a fixed `<out>_vis` name was removed afterwards
|
|
339
|
+
# whoever had written it, the input or another file of the caller's included
|
|
340
|
+
render = sibling_temp(output, "vis")
|
|
341
|
+
cmd = ffmpeg_base() + ["-i", args.input]
|
|
342
|
+
if args.image:
|
|
343
|
+
# -framerate before -loop: a looped still defaults to 25 fps, and overlay takes its rate
|
|
344
|
+
# from the FIRST input -- so without this the file came out 25 fps however loud --fps or
|
|
345
|
+
# --platform said otherwise (the colour-plate path never had the bug: `color=` carries r=).
|
|
346
|
+
cmd += ["-framerate", f"{args.fps:g}", "-loop", "1", *still_input_args(args.image), "-i", args.image]
|
|
347
|
+
cmd += ["-filter_complex", vf]
|
|
348
|
+
if args.image:
|
|
349
|
+
cmd += ["-map", "[v]"]
|
|
350
|
+
cmd += ["-map", f"0:a:{args.audio_stream}"]
|
|
351
|
+
cmd += video_args(None, args.crf, args.preset) # the one encoder line, so --codec / --quality reach it (review 7)
|
|
352
|
+
cmd += aac_args()
|
|
353
|
+
# -shortest alone is not enough on FFmpeg 5.x: showwaves keeps emitting frames after the
|
|
354
|
+
# audio ends (a 12 s source came out 14.08 s on 5.1.1, #146), so the output is also capped
|
|
355
|
+
# at the source's own duration when probe knows it.
|
|
356
|
+
if meta.get("duration"):
|
|
357
|
+
# to the sample of the drawn track when the millisecond would cut it (length_output_t)
|
|
358
|
+
drawn_track = audio_streams[args.audio_stream] if audio_streams else meta["audio"]
|
|
359
|
+
cmd += ["-t", length_output_t(float(meta["duration"]), drawn_track.get("sample_rate"))]
|
|
360
|
+
cmd += ["-shortest", render]
|
|
361
|
+
if args.title or args.srt or args.text:
|
|
362
|
+
# #510: the title and captions are later stages; one that needs a filter this build lacks
|
|
363
|
+
# (drawtext, subtitles) is refused before the visualisation is encoded, as the dry run is
|
|
364
|
+
refuse_missing_components_first(os.path.abspath(__file__), "stage's filters and encoders")
|
|
365
|
+
titled_tmp = sibling_temp(output, "titled")
|
|
366
|
+
intermediates = [p for p in (render, titled_tmp) if p != output]
|
|
367
|
+
try:
|
|
368
|
+
run(cmd)
|
|
369
|
+
|
|
370
|
+
stages = ["waveform"]
|
|
371
|
+
current = render
|
|
372
|
+
if args.title:
|
|
373
|
+
titled = titled_tmp if (args.srt or args.text) else output
|
|
374
|
+
if titled == titled_tmp:
|
|
375
|
+
# graphics.py's libass route writes <its output stem>_gfx.ass beside it (#413 review)
|
|
376
|
+
titled_ass = os.path.splitext(titled)[0] + "_gfx.ass"
|
|
377
|
+
if not os.path.exists(titled_ass):
|
|
378
|
+
intermediates.append(titled_ass)
|
|
379
|
+
# a dry run rendered no _vis file for graphics.py to probe, so its default --end (the
|
|
380
|
+
# clip's end) came out 0 and the plan failed: give it the source's duration, which
|
|
381
|
+
# is what -t caps the render at. A real run is unchanged.
|
|
382
|
+
end = (["--end", f"{float(meta['duration']):.3f}"]
|
|
383
|
+
if STATE.dry_run and meta.get("duration") else [])
|
|
384
|
+
_child("graphics.py", [current, "--template", "sticker", "--text", args.title,
|
|
385
|
+
"--position", "top-left"] + end + ["-o", titled]
|
|
386
|
+
+ (["--brand", args.brand] if args.brand else []))
|
|
387
|
+
stages.append("title")
|
|
388
|
+
current = titled
|
|
389
|
+
if args.srt or args.text:
|
|
390
|
+
_child("caption.py", [current] + (["--srt", args.srt] if args.srt else ["--text", args.text])
|
|
391
|
+
+ (["--platform", args.platform] if args.platform else []) + ["-o", output])
|
|
392
|
+
stages.append("captions")
|
|
393
|
+
current = output
|
|
394
|
+
if current != output and not STATE.dry_run:
|
|
395
|
+
os.replace(current, output)
|
|
396
|
+
current = output
|
|
397
|
+
finally:
|
|
398
|
+
# the intermediates exist only to keep each tool's own code path the only one there is;
|
|
399
|
+
# a failed stage removes them too, not only a finished chain
|
|
400
|
+
if not STATE.dry_run:
|
|
401
|
+
for temp in intermediates:
|
|
402
|
+
if os.path.exists(temp):
|
|
403
|
+
os.remove(temp)
|
|
404
|
+
|
|
405
|
+
result = probe(output, role="output")
|
|
406
|
+
v = result["video"] or {}
|
|
407
|
+
notes: "list" = []
|
|
408
|
+
if args.image and args.platform and args.srt:
|
|
409
|
+
safe_px = int(round(PLATFORMS[args.platform]["safe"]["bottom"] * args.height))
|
|
410
|
+
overlap = (vis_h + safe_px) - args.height
|
|
411
|
+
if args.position in ("strip", "bottom") and overlap > 0:
|
|
412
|
+
notes.append(f"the visualisation band and {args.platform}'s bottom safe zone overlap by "
|
|
413
|
+
f"{overlap}px: the captions or the app's own UI will sit over the waveform "
|
|
414
|
+
f"(lower --vis-height to {max(0.05, (args.height - safe_px) / args.height):.2f})")
|
|
415
|
+
if STATE.dry_run and (args.title or args.srt or args.text):
|
|
416
|
+
# graphics.py / caption.py plan on the render this dry run did not write, whose frame they
|
|
417
|
+
# cannot measure: their sizes and offsets come out 0 in the plan, and the real run takes
|
|
418
|
+
# them from the WxH render (#415). Said here, so a plan is not read as the real numbers.
|
|
419
|
+
later = " and ".join(n for n, on in (("title", args.title), ("captions", args.srt or args.text)) if on)
|
|
420
|
+
notes.append(f"the {later} stage was planned on the visualisation render this dry run did not write, so the "
|
|
421
|
+
f"font sizes and offsets in its planned command are placeholders (0); the real run sizes them "
|
|
422
|
+
f"from the {args.width}x{args.height} render")
|
|
423
|
+
if silent_peak is not None:
|
|
424
|
+
warn(f"{args.input} is silent (peak {silent_peak:g} dBFS); the visualisation is a flat line", "silent_input",
|
|
425
|
+
path=args.input, peak_db=silent_peak)
|
|
426
|
+
notes.append(f"the input audio is silent (peak {silent_peak:g} dBFS, at or below --silence-threshold "
|
|
427
|
+
f"{args.silence_threshold:g}): the visualisation is a flat line; pass --on-silent fail to refuse instead")
|
|
428
|
+
duration_ok = True
|
|
429
|
+
if not STATE.dry_run and meta.get("duration") and result.get("duration"):
|
|
430
|
+
duration_ok = abs(float(result["duration"]) - float(meta["duration"])) <= 0.05
|
|
431
|
+
if not duration_ok:
|
|
432
|
+
notes.append("the render is " + fmt_secs(result.get("duration")) + " against "
|
|
433
|
+
+ fmt_secs(meta.get("duration")) + " of audio")
|
|
434
|
+
size_ok = (v.get("width"), v.get("height")) == (args.width, args.height) or STATE.dry_run
|
|
435
|
+
# the rate the run announced is the rate the file must carry: the audiogram path builds the
|
|
436
|
+
# plate as a second input, so getting this wrong is silent (see the -framerate above)
|
|
437
|
+
fps_ok = True
|
|
438
|
+
if not STATE.dry_run and v.get("fps"):
|
|
439
|
+
fps_ok = abs(float(v["fps"]) - float(args.fps)) <= 0.01
|
|
440
|
+
if not fps_ok:
|
|
441
|
+
notes.append(f"the render is {float(v['fps']):g} fps against the {args.fps:g} fps asked for")
|
|
442
|
+
# reported on every run, not only an audiogram one: a caller that keys on `audiogram.background`
|
|
443
|
+
# should not have to guess whether the key exists (`"color"` is the plain-waveform answer).
|
|
444
|
+
extra = {"silent": None if STATE.dry_run else silent_peak is not None, "audiogram": {
|
|
445
|
+
"style": args.style,
|
|
446
|
+
"background": "image" if args.image else "color",
|
|
447
|
+
"image": args.image,
|
|
448
|
+
"position": args.position if args.image else None,
|
|
449
|
+
"vis_height": args.vis_height if args.image else 1.0,
|
|
450
|
+
"platform": args.platform,
|
|
451
|
+
"captions": (args.srt or args.text) if (args.srt or args.text) else None,
|
|
452
|
+
"title": args.title,
|
|
453
|
+
"stages": stages,
|
|
454
|
+
# a dry run rendered nothing, so there is nothing to have verified -- the common
|
|
455
|
+
# top-level `verified` says false for the same run and these two must not disagree
|
|
456
|
+
"verified": False if STATE.dry_run else bool(duration_ok and size_ok and fps_ok),
|
|
457
|
+
}}
|
|
458
|
+
if notes:
|
|
459
|
+
extra["notes"] = notes
|
|
460
|
+
info(f"wrote {output} ({fmt_secs(result['duration'])}, {v.get('width')}x{v.get('height')}, {args.style}"
|
|
461
|
+
+ (", audiogram" if args.image else "") + ")")
|
|
462
|
+
emit(output, **extra)
|
|
463
|
+
return 0
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
def _child(script_name: str, argv: "list") -> None:
|
|
467
|
+
"""Run one of this skill's own tools as a second process, so the code path it owns (the ASS
|
|
468
|
+
generator, the drawtext template) stays the only one there is. The shared flags (--overwrite,
|
|
469
|
+
--timeout, --fast, --dry-run) reach it through child_args(), as render.py's stages get them,
|
|
470
|
+
and a failure is re-raised with the child's own kind, exit code and hint.
|
|
471
|
+
|
|
472
|
+
The GPU choice reaches it too: an explicit --hw/--no-hw is passed on (the child would
|
|
473
|
+
otherwise resolve $FFMPEG_SKILL_HW for itself, and the last stage writes the deliverable),
|
|
474
|
+
and the child's commands and `hw` facts join this result, so `encoder`/`hw` describe the
|
|
475
|
+
file delivered rather than the intermediate render."""
|
|
476
|
+
here = os.path.dirname(os.path.abspath(__file__))
|
|
477
|
+
hw = (["--hw"] if STATE.hw else ["--no-hw"]) if STATE.hw_source == "flag" else []
|
|
478
|
+
cmd = [os.path.join(here, script_name)] + [str(a) for a in argv] + hw + child_args() + ["--json"]
|
|
479
|
+
info("-> " + " ".join(os.path.basename(c) if c.endswith(".py") else str(c) for c in cmd[:-1]))
|
|
480
|
+
proc = run_tool(cmd)
|
|
481
|
+
try:
|
|
482
|
+
doc = json.loads(proc.stdout.strip() or "{}")
|
|
483
|
+
except ValueError:
|
|
484
|
+
doc = {}
|
|
485
|
+
if not isinstance(doc, dict):
|
|
486
|
+
doc = {}
|
|
487
|
+
STATE.commands.extend(str(c) for c in (doc.get("commands") or []))
|
|
488
|
+
absorb_stage_hw(os.path.splitext(script_name)[0], doc)
|
|
489
|
+
if proc.returncode != 0:
|
|
490
|
+
err = doc.get("error") or {}
|
|
491
|
+
extra = {"hint": err["hint"]} if err.get("hint") else {}
|
|
492
|
+
if doc.get("encoder"):
|
|
493
|
+
extra["encoder"] = doc["encoder"]
|
|
494
|
+
# the stage's own reason and details ride along (#402: a caller keyed on error.reason saw
|
|
495
|
+
# filter_missing from caption.py and graphics.py run by hand, and nothing from here)
|
|
496
|
+
why = {k: err[k] for k in ("reason", "details") if err.get(k) is not None}
|
|
497
|
+
die(f"{script_name} failed: {err.get('message') or (proc.stderr.strip().splitlines() or ['?'])[-1][:300]}",
|
|
498
|
+
code=int(doc.get("exit_code") or 1), kind=err.get("kind") or "input", stage=script_name,
|
|
499
|
+
error_extra=why or None, **extra)
|
|
500
|
+
|
|
501
|
+
if __name__ == "__main__":
|
|
502
|
+
sys.exit(main())
|