ffmpeg-skill 0.4.1 → 0.6.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 +12 -0
- package/SKILL.md +80 -7
- package/package.json +2 -2
- package/scripts/__pycache__/_common.cpython-311.pyc +0 -0
- package/scripts/__pycache__/caption.cpython-311.pyc +0 -0
- package/scripts/__pycache__/check.cpython-311.pyc +0 -0
- package/scripts/__pycache__/export.cpython-311.pyc +0 -0
- package/scripts/__pycache__/fit.cpython-311.pyc +0 -0
- package/scripts/__pycache__/graphics.cpython-311.pyc +0 -0
- package/scripts/__pycache__/join.cpython-311.pyc +0 -0
- package/scripts/__pycache__/loudness.cpython-311.pyc +0 -0
- package/scripts/__pycache__/overlay.cpython-311.pyc +0 -0
- package/scripts/__pycache__/render.cpython-311.pyc +0 -0
- package/scripts/__pycache__/report.cpython-311.pyc +0 -0
- package/scripts/__pycache__/scenes.cpython-311.pyc +0 -0
- package/scripts/__pycache__/sync.cpython-311.pyc +0 -0
- package/scripts/_common.py +52 -2
- package/scripts/caption.py +27 -9
- package/scripts/check.py +163 -0
- package/scripts/export.py +3 -1
- package/scripts/fit.py +2 -0
- package/scripts/graphics.py +166 -0
- package/scripts/join.py +13 -6
- package/scripts/loudness.py +3 -1
- package/scripts/overlay.py +24 -2
- package/scripts/render.py +362 -0
- package/scripts/report.py +162 -0
- package/scripts/scenes.py +155 -0
package/README.md
CHANGED
|
@@ -17,6 +17,12 @@ npx ffmpeg-skill
|
|
|
17
17
|
- **Probe first, verify last** — the skill forces the agent to read real duration/fps/resolution before editing and to check the result after, so you get "final.mp4: 59.98 s, 1080×1920, 30 fps" instead of guesses.
|
|
18
18
|
- **Lossless when possible** — cuts and joins use stream copy by default; re-encoding only happens when it must (frame-accurate cuts, filters, format changes).
|
|
19
19
|
- **Cut & join** segments with `mm:ss` / `hh:mm:ss.ms` times.
|
|
20
|
+
- **Declarative edits** — describe the whole edit in a `project.json` (clips, transitions, captions, overlays, music, loudness, export, check) and re-render after every tweak.
|
|
21
|
+
- **Brand kit** — one `brand.json` (fonts, colours, logo, safe margins, caption style) applied by captions, overlays, graphics and projects.
|
|
22
|
+
- **Motion graphics without assets** — lower-thirds, title cards, chapter chips, progress bars, countdowns and corner bugs drawn by FFmpeg.
|
|
23
|
+
- **HTML delivery report** — before/after contact sheets, media facts, loudness, compliance and the commands run, in one file.
|
|
24
|
+
- **Scene detection and highlight picks** — find cuts and loud moments, get a 60-second digest proposal as a cut list.
|
|
25
|
+
- **Delivery checks** — PASS/FAIL against YouTube, Shorts, Reels, TikTok, X, LinkedIn, broadcast and podcast specs, with the fix for each failure.
|
|
20
26
|
- **Multicam** — align any number of cameras and recorders by audio (with drift correction) and cut between them from a switch list.
|
|
21
27
|
- **Real-footage verification kit** — run the whole toolchain on your own device files and get a PASS/FAIL report.
|
|
22
28
|
- **Silence removal / jump cuts** — detect dead air, keep a margin around speech, render frame-accurate in one pass; export the cut list for hand editing.
|
|
@@ -92,6 +98,11 @@ More examples: [examples/README.md](examples/README.md). To see everything run e
|
|
|
92
98
|
|--------|--------------|
|
|
93
99
|
| `probe.py` | Duration, fps (+ VFR detection), resolution, codecs, bit depth, HDR format incl. Dolby Vision, colour space, rotation, audio channels as JSON; `--analyze` flags Log footage |
|
|
94
100
|
| `cut.py` | In/out or multi-segment cuts, lossless `-c copy` first, re-encode fallback, `--accurate` for frame-exact |
|
|
101
|
+
| `render.py` | Render a whole edit from `project.json`; `--init`, `--dry-run`, `--stop-after` |
|
|
102
|
+
| `graphics.py` | Lower-third, title, chapter, progress, countdown, bug templates (brand colours) |
|
|
103
|
+
| `report.py` | Single-file HTML delivery report with sheets, facts, loudness, compliance, commands |
|
|
104
|
+
| `scenes.py` | Scene changes, audio peaks, highlight proposals and per-scene sheet |
|
|
105
|
+
| `check.py` | Pre-delivery compliance per platform (duration, aspect, codec, colour, loudness, size) |
|
|
95
106
|
| `multicam.py` | Align cameras/recorders by audio and switch between them from a time list |
|
|
96
107
|
| `verify.py` | Run the toolchain on real device files and report PASS/FAIL per step |
|
|
97
108
|
| `silence.py` | Detect and remove silences (jump cuts), list or export the cut list |
|
|
@@ -119,6 +130,7 @@ All scripts: Python 3.9+, standard library only, `--help`, non-zero exit + stder
|
|
|
119
130
|
```bash
|
|
120
131
|
bash examples/make_demo.sh # generates footage, runs every script, rebuilds assets/demo.gif
|
|
121
132
|
python3 tests/test_all.py # end-to-end tests incl. VFR, rotated, 5.1, 10-bit HDR10 and drifting sources (needs ffmpeg)
|
|
133
|
+
python3 evals/run.py --list # routing eval prompts (see evals/)
|
|
122
134
|
node bin/install.js --dir /tmp/skills # try the installer without touching ~/.claude
|
|
123
135
|
```
|
|
124
136
|
|
package/SKILL.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: ffmpeg-skill
|
|
3
|
-
description: Professional video editing with local FFmpeg —
|
|
3
|
+
description: Professional video editing with local FFmpeg — declarative project rendering, brand kits, motion-graphics templates (lower-thirds, titles, countdowns), HTML delivery reports, scene detection and highlight picks, delivery compliance checks, cut, silence removal, transitions, multicam, captions (animated/karaoke timed to speech), fit to duration/aspect, audio sync with drift correction, HDR/HLG/Dolby Vision to SDR, LUTs, audio clean-up and ducking, loudness, overlays, platform exports, frame inspection and a real-footage verification kit; Python stdlib scripts, no cloud or API keys.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# ffmpeg-skill
|
|
@@ -30,15 +30,23 @@ path on stdout, and defaults the output name to `<input>_<operation>.<ext>`.
|
|
|
30
30
|
`--fast` gives a quick preview-quality render (x264 veryfast), `--progress`
|
|
31
31
|
prints percent and ETA on stderr for long encodes.
|
|
32
32
|
4. **Chain operations in a sensible order.** Colour (HDR→SDR / LUT) → cut →
|
|
33
|
-
fit → caption/overlay → sync → audio → loudness → export.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
CRF 18 (the default) and only use `export.py` for the last step
|
|
37
|
-
|
|
33
|
+
join → silence → fit → caption/overlay → sync → audio → loudness → export.
|
|
34
|
+
Do frame changes (fit/crop) before captions and overlays so text is sized
|
|
35
|
+
for the final frame. Re-encode as few times as possible: keep intermediates
|
|
36
|
+
at CRF 18 (the default) and only use `export.py` for the last step; for
|
|
37
|
+
anything with more than two steps use `render.py` with a project.json.
|
|
38
|
+
5. **Check the deliverable.** Before reporting, run `check.py OUTPUT --platform X`
|
|
39
|
+
for the destination the user named; fix FAILs, mention WARNs.
|
|
40
|
+
6. **Verify the output.** Run `probe.py` on each result and confirm duration,
|
|
38
41
|
resolution, fps and audio match what was requested. Report those numbers to
|
|
39
42
|
the user (e.g. "final.mp4: 59.98 s, 1080x1920, 30 fps, AAC stereo").
|
|
40
|
-
|
|
43
|
+
7. **Keep the user's originals.** Never overwrite the source file. Write new
|
|
41
44
|
files next to the input or where the user asked.
|
|
45
|
+
8. **Look at the picture.** After captioning, overlaying, cropping or colour
|
|
46
|
+
work run `look.py OUTPUT` (contact sheet) or `look.py OUTPUT --at T` and
|
|
47
|
+
view the PNG: text inside the frame and not over faces, logos where asked,
|
|
48
|
+
crops keeping the subject, colours not washed out. Fix and re-run before
|
|
49
|
+
reporting. Numbers from probe are not enough.
|
|
42
50
|
|
|
43
51
|
## Request → script
|
|
44
52
|
|
|
@@ -61,6 +69,12 @@ path on stdout, and defaults the output name to `<input>_<operation>.<ext>`.
|
|
|
61
69
|
| "stitch these clips together", "add a crossfade between them" | `join.py a.mp4 b.mp4 c.mp4 --transition fade --duration 0.5` |
|
|
62
70
|
| "show me what it looks like", "check the captions are readable" | `look.py output.mp4` then view the PNG |
|
|
63
71
|
| "what would you run?", "don't render yet" | any script with `--dry-run` |
|
|
72
|
+
| "make a 60 s highlight from this hour", "find the good bits" | `scenes.py long.mp4 --highlights 6 --target 60 --edl picks.txt` → `cut.py --segments` |
|
|
73
|
+
| "is this OK to upload?", "check it meets the Reels spec" | `check.py final.mp4 --platform reels` |
|
|
74
|
+
| "set it up so I can tweak and re-render", "several changes to the same edit" | `render.py --init project.json`, edit, `render.py project.json` |
|
|
75
|
+
| "add a lower third with my name", "title card", "countdown intro", "progress bar" | `graphics.py input.mp4 --template lower-third --name "..." --title "..." --start 2 --end 8` |
|
|
76
|
+
| "use our brand fonts/colours/logo" | pass `--brand brand.json` to caption/overlay/graphics, or `"brand"` in project.json |
|
|
77
|
+
| "send me a summary of what you did" | `report.py --before raw.mov --after final.mp4 --platform youtube -o report.html` |
|
|
64
78
|
| "three cameras, cut between them" | `multicam.py camA.mp4 camB.mp4 camC.mp4 --switch "0-20:0,20-40:1,40-60:2"` |
|
|
65
79
|
| "it's an iPhone Dolby Vision clip and players show it wrong" | `color.py clip.mov --to-sdr` or `color.py clip.mov --strip-dovi` (keep HDR, drop the DV layer) |
|
|
66
80
|
| "does it look like Log / S-Log / flat footage?" | `probe.py clip.mp4 --analyze` (`looks_like_log`) then `color.py --lut` |
|
|
@@ -132,6 +146,65 @@ Normalises every clip to one frame size, fps, `yuv420p` and 48 kHz stereo
|
|
|
132
146
|
`acrossfade`. Output length = sum of clips − transition × (n−1). Clips must be
|
|
133
147
|
longer than 2 × the transition. Use `--transition none` for a plain cut.
|
|
134
148
|
|
|
149
|
+
### render.py — the whole edit in one project.json
|
|
150
|
+
```
|
|
151
|
+
render.py --init project.json # starter file
|
|
152
|
+
render.py project.json [--fast] [--dry-run] [--stop-after STAGE] [--work DIR --keep]
|
|
153
|
+
```
|
|
154
|
+
Stages: clips (cut, optional speed) → join (transition) → silence → fit →
|
|
155
|
+
captions → graphics → overlays → audio → loudness → export → check. Keys mirror the
|
|
156
|
+
CLI flags of each script (see the docstring). Use it whenever an edit has
|
|
157
|
+
more than two steps or the user is likely to ask for changes: edit the JSON,
|
|
158
|
+
re-render, and the result is reproducible. `--dry-run --json` prints the
|
|
159
|
+
complete command plan for review.
|
|
160
|
+
|
|
161
|
+
### scenes.py — scene changes and highlight candidates
|
|
162
|
+
```
|
|
163
|
+
scenes.py INPUT [--threshold 10] [--min-scene 1] [--highlights N [--target SECONDS] [--max-scene 15]] [--edl picks.txt] [--sheet scenes.png] [--json]
|
|
164
|
+
```
|
|
165
|
+
Lists scenes with audio energy, the loudest moments, and (with
|
|
166
|
+
`--highlights`) proposes N ranges that add up to `--target` seconds, biased to
|
|
167
|
+
the loudest window of each scene. Review the sheet + JSON, adjust the EDL, then
|
|
168
|
+
`cut.py --segments`. It is a proposal engine, not a judgement of content:
|
|
169
|
+
tell the user what it picked and why (energy, scene length).
|
|
170
|
+
|
|
171
|
+
### check.py — pre-delivery compliance
|
|
172
|
+
```
|
|
173
|
+
check.py INPUT --platform youtube|shorts|reels|tiktok|x|linkedin|broadcast|podcast|custom [--no-loudness] [--json]
|
|
174
|
+
[--max-duration S] [--aspect 9:16] [--lufs -14] [--tp -1] [--max-mb N]
|
|
175
|
+
```
|
|
176
|
+
PASS/WARN/FAIL per check with the script that fixes it. Run it as the final
|
|
177
|
+
step before reporting a deliverable; fix FAILs, mention WARNs.
|
|
178
|
+
|
|
179
|
+
### graphics.py — motion-graphics templates
|
|
180
|
+
```
|
|
181
|
+
graphics.py INPUT --template lower-third|title|chapter|progress|countdown|bug [--name] [--title] [--subtitle]
|
|
182
|
+
[--from N] [--start S] [--end E] [--position CORNER] [--brand brand.json] [--primary RRGGBB] [--scale 1.0] [-o OUT]
|
|
183
|
+
```
|
|
184
|
+
Drawn with drawbox/drawtext/overlay — no PNG assets needed. Sizes scale with
|
|
185
|
+
the frame's short side; colours, font and safe margin come from `--brand`.
|
|
186
|
+
Lower-third slides in over 0.4 s and out over 0.3 s; title/chapter/bug fade.
|
|
187
|
+
|
|
188
|
+
### brand.json — one file for fonts, colours, logo, margins
|
|
189
|
+
```json
|
|
190
|
+
{"font": "Noto Sans CJK JP", "font_file": "fonts/NotoSansCJK-Bold.ttc",
|
|
191
|
+
"colors": {"primary": "FF6A00", "text": "FFFFFF", "outline": "000000", "background": "0B1D2A"},
|
|
192
|
+
"logo": "logo.png", "logo_position": "top-right", "logo_scale": 160, "logo_opacity": 0.9,
|
|
193
|
+
"safe_margin": 48, "caption": {"size": 28, "position": "bottom", "animate": "pop", "karaoke": true, "bold": true}}
|
|
194
|
+
```
|
|
195
|
+
`caption.py --brand`, `overlay.py --brand --logo`, `graphics.py --brand`, and
|
|
196
|
+
`"brand": "brand.json"` in a render project. Explicit flags still win. When a
|
|
197
|
+
user mentions brand guidelines, colours, "our font" or a logo, ask for or
|
|
198
|
+
write a brand.json once and reuse it across every output.
|
|
199
|
+
|
|
200
|
+
### report.py — HTML delivery report
|
|
201
|
+
```
|
|
202
|
+
report.py --after FINAL [--before SOURCE] [--platform youtube] [--commands cmds.txt] [--notes notes.md] [--title T] [--no-sheets] [-o report.html]
|
|
203
|
+
```
|
|
204
|
+
One self-contained HTML: before/after facts and contact sheets, loudness,
|
|
205
|
+
compliance table with fixes, commands. Produce it for any multi-step job and
|
|
206
|
+
hand the path to the user together with the numbers.
|
|
207
|
+
|
|
135
208
|
### multicam.py — align several cameras and switch between them
|
|
136
209
|
```
|
|
137
210
|
multicam.py REF CAM2 [CAM3 ...] [--switch "START-END:CAM,..."] | [--auto N] [--audio IDX] [--fix-drift]
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ffmpeg-skill",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Agent Skill that lets coding agents (Claude Code, Cursor, Codex) do professional video editing with local FFmpeg: cut, silence removal, transitions, multicam, captions, sync with drift correction, HDR to SDR, LUTs, audio clean-up and ducking, loudness, platform exports. No API keys, no cloud, no dependencies.",
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "Agent Skill that lets coding agents (Claude Code, Cursor, Codex) do professional video editing with local FFmpeg: declarative project rendering, brand kits, motion-graphics templates, HTML delivery reports, scene detection, delivery checks, cut, silence removal, transitions, multicam, captions, sync with drift correction, HDR to SDR, LUTs, audio clean-up and ducking, loudness, platform exports. No API keys, no cloud, no dependencies.",
|
|
5
5
|
"keywords": ["ffmpeg", "video", "agent-skill", "claude-code", "cursor", "codex", "skill", "video-editing"],
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "kajisho5",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/scripts/_common.py
CHANGED
|
@@ -55,6 +55,7 @@ def require_tool(name: str) -> str:
|
|
|
55
55
|
return "" # unreachable
|
|
56
56
|
|
|
57
57
|
|
|
58
|
+
X264_PRESETS = ("ultrafast", "superfast", "veryfast", "faster", "fast", "medium", "slow", "slower", "veryslow", "placebo")
|
|
58
59
|
STATE: Dict[str, Any] = {"dry_run": False, "json": False, "commands": [], "progress": False, "fast": False, "duration_hint": None}
|
|
59
60
|
|
|
60
61
|
|
|
@@ -72,7 +73,7 @@ def apply_common(args: "argparse.Namespace") -> None:
|
|
|
72
73
|
STATE["json"] = bool(getattr(args, "json", False))
|
|
73
74
|
STATE["progress"] = bool(getattr(args, "progress", False))
|
|
74
75
|
STATE["fast"] = bool(getattr(args, "fast", False))
|
|
75
|
-
if STATE["fast"] and
|
|
76
|
+
if STATE["fast"] and getattr(args, "preset", None) in X264_PRESETS:
|
|
76
77
|
args.preset = "veryfast"
|
|
77
78
|
|
|
78
79
|
|
|
@@ -163,7 +164,7 @@ def probe(path: str) -> Dict[str, Any]:
|
|
|
163
164
|
if not os.path.exists(path):
|
|
164
165
|
if STATE["dry_run"]:
|
|
165
166
|
return {"file": path, "dry_run": True, "format": None, "duration": 0.0, "size_bytes": 0, "bitrate": None,
|
|
166
|
-
"video": {"codec": None, "width":
|
|
167
|
+
"video": {"codec": None, "width": 1920, "height": 1080, "fps": 30.0, "pix_fmt": None, "hdr": False,
|
|
167
168
|
"color_transfer": None, "color_primaries": None, "rotation": 0, "variable_frame_rate_suspected": False},
|
|
168
169
|
"audio": {"codec": None, "channels": 0, "sample_rate": 0}, "subtitle_streams": 0}
|
|
169
170
|
die(f"input not found: {path}")
|
|
@@ -416,6 +417,55 @@ def analyze_levels(path: str, seconds: float = 20.0) -> Dict[str, Any]:
|
|
|
416
417
|
}
|
|
417
418
|
|
|
418
419
|
|
|
420
|
+
BRAND_DEFAULTS: Dict[str, Any] = {
|
|
421
|
+
"font": "DejaVu Sans",
|
|
422
|
+
"font_file": None,
|
|
423
|
+
"colors": {"primary": "FFD200", "text": "FFFFFF", "outline": "000000", "background": "101418", "accent": "1E6F8E"},
|
|
424
|
+
"logo": None,
|
|
425
|
+
"logo_position": "top-right",
|
|
426
|
+
"logo_scale": 160,
|
|
427
|
+
"logo_opacity": 0.9,
|
|
428
|
+
"safe_margin": 48,
|
|
429
|
+
"caption": {"size": 26, "position": "bottom", "animate": "pop", "karaoke": False, "bold": True, "outline": 2},
|
|
430
|
+
"loudness": {"lufs": -14, "tp": -1},
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
def load_brand(path: Optional[str]) -> Dict[str, Any]:
|
|
435
|
+
"""Load brand.json (fonts, colours, logo, safe margins, caption defaults); missing keys fall back to defaults."""
|
|
436
|
+
import copy
|
|
437
|
+
brand = copy.deepcopy(BRAND_DEFAULTS)
|
|
438
|
+
if not path:
|
|
439
|
+
return brand
|
|
440
|
+
if not os.path.exists(path):
|
|
441
|
+
die(f"brand file not found: {path}")
|
|
442
|
+
try:
|
|
443
|
+
data = json.loads(Path(path).read_text(encoding="utf-8"))
|
|
444
|
+
except ValueError as exc:
|
|
445
|
+
die(f"brand file is not valid JSON: {exc}")
|
|
446
|
+
base = Path(path).resolve().parent
|
|
447
|
+
for k, v in data.items():
|
|
448
|
+
if isinstance(v, dict) and isinstance(brand.get(k), dict):
|
|
449
|
+
brand[k].update(v)
|
|
450
|
+
else:
|
|
451
|
+
brand[k] = v
|
|
452
|
+
for key in ("logo", "font_file"):
|
|
453
|
+
if brand.get(key) and not os.path.isabs(brand[key]):
|
|
454
|
+
brand[key] = str(base / brand[key])
|
|
455
|
+
brand["_path"] = str(path)
|
|
456
|
+
return brand
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
def color_hex(value: str) -> str:
|
|
460
|
+
"""Normalise '#ffd200' / 'ffd200' / '0xFFD200' to 'FFD200'."""
|
|
461
|
+
v = str(value).strip().lstrip("#")
|
|
462
|
+
if v.lower().startswith("0x"):
|
|
463
|
+
v = v[2:]
|
|
464
|
+
if len(v) != 6:
|
|
465
|
+
die(f"colour must be RRGGBB, got '{value}'")
|
|
466
|
+
return v.upper()
|
|
467
|
+
|
|
468
|
+
|
|
419
469
|
def print_json(obj: Any) -> None:
|
|
420
470
|
sys.stdout.write(json.dumps(obj, indent=2, ensure_ascii=False) + "\n")
|
|
421
471
|
|
package/scripts/caption.py
CHANGED
|
@@ -20,9 +20,10 @@ import argparse
|
|
|
20
20
|
import os
|
|
21
21
|
import re
|
|
22
22
|
import sys
|
|
23
|
+
from pathlib import Path
|
|
23
24
|
from typing import List, Tuple
|
|
24
25
|
|
|
25
|
-
from _common import video_args, add_common, apply_common, emit, aac_args, cfr_args, default_output, die, escape_filter_path, ffmpeg_base, fmt_srt_time, info, parse_time, probe, run, x264_args
|
|
26
|
+
from _common import color_hex, load_brand, video_args, add_common, apply_common, emit, aac_args, cfr_args, default_output, die, escape_filter_path, ffmpeg_base, fmt_srt_time, info, parse_time, probe, run, x264_args
|
|
26
27
|
|
|
27
28
|
ALIGN = {"bottom": 2, "top": 8, "center": 5, "bottom-left": 1, "bottom-right": 3, "top-left": 7, "top-right": 9}
|
|
28
29
|
|
|
@@ -220,21 +221,22 @@ def main() -> int:
|
|
|
220
221
|
src.add_argument("--auto-seconds", type=float, default=3.0, help="duration for cues without timing (default 3)")
|
|
221
222
|
src.add_argument("--gap", type=float, default=0.0, help="gap after auto-timed cues in seconds")
|
|
222
223
|
sty = ap.add_argument_group("style (SRT only)")
|
|
223
|
-
sty.add_argument("--
|
|
224
|
+
sty.add_argument("--brand", help="brand.json: font, colours, caption size/position/animation defaults")
|
|
225
|
+
sty.add_argument("--font", default=None, help="font family, e.g. 'Noto Sans CJK JP' for Japanese (default DejaVu Sans or brand font)")
|
|
224
226
|
sty.add_argument("--fonts-dir", help="directory with extra .ttf/.otf files")
|
|
225
|
-
sty.add_argument("--size", type=int, default=
|
|
226
|
-
sty.add_argument("--color", default=
|
|
227
|
-
sty.add_argument("--outline-color", default=
|
|
228
|
-
sty.add_argument("--outline", type=float, default=
|
|
227
|
+
sty.add_argument("--size", type=int, default=None, help="font size in ASS points (relative to a 288p script height, scales automatically)")
|
|
228
|
+
sty.add_argument("--color", default=None, help="text colour RRGGBB (default FFFFFF or brand text colour)")
|
|
229
|
+
sty.add_argument("--outline-color", default=None, help="outline colour RRGGBB")
|
|
230
|
+
sty.add_argument("--outline", type=float, default=None, help="outline width (default 2)")
|
|
229
231
|
sty.add_argument("--shadow", type=float, default=0.0, help="shadow depth (default 0)")
|
|
230
232
|
sty.add_argument("--bold", action="store_true")
|
|
231
|
-
sty.add_argument("--position", choices=sorted(ALIGN), default=
|
|
233
|
+
sty.add_argument("--position", choices=sorted(ALIGN), default=None, help="on-screen placement (default bottom)")
|
|
232
234
|
sty.add_argument("--margin", type=int, default=30, help="vertical margin from the edge (default 30)")
|
|
233
235
|
sty.add_argument("--box", action="store_true", help="draw an opaque box behind text instead of an outline")
|
|
234
236
|
anim = ap.add_argument_group("animation (generates ASS; needs --text or --srt input)")
|
|
235
|
-
anim.add_argument("--animate", choices=["none", "fade", "pop", "slide"], default=
|
|
237
|
+
anim.add_argument("--animate", choices=["none", "fade", "pop", "slide"], default=None, help="per-cue entrance animation (default none, or brand caption.animate)")
|
|
236
238
|
anim.add_argument("--karaoke", action="store_true", help="word-by-word highlight (fills from --color to --highlight-color across each cue)")
|
|
237
|
-
anim.add_argument("--highlight-color", default=
|
|
239
|
+
anim.add_argument("--highlight-color", default=None, help="karaoke fill colour RRGGBB (default FFD200 or brand primary)")
|
|
238
240
|
anim.add_argument("--karaoke-timing", choices=["even", "energy"], default="energy",
|
|
239
241
|
help="how words are timed inside a cue: 'energy' follows the speech loudness in the audio (default), 'even' splits time equally")
|
|
240
242
|
anim.add_argument("--write-ass", help="where to save the generated ASS (default: next to the output)")
|
|
@@ -245,6 +247,22 @@ def main() -> int:
|
|
|
245
247
|
args = ap.parse_args()
|
|
246
248
|
apply_common(args)
|
|
247
249
|
|
|
250
|
+
brand = load_brand(args.brand)
|
|
251
|
+
bc, bcap = brand["colors"], brand["caption"]
|
|
252
|
+
args.font = args.font or brand.get("font") or "DejaVu Sans"
|
|
253
|
+
args.size = args.size if args.size is not None else (bcap.get("size", 24) if args.brand else 24)
|
|
254
|
+
args.color = color_hex(args.color or bc.get("text", "FFFFFF"))
|
|
255
|
+
args.outline_color = color_hex(args.outline_color or bc.get("outline", "000000"))
|
|
256
|
+
args.outline = args.outline if args.outline is not None else (float(bcap.get("outline", 2)) if args.brand else 2.0)
|
|
257
|
+
args.position = args.position or (bcap.get("position", "bottom") if args.brand else "bottom")
|
|
258
|
+
args.animate = args.animate or (bcap.get("animate", "none") if args.brand else "none")
|
|
259
|
+
args.highlight_color = color_hex(args.highlight_color or bc.get("primary", "FFD200"))
|
|
260
|
+
if args.brand and bcap.get("bold") and not args.bold:
|
|
261
|
+
args.bold = True
|
|
262
|
+
if args.brand and bcap.get("karaoke") and not args.karaoke:
|
|
263
|
+
args.karaoke = True
|
|
264
|
+
if args.brand and brand.get("font_file") and not args.fonts_dir:
|
|
265
|
+
args.fonts_dir = str(Path(brand["font_file"]).parent)
|
|
248
266
|
if not (args.srt or args.ass or args.text):
|
|
249
267
|
die("give one of --srt, --ass or --text")
|
|
250
268
|
|
package/scripts/check.py
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Pre-delivery compliance check: does this file meet the platform's spec?
|
|
3
|
+
|
|
4
|
+
Checks duration, frame size / aspect, fps, codec, pixel format, colour tags,
|
|
5
|
+
file size, integrated loudness and true peak against the chosen platform
|
|
6
|
+
and prints a PASS/WARN/FAIL table. Exit code 1 when anything FAILs.
|
|
7
|
+
|
|
8
|
+
Platforms: youtube, shorts, reels, tiktok, x, linkedin, broadcast (EBU R128), podcast, custom
|
|
9
|
+
|
|
10
|
+
Examples:
|
|
11
|
+
python3 check.py final.mp4 --platform youtube
|
|
12
|
+
python3 check.py reel.mp4 --platform reels --json
|
|
13
|
+
python3 check.py spot.mov --platform broadcast
|
|
14
|
+
python3 check.py clip.mp4 --platform custom --max-duration 30 --aspect 1:1 --lufs -16
|
|
15
|
+
"""
|
|
16
|
+
import argparse
|
|
17
|
+
import json
|
|
18
|
+
import re
|
|
19
|
+
import sys
|
|
20
|
+
from fractions import Fraction
|
|
21
|
+
from typing import Any, Dict, List
|
|
22
|
+
|
|
23
|
+
from _common import add_common, apply_common, die, emit, info, probe, require_tool, run
|
|
24
|
+
|
|
25
|
+
SPECS: Dict[str, Dict[str, Any]] = {
|
|
26
|
+
"youtube": {"max_duration": 12 * 3600, "aspects": ["16:9", "9:16", "1:1", "4:3"], "min_height": 720, "fps_max": 60, "codecs": ["h264", "hevc", "prores", "av1", "vp9"], "max_bytes": 256 * 1024 ** 3, "lufs": -14, "lufs_tol": 2.0, "tp": -1.0, "sdr_only": False},
|
|
27
|
+
"shorts": {"max_duration": 180, "aspects": ["9:16", "1:1"], "min_height": 1080, "fps_max": 60, "codecs": ["h264", "hevc"], "max_bytes": 256 * 1024 ** 3, "lufs": -14, "lufs_tol": 2.0, "tp": -1.0, "sdr_only": False},
|
|
28
|
+
"reels": {"max_duration": 90, "aspects": ["9:16", "4:5", "1:1"], "min_height": 1080, "fps_max": 60, "codecs": ["h264", "hevc"], "max_bytes": 4 * 1024 ** 3, "lufs": -14, "lufs_tol": 2.0, "tp": -1.0, "sdr_only": True},
|
|
29
|
+
"tiktok": {"max_duration": 600, "aspects": ["9:16", "1:1"], "min_height": 1080, "fps_max": 60, "codecs": ["h264", "hevc"], "max_bytes": 4 * 1024 ** 3, "lufs": -14, "lufs_tol": 2.0, "tp": -1.0, "sdr_only": True},
|
|
30
|
+
"x": {"max_duration": 140, "aspects": ["16:9", "1:1", "9:16"], "min_height": 720, "fps_max": 60, "codecs": ["h264"], "max_bytes": 512 * 1024 ** 2, "lufs": -14, "lufs_tol": 3.0, "tp": -1.0, "sdr_only": True},
|
|
31
|
+
"linkedin": {"max_duration": 600, "aspects": ["16:9", "1:1", "9:16", "4:5"], "min_height": 720, "fps_max": 60, "codecs": ["h264"], "max_bytes": 5 * 1024 ** 3, "lufs": -14, "lufs_tol": 3.0, "tp": -1.0, "sdr_only": True},
|
|
32
|
+
"broadcast": {"max_duration": None, "aspects": ["16:9"], "min_height": 1080, "fps_max": 60, "codecs": ["prores", "dnxhd", "h264", "hevc", "mpeg2video"], "max_bytes": None, "lufs": -23, "lufs_tol": 1.0, "tp": -1.0, "sdr_only": False},
|
|
33
|
+
"podcast": {"max_duration": None, "aspects": None, "min_height": 0, "fps_max": None, "codecs": None, "max_bytes": None, "lufs": -16, "lufs_tol": 1.0, "tp": -1.0, "sdr_only": False},
|
|
34
|
+
"custom": {"max_duration": None, "aspects": None, "min_height": 0, "fps_max": None, "codecs": None, "max_bytes": None, "lufs": None, "lufs_tol": 2.0, "tp": -1.0, "sdr_only": False},
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def measure_loudness(path: str) -> Dict[str, float]:
|
|
39
|
+
ffmpeg = require_tool("ffmpeg")
|
|
40
|
+
proc = run([ffmpeg, "-hide_banner", "-nostdin", "-i", path, "-vn", "-af", "loudnorm=I=-14:TP=-1:LRA=11:print_format=json", "-f", "null", "-"], quiet=True, check=False)
|
|
41
|
+
m = re.search(r"\{[^{}]*\"input_i\"[^{}]*\}", proc.stderr, re.S)
|
|
42
|
+
if not m:
|
|
43
|
+
return {}
|
|
44
|
+
d = json.loads(m.group(0))
|
|
45
|
+
try:
|
|
46
|
+
return {"lufs": float(d["input_i"]), "tp": float(d["input_tp"]), "lra": float(d["input_lra"])}
|
|
47
|
+
except (KeyError, ValueError):
|
|
48
|
+
return {}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def aspect_name(w: int, h: int) -> str:
|
|
52
|
+
f = Fraction(w, h)
|
|
53
|
+
for name, target in (("16:9", Fraction(16, 9)), ("9:16", Fraction(9, 16)), ("1:1", Fraction(1)), ("4:5", Fraction(4, 5)), ("4:3", Fraction(4, 3)), ("21:9", Fraction(21, 9))):
|
|
54
|
+
if abs(float(f) - float(target)) < 0.02:
|
|
55
|
+
return name
|
|
56
|
+
return f"{f.numerator}:{f.denominator}"
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def main() -> int:
|
|
60
|
+
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
61
|
+
ap.add_argument("input")
|
|
62
|
+
ap.add_argument("--platform", choices=sorted(SPECS), default="youtube")
|
|
63
|
+
ap.add_argument("--max-duration", type=float, help="override max duration in seconds")
|
|
64
|
+
ap.add_argument("--aspect", help="override allowed aspect (e.g. 9:16 or 16:9,1:1)")
|
|
65
|
+
ap.add_argument("--lufs", type=float, help="override loudness target")
|
|
66
|
+
ap.add_argument("--tp", type=float, help="override true-peak ceiling")
|
|
67
|
+
ap.add_argument("--max-mb", type=float, help="override max file size in MB")
|
|
68
|
+
ap.add_argument("--no-loudness", action="store_true", help="skip the loudness measurement (faster)")
|
|
69
|
+
add_common(ap)
|
|
70
|
+
args = ap.parse_args()
|
|
71
|
+
apply_common(args)
|
|
72
|
+
|
|
73
|
+
spec = dict(SPECS[args.platform])
|
|
74
|
+
if args.max_duration is not None:
|
|
75
|
+
spec["max_duration"] = args.max_duration
|
|
76
|
+
if args.aspect:
|
|
77
|
+
spec["aspects"] = [a.strip() for a in args.aspect.split(",")]
|
|
78
|
+
if args.lufs is not None:
|
|
79
|
+
spec["lufs"] = args.lufs
|
|
80
|
+
if args.tp is not None:
|
|
81
|
+
spec["tp"] = args.tp
|
|
82
|
+
if args.max_mb is not None:
|
|
83
|
+
spec["max_bytes"] = int(args.max_mb * 1024 * 1024)
|
|
84
|
+
|
|
85
|
+
meta = probe(args.input)
|
|
86
|
+
v, a = meta.get("video") or {}, meta.get("audio") or {}
|
|
87
|
+
rows: List[Dict[str, Any]] = []
|
|
88
|
+
|
|
89
|
+
def row(name: str, status: str, value: Any, expect: Any, fix: str = "") -> None:
|
|
90
|
+
rows.append({"check": name, "status": status, "value": value, "expected": expect, "fix": fix})
|
|
91
|
+
|
|
92
|
+
dur = meta.get("duration") or 0.0
|
|
93
|
+
if spec["max_duration"]:
|
|
94
|
+
row("duration", "PASS" if dur <= spec["max_duration"] else "FAIL", f"{dur:.2f}s", f"<= {spec['max_duration']:g}s", "fit.py --duration N or cut.py")
|
|
95
|
+
else:
|
|
96
|
+
row("duration", "PASS", f"{dur:.2f}s", "any")
|
|
97
|
+
|
|
98
|
+
if v:
|
|
99
|
+
w, h = v["width"], v["height"]
|
|
100
|
+
if v.get("rotation") in (90, -90, 270, -270):
|
|
101
|
+
w, h = h, w
|
|
102
|
+
asp = aspect_name(w, h)
|
|
103
|
+
if spec["aspects"]:
|
|
104
|
+
row("aspect", "PASS" if asp in spec["aspects"] else "FAIL", asp, "/".join(spec["aspects"]), f"fit.py --aspect {spec['aspects'][0]} --fit pad|crop")
|
|
105
|
+
else:
|
|
106
|
+
row("aspect", "PASS", asp, "any")
|
|
107
|
+
short = min(w, h)
|
|
108
|
+
if spec["min_height"]:
|
|
109
|
+
row("resolution", "PASS" if short >= spec["min_height"] else "WARN", f"{w}x{h}", f"short side >= {spec['min_height']}", "upscaling will not add detail; re-export from the master")
|
|
110
|
+
fps = v.get("fps") or 0
|
|
111
|
+
if spec["fps_max"]:
|
|
112
|
+
row("fps", "PASS" if fps <= spec["fps_max"] + 0.01 else "FAIL", f"{fps:g}", f"<= {spec['fps_max']}", "fit.py --fps 30")
|
|
113
|
+
row("vfr", "PASS" if not v.get("variable_frame_rate_suspected") else "WARN", "variable" if v.get("variable_frame_rate_suspected") else "constant", "constant", "fit.py --fps N (any re-encode conforms it)")
|
|
114
|
+
if spec["codecs"]:
|
|
115
|
+
row("video codec", "PASS" if v.get("codec") in spec["codecs"] else "FAIL", v.get("codec"), "/".join(spec["codecs"]), "export.py --preset " + args.platform.replace("shorts", "reels").replace("tiktok", "reels").replace("linkedin", "youtube"))
|
|
116
|
+
pf = v.get("pix_fmt") or ""
|
|
117
|
+
if args.platform in ("reels", "tiktok", "x", "linkedin"):
|
|
118
|
+
row("pixel format", "PASS" if pf == "yuv420p" else "FAIL", pf, "yuv420p (8-bit 4:2:0)", "export.py preset re-encodes to yuv420p")
|
|
119
|
+
if spec["sdr_only"] and v.get("hdr"):
|
|
120
|
+
row("colour", "FAIL", v.get("hdr_format"), "SDR BT.709", "color.py --to-sdr")
|
|
121
|
+
else:
|
|
122
|
+
tags = (v.get("color_primaries"), v.get("color_transfer"))
|
|
123
|
+
ok = v.get("hdr") or tags == ("bt709", "bt709") or (args.platform in ("podcast", "custom"))
|
|
124
|
+
row("colour", "PASS" if ok else "WARN", f"{tags[0]}/{tags[1]}" + (f" ({v.get('hdr_format')})" if v.get("hdr") else ""), "bt709/bt709 tagged (or HDR)", "color.py --retag bt709 when the picture really is 709")
|
|
125
|
+
elif args.platform not in ("podcast", "custom"):
|
|
126
|
+
row("video", "FAIL", "none", "video stream", "")
|
|
127
|
+
|
|
128
|
+
size = meta.get("size_bytes") or 0
|
|
129
|
+
if spec["max_bytes"]:
|
|
130
|
+
row("file size", "PASS" if size <= spec["max_bytes"] else "FAIL", f"{size / 1024 / 1024:.1f} MB", f"<= {spec['max_bytes'] / 1024 / 1024:.0f} MB", "export.py --crf 24 or lower resolution")
|
|
131
|
+
|
|
132
|
+
if a:
|
|
133
|
+
row("audio", "PASS", f"{a.get('codec')} {a.get('channels')}ch {a.get('sample_rate')}Hz", "present")
|
|
134
|
+
if a.get("sample_rate") and a["sample_rate"] not in (44100, 48000):
|
|
135
|
+
row("sample rate", "WARN", a["sample_rate"], "44100 or 48000", "loudness.py --sample-rate 48000")
|
|
136
|
+
if not args.no_loudness and spec["lufs"] is not None:
|
|
137
|
+
lm = measure_loudness(args.input)
|
|
138
|
+
if lm:
|
|
139
|
+
diff = abs(lm["lufs"] - spec["lufs"])
|
|
140
|
+
row("loudness", "PASS" if diff <= spec["lufs_tol"] else "FAIL", f"{lm['lufs']:.1f} LUFS", f"{spec['lufs']:g} ± {spec['lufs_tol']:g} LUFS", f"loudness.py -I {spec['lufs']:g}")
|
|
141
|
+
row("true peak", "PASS" if lm["tp"] <= spec["tp"] + 0.05 else "FAIL", f"{lm['tp']:.1f} dBTP", f"<= {spec['tp']:g} dBTP", f"loudness.py --tp {spec['tp']:g}")
|
|
142
|
+
elif args.platform in ("podcast",):
|
|
143
|
+
row("audio", "FAIL", "none", "audio stream", "audio.py --replace")
|
|
144
|
+
else:
|
|
145
|
+
row("audio", "WARN", "none", "audio stream", "audio.py --replace (silent uploads are often rejected)")
|
|
146
|
+
|
|
147
|
+
failed = [r for r in rows if r["status"] == "FAIL"]
|
|
148
|
+
warned = [r for r in rows if r["status"] == "WARN"]
|
|
149
|
+
if not args.json:
|
|
150
|
+
width = max(len(r["check"]) for r in rows)
|
|
151
|
+
print(f"{args.input} — {args.platform}")
|
|
152
|
+
for r in rows:
|
|
153
|
+
line = f" {r['status']:4s} {r['check']:{width}s} {r['value']} (expected {r['expected']})"
|
|
154
|
+
if r["status"] != "PASS" and r["fix"]:
|
|
155
|
+
line += f" -> {r['fix']}"
|
|
156
|
+
print(line)
|
|
157
|
+
print(f" {len(rows)} checks, {len(failed)} failed, {len(warned)} warnings")
|
|
158
|
+
emit(None, platform=args.platform, checks=rows, failed=len(failed), warnings=len(warned), ok=not failed)
|
|
159
|
+
return 1 if failed else 0
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
if __name__ == "__main__":
|
|
163
|
+
sys.exit(main())
|
package/scripts/export.py
CHANGED
|
@@ -22,7 +22,7 @@ import argparse
|
|
|
22
22
|
import sys
|
|
23
23
|
from typing import Dict, List
|
|
24
24
|
|
|
25
|
-
from _common import add_common, apply_common, emit, cfr_args, default_output, die, ffmpeg_base, info, probe, run
|
|
25
|
+
from _common import STATE, add_common, apply_common, emit, cfr_args, default_output, die, ffmpeg_base, info, probe, run
|
|
26
26
|
|
|
27
27
|
PRESETS: Dict[str, Dict] = {
|
|
28
28
|
"youtube": {"w": 1920, "h": 1080, "ext": "mp4", "video": ["-c:v", "libx264", "-preset", "slow", "-crf", "18", "-profile:v", "high", "-pix_fmt", "yuv420p"], "audio": ["-c:a", "aac", "-b:a", "192k", "-ar", "48000"], "max": None, "desc": "1080p H.264, AAC 192k"},
|
|
@@ -94,6 +94,8 @@ def main() -> int:
|
|
|
94
94
|
video = list(p["video"])
|
|
95
95
|
if args.crf is not None and "-crf" in video:
|
|
96
96
|
video[video.index("-crf") + 1] = str(args.crf)
|
|
97
|
+
if STATE["fast"] and "-preset" in video:
|
|
98
|
+
video[video.index("-preset") + 1] = "veryfast"
|
|
97
99
|
cmd += video
|
|
98
100
|
if "-r" not in video:
|
|
99
101
|
cmd += cfr_args(meta)
|
package/scripts/fit.py
CHANGED
|
@@ -102,6 +102,8 @@ def main() -> int:
|
|
|
102
102
|
if target <= 0:
|
|
103
103
|
die("target duration must be > 0")
|
|
104
104
|
if args.method == "speed":
|
|
105
|
+
if src_dur <= 0 and STATE["dry_run"]:
|
|
106
|
+
src_dur = target # planning against an intermediate that does not exist yet
|
|
105
107
|
factor = src_dur / target # >1 = speed up
|
|
106
108
|
if factor > args.max_speed or factor < 1 / args.max_speed:
|
|
107
109
|
die(f"required speed factor {factor:.2f}x exceeds --max-speed {args.max_speed}x; use --method trim or raise the limit")
|