short-video-studio 0.2.3__py3-none-any.whl
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.
- short_video_studio/__init__.py +2 -0
- short_video_studio/burn_cards.py +119 -0
- short_video_studio/cli.py +100 -0
- short_video_studio/make_cover.py +117 -0
- short_video_studio/preflight.py +64 -0
- short_video_studio/probe_source.py +82 -0
- short_video_studio/rep_counter.py +159 -0
- short_video_studio/safe_zone_check.py +104 -0
- short_video_studio/sharpest_frames.py +115 -0
- short_video_studio/stats_log.py +133 -0
- short_video_studio/svs_common.py +204 -0
- short_video_studio/svs_text.py +130 -0
- short_video_studio/templates_en/CREATOR.md +35 -0
- short_video_studio/templates_en/LEARNINGS.md +23 -0
- short_video_studio/templates_en/STOCK.md +17 -0
- short_video_studio/templates_en/cards.example.json +20 -0
- short_video_studio/templates_en/copy.md +41 -0
- short_video_studio/templates_tr/CREATOR.md +35 -0
- short_video_studio/templates_tr/LEARNINGS.md +23 -0
- short_video_studio/templates_tr/STOCK.md +17 -0
- short_video_studio/templates_tr/cards.example.json +20 -0
- short_video_studio/templates_tr/copy.md +41 -0
- short_video_studio/to_sdr.py +172 -0
- short_video_studio-0.2.3.dist-info/METADATA +179 -0
- short_video_studio-0.2.3.dist-info/RECORD +29 -0
- short_video_studio-0.2.3.dist-info/WHEEL +5 -0
- short_video_studio-0.2.3.dist-info/entry_points.txt +2 -0
- short_video_studio-0.2.3.dist-info/licenses/LICENSE +21 -0
- short_video_studio-0.2.3.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Burn timed text cards (hook, facts, counter, end card) onto a vertical video.
|
|
3
|
+
|
|
4
|
+
Cards are rendered with Pillow (works with any ffmpeg build, handles Turkish
|
|
5
|
+
and CJK glyphs) and overlaid with ffmpeg. Audio is copied untouched.
|
|
6
|
+
|
|
7
|
+
cards.json:
|
|
8
|
+
{
|
|
9
|
+
"style": {"size": 0.062, "y": 0.17, "color": "#FFFFFF", "accent": "#C9341F",
|
|
10
|
+
"align": "center", "shadow": true, "stroke": 0, "box": null,
|
|
11
|
+
"upper": true, "lang": "en"},
|
|
12
|
+
"cards": [
|
|
13
|
+
{"start": 0.0, "end": 2.6, "lines": ["WAR RECORDS SAY", "SAMURAI WERE WOUNDED", "BY *ARROWS*, NOT SWORDS."]},
|
|
14
|
+
{"start": 10.7, "end": 14.1, "lines": ["NEXT: SPEAR OR BOW?"], "y": 0.5, "size": 0.07}
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
size = font size as a fraction of video width (auto-shrinks to fit 86% width)
|
|
18
|
+
y = vertical centre of the block as a fraction of height (keep 0.12-0.75)
|
|
19
|
+
*word* = accent colour; "upper": true uppercases (Turkish-aware when lang = "tr")
|
|
20
|
+
|
|
21
|
+
Usage: python3 burn_cards.py IN.mp4 cards.json OUT.mp4 [--font F] [--cjk-font F] [--crf 17] [--allow-hdr]
|
|
22
|
+
"""
|
|
23
|
+
import argparse
|
|
24
|
+
import json
|
|
25
|
+
import os
|
|
26
|
+
import shutil
|
|
27
|
+
import subprocess
|
|
28
|
+
import tempfile
|
|
29
|
+
|
|
30
|
+
try:
|
|
31
|
+
from .svs_common import die, display_size, duration, has_audio, hdr_kind, need, need_pillow, probe, tr_upper, video_stream
|
|
32
|
+
except ImportError:
|
|
33
|
+
from svs_common import die, display_size, duration, has_audio, hdr_kind, need, need_pillow, probe, tr_upper, video_stream
|
|
34
|
+
try:
|
|
35
|
+
from .svs_text import draw_block, fit_size
|
|
36
|
+
except ImportError:
|
|
37
|
+
from svs_text import draw_block, fit_size
|
|
38
|
+
|
|
39
|
+
Image, _, _ = need_pillow()
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def main():
|
|
43
|
+
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
44
|
+
ap.add_argument("src")
|
|
45
|
+
ap.add_argument("cards")
|
|
46
|
+
ap.add_argument("dst")
|
|
47
|
+
ap.add_argument("--font", default=None)
|
|
48
|
+
ap.add_argument("--cjk-font", default=None)
|
|
49
|
+
ap.add_argument("--crf", type=int, default=17)
|
|
50
|
+
ap.add_argument("--allow-hdr", action="store_true")
|
|
51
|
+
ap.add_argument("--keep-png", action="store_true", help="keep rendered card PNGs for review")
|
|
52
|
+
a = ap.parse_args()
|
|
53
|
+
|
|
54
|
+
need("ffmpeg", "ffprobe")
|
|
55
|
+
info = probe(a.src)
|
|
56
|
+
vs = video_stream(info)
|
|
57
|
+
if hdr_kind(vs) and not a.allow_hdr:
|
|
58
|
+
die("source is HDR; convert it with to_sdr.py first (or pass --allow-hdr if you know why)")
|
|
59
|
+
W, H = display_size(vs)
|
|
60
|
+
|
|
61
|
+
with open(a.cards, encoding="utf-8") as fh:
|
|
62
|
+
spec = json.load(fh)
|
|
63
|
+
base = {"size": 0.062, "y": 0.17, "color": "#FFFFFF", "accent": "#C9341F", "align": "center",
|
|
64
|
+
"shadow": True, "stroke": 0, "box": None, "upper": True, "lang": "en"}
|
|
65
|
+
base.update(spec.get("style", {}))
|
|
66
|
+
cards = spec.get("cards", [])
|
|
67
|
+
if not cards:
|
|
68
|
+
die("no cards in JSON")
|
|
69
|
+
|
|
70
|
+
tmpdir = tempfile.mkdtemp(prefix="svs_cards_")
|
|
71
|
+
pngs = []
|
|
72
|
+
for i, c in enumerate(cards):
|
|
73
|
+
st = dict(base, **{k: v for k, v in c.items() if k not in ("start", "end", "lines")})
|
|
74
|
+
lines = c["lines"]
|
|
75
|
+
if st["upper"]:
|
|
76
|
+
lines = [tr_upper(ln) if st["lang"] == "tr" else ln.upper() for ln in lines]
|
|
77
|
+
if not (0.10 <= st["y"] <= 0.78):
|
|
78
|
+
print(f"WARNING card {i}: y={st['y']} is inside a platform UI zone")
|
|
79
|
+
img = Image.new("RGBA", (W, H), (0, 0, 0, 0))
|
|
80
|
+
fonts = fit_size(img, lines, int(W * st["size"]), latin=a.font, cjk=a.cjk_font)
|
|
81
|
+
draw_block(img, lines, st["y"], fonts, st["color"], st["accent"], st["align"],
|
|
82
|
+
st["shadow"], st["stroke"], box=st["box"])
|
|
83
|
+
p = os.path.join(tmpdir, f"card_{i:03d}.png")
|
|
84
|
+
img.save(p)
|
|
85
|
+
pngs.append((p, float(c["start"]), float(c["end"])))
|
|
86
|
+
|
|
87
|
+
# Each card PNG is looped for the whole video and placed on the timeline with enable=.
|
|
88
|
+
# A single-frame PNG input (no -loop) is NOT reliable: on some sources every card that
|
|
89
|
+
# doesn't start at 0 s silently never appears.
|
|
90
|
+
total = duration(info)
|
|
91
|
+
cmd = ["ffmpeg", "-y", "-hide_banner", "-loglevel", "error", "-stats", "-i", a.src]
|
|
92
|
+
for p, _, _ in pngs:
|
|
93
|
+
cmd += ["-loop", "1", "-t", f"{total:.3f}", "-i", p]
|
|
94
|
+
chain, last = [], "0:v"
|
|
95
|
+
for i, (_, s, e) in enumerate(pngs, 1):
|
|
96
|
+
out = f"v{i}"
|
|
97
|
+
chain.append(f"[{last}][{i}:v]overlay=0:0:eof_action=pass:enable='between(t,{s:.3f},{e:.3f})'[{out}]")
|
|
98
|
+
last = out
|
|
99
|
+
chain.append(f"[{last}]format=yuv420p,setparams=color_primaries=bt709:color_trc=bt709:colorspace=bt709:range=tv[vout]")
|
|
100
|
+
script = os.path.join(tmpdir, "filter.txt")
|
|
101
|
+
with open(script, "w") as fh:
|
|
102
|
+
fh.write(";\n".join(chain))
|
|
103
|
+
cmd += ["-filter_complex_script", script, "-map", "[vout]"]
|
|
104
|
+
if has_audio(info):
|
|
105
|
+
cmd += ["-map", "0:a:0", "-c:a", "copy"]
|
|
106
|
+
cmd += ["-c:v", "libx264", "-preset", "slow", "-crf", str(a.crf),
|
|
107
|
+
"-color_primaries", "bt709", "-color_trc", "bt709", "-colorspace", "bt709",
|
|
108
|
+
"-movflags", "+faststart", a.dst]
|
|
109
|
+
subprocess.run(cmd, check=True)
|
|
110
|
+
|
|
111
|
+
if a.keep_png:
|
|
112
|
+
print(f"Card PNGs kept in {tmpdir}")
|
|
113
|
+
else:
|
|
114
|
+
shutil.rmtree(tmpdir, ignore_errors=True)
|
|
115
|
+
print(f"OK -> {a.dst} ({len(pngs)} cards). Review frame by frame: no clipped words, no text on faces.")
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
if __name__ == "__main__":
|
|
119
|
+
main()
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""svs: the short-video-studio tools as one command, usable with or without Claude.
|
|
3
|
+
|
|
4
|
+
svs init [DIR] [--lang en|tr] create CREATOR.md, LEARNINGS.md, STOCK.md, stock/ in a content folder
|
|
5
|
+
svs preflight check ffmpeg, numpy, Pillow, fonts, free disk
|
|
6
|
+
svs probe CLIP... size, fps, colour, HDR, what to do next
|
|
7
|
+
svs to-sdr IN OUT HDR (iPhone HLG / PQ) -> SDR BT.709
|
|
8
|
+
svs sharpest CLIP export the sharpest frames (cover/teaser candidates)
|
|
9
|
+
svs safe-zone IMAGE_OR_CLIP draw platform UI zones / 3:4 profile crop
|
|
10
|
+
svs count CLIP draft rep/strike count, optional counter cards
|
|
11
|
+
svs cards IN cards.json OUT burn timed text cards
|
|
12
|
+
svs cover STILL OUT --lines ... make a 1080x1920 cover or teaser
|
|
13
|
+
svs stats add|report ... log and compare video stats
|
|
14
|
+
|
|
15
|
+
Run `svs <command> --help` for options.
|
|
16
|
+
"""
|
|
17
|
+
import importlib
|
|
18
|
+
import shutil
|
|
19
|
+
import sys
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
from . import __version__
|
|
24
|
+
except ImportError:
|
|
25
|
+
__version__ = "0.2.3"
|
|
26
|
+
|
|
27
|
+
COMMANDS = {
|
|
28
|
+
"preflight": "preflight",
|
|
29
|
+
"probe": "probe_source",
|
|
30
|
+
"to-sdr": "to_sdr",
|
|
31
|
+
"sharpest": "sharpest_frames",
|
|
32
|
+
"safe-zone": "safe_zone_check",
|
|
33
|
+
"count": "rep_counter",
|
|
34
|
+
"cards": "burn_cards",
|
|
35
|
+
"cover": "make_cover",
|
|
36
|
+
"stats": "stats_log",
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _module(name: str):
|
|
41
|
+
if __package__:
|
|
42
|
+
return importlib.import_module(f".{name}", __package__)
|
|
43
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
44
|
+
return importlib.import_module(name)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _templates(lang: str) -> Path:
|
|
48
|
+
here = Path(__file__).resolve().parent
|
|
49
|
+
packaged = here / f"templates_{lang}" # installed with pip/pipx
|
|
50
|
+
if (packaged / "CREATOR.md").exists():
|
|
51
|
+
return packaged
|
|
52
|
+
return here.parent / "templates" # running from inside the skill folder
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def cmd_init(argv):
|
|
56
|
+
import argparse
|
|
57
|
+
ap = argparse.ArgumentParser(prog="svs init", description="Create the workspace files in a content folder.")
|
|
58
|
+
ap.add_argument("dir", nargs="?", default=".")
|
|
59
|
+
ap.add_argument("--lang", choices=["en", "tr"], default="en")
|
|
60
|
+
a = ap.parse_args(argv)
|
|
61
|
+
src = _templates(a.lang)
|
|
62
|
+
dst = Path(a.dir)
|
|
63
|
+
(dst / "stock").mkdir(parents=True, exist_ok=True)
|
|
64
|
+
for name in ("CREATOR.md", "LEARNINGS.md", "STOCK.md"):
|
|
65
|
+
target = dst / name
|
|
66
|
+
if target.exists():
|
|
67
|
+
print(f" kept {target} (already exists)")
|
|
68
|
+
else:
|
|
69
|
+
shutil.copy(src / name, target)
|
|
70
|
+
print(f" created {target}")
|
|
71
|
+
for name in ("copy.md", "cards.example.json"):
|
|
72
|
+
target = dst / "stock" / f"_{name}"
|
|
73
|
+
if not target.exists():
|
|
74
|
+
shutil.copy(src / name, target)
|
|
75
|
+
print(f" created {target}")
|
|
76
|
+
print("Next: fill CREATOR.md, then run `svs preflight`.")
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def main(argv=None):
|
|
80
|
+
argv = list(sys.argv[1:] if argv is None else argv)
|
|
81
|
+
if not argv or argv[0] in ("-h", "--help", "help"):
|
|
82
|
+
print(__doc__)
|
|
83
|
+
return 0
|
|
84
|
+
if argv[0] in ("-V", "--version"):
|
|
85
|
+
print(f"svs {__version__}")
|
|
86
|
+
return 0
|
|
87
|
+
cmd, rest = argv[0], argv[1:]
|
|
88
|
+
if cmd == "init":
|
|
89
|
+
cmd_init(rest)
|
|
90
|
+
return 0
|
|
91
|
+
if cmd not in COMMANDS:
|
|
92
|
+
print(f"unknown command: {cmd}\n{__doc__}", file=sys.stderr)
|
|
93
|
+
return 2
|
|
94
|
+
mod = _module(COMMANDS[cmd])
|
|
95
|
+
sys.argv = [f"svs {cmd}"] + rest
|
|
96
|
+
return mod.main() or 0
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
if __name__ == "__main__":
|
|
100
|
+
sys.exit(main())
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Make a vertical cover (9:16) or a teaser story from a still.
|
|
3
|
+
|
|
4
|
+
cover : full-bleed photo, bold uppercase white text with shadow, optional accent
|
|
5
|
+
words (*word*), optional series pill ("11-13 / 20") and small mark/seal.
|
|
6
|
+
Text is kept inside the centre 3:4 box so the profile grid never cuts it.
|
|
7
|
+
teaser : darker, moody still with letter-spaced serif text in the accent colour
|
|
8
|
+
(e.g. "TOMORROW" / "DEVAMI YARIN"). Never use frames from an unpublished
|
|
9
|
+
video that would spoil it.
|
|
10
|
+
|
|
11
|
+
Usage:
|
|
12
|
+
python3 make_cover.py STILL.jpg OUT.jpg --lines "SAMURAI WEREN'T" "KILLED BY *SWORDS*"
|
|
13
|
+
[--style cover|teaser] [--pill "11-13 / 20"] [--mark 杖] [--y 0.30]
|
|
14
|
+
[--accent "#C9341F"] [--size 0.085] [--lang en|tr] [--font F] [--cjk-font F]
|
|
15
|
+
"""
|
|
16
|
+
import argparse
|
|
17
|
+
|
|
18
|
+
try:
|
|
19
|
+
from .svs_common import hex_rgba, need_pillow, tr_upper
|
|
20
|
+
except ImportError:
|
|
21
|
+
from svs_common import hex_rgba, need_pillow, tr_upper
|
|
22
|
+
try:
|
|
23
|
+
from .svs_text import Fonts, draw_block, fit_size, line_width
|
|
24
|
+
except ImportError:
|
|
25
|
+
from svs_text import Fonts, draw_block, fit_size, line_width
|
|
26
|
+
|
|
27
|
+
Image, ImageDraw, _ = need_pillow()
|
|
28
|
+
from PIL import ImageEnhance # noqa: E402
|
|
29
|
+
|
|
30
|
+
OUT_W, OUT_H = 1080, 1920
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def fill_vertical(img):
|
|
34
|
+
"""Scale + centre-crop to 1080x1920."""
|
|
35
|
+
w, h = img.size
|
|
36
|
+
scale = max(OUT_W / w, OUT_H / h)
|
|
37
|
+
img = img.resize((int(w * scale + 0.5), int(h * scale + 0.5)), Image.LANCZOS)
|
|
38
|
+
w, h = img.size
|
|
39
|
+
x, y = (w - OUT_W) // 2, (h - OUT_H) // 2
|
|
40
|
+
return img.crop((x, y, x + OUT_W, y + OUT_H))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def main():
|
|
44
|
+
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
45
|
+
ap.add_argument("still")
|
|
46
|
+
ap.add_argument("out")
|
|
47
|
+
ap.add_argument("--lines", nargs="+", required=True)
|
|
48
|
+
ap.add_argument("--style", choices=["cover", "teaser"], default="cover")
|
|
49
|
+
ap.add_argument("--pill", default=None)
|
|
50
|
+
ap.add_argument("--mark", default=None, help="small seal text, e.g. a single kanji or initials")
|
|
51
|
+
ap.add_argument("--y", type=float, default=None, help="block centre as fraction of height")
|
|
52
|
+
ap.add_argument("--accent", default="#C9341F")
|
|
53
|
+
ap.add_argument("--size", type=float, default=None, help="font size as fraction of width")
|
|
54
|
+
ap.add_argument("--lang", default="en")
|
|
55
|
+
ap.add_argument("--no-upper", action="store_true")
|
|
56
|
+
ap.add_argument("--font", default=None)
|
|
57
|
+
ap.add_argument("--cjk-font", default=None)
|
|
58
|
+
a = ap.parse_args()
|
|
59
|
+
|
|
60
|
+
img = fill_vertical(Image.open(a.still).convert("RGB")).convert("RGBA")
|
|
61
|
+
lines = a.lines
|
|
62
|
+
if not a.no_upper:
|
|
63
|
+
lines = [tr_upper(ln) if a.lang == "tr" else ln.upper() for ln in lines]
|
|
64
|
+
|
|
65
|
+
box_top = (OUT_H - int(OUT_W * 4 / 3)) // 2 # 3:4 profile crop
|
|
66
|
+
box_bot = box_top + int(OUT_W * 4 / 3)
|
|
67
|
+
|
|
68
|
+
if a.style == "teaser":
|
|
69
|
+
img = ImageEnhance.Brightness(img.convert("RGB")).enhance(0.55)
|
|
70
|
+
img = ImageEnhance.Color(img).enhance(0.8).convert("RGBA")
|
|
71
|
+
grad = Image.new("RGBA", img.size, (0, 0, 0, 0))
|
|
72
|
+
gd = ImageDraw.Draw(grad)
|
|
73
|
+
for y in range(OUT_H // 2, OUT_H):
|
|
74
|
+
gd.line([(0, y), (OUT_W, y)], fill=(0, 0, 0, int(200 * (y - OUT_H / 2) / (OUT_H / 2))))
|
|
75
|
+
img = Image.alpha_composite(img, grad)
|
|
76
|
+
size = int(OUT_W * (a.size or 0.075))
|
|
77
|
+
fonts = fit_size(img, lines, size, 0.84, a.font, a.cjk_font, kind="serif", tracking=0.25)
|
|
78
|
+
draw_block(img, lines, a.y or 0.66, fonts, color=a.accent, accent="#FFFFFF",
|
|
79
|
+
shadow=True, tracking=0.25, line_gap=0.35)
|
|
80
|
+
else:
|
|
81
|
+
shade = Image.new("RGBA", img.size, (0, 0, 0, 0))
|
|
82
|
+
sd = ImageDraw.Draw(shade)
|
|
83
|
+
fade_end = box_top + int(OUT_H * 0.32)
|
|
84
|
+
for y in range(0, fade_end): # solid above the 3:4 box, fading below it: no visible edge
|
|
85
|
+
k = 1.0 if y < box_top else 1 - (y - box_top) / (fade_end - box_top)
|
|
86
|
+
sd.line([(0, y), (OUT_W, y)], fill=(0, 0, 0, int(110 * k)))
|
|
87
|
+
img = Image.alpha_composite(img, shade)
|
|
88
|
+
size = int(OUT_W * (a.size or 0.085))
|
|
89
|
+
fonts = fit_size(img, lines, size, 0.86, a.font, a.cjk_font)
|
|
90
|
+
cy = a.y or (box_top / OUT_H + 0.12)
|
|
91
|
+
top, bot = draw_block(img, lines, cy, fonts, "#FFFFFF", a.accent, stroke=max(1, size // 30))
|
|
92
|
+
if top < box_top or bot > box_bot:
|
|
93
|
+
print("WARNING: text leaves the 3:4 profile crop; move --y or shorten lines")
|
|
94
|
+
d = ImageDraw.Draw(img, "RGBA")
|
|
95
|
+
if a.pill:
|
|
96
|
+
pf = Fonts(int(OUT_W * 0.04), a.font, a.cjk_font)
|
|
97
|
+
pw = line_width(d, a.pill, pf) + pf.size
|
|
98
|
+
ph = int(pf.size * 1.6)
|
|
99
|
+
px, py = (OUT_W - pw) // 2, bot + int(pf.size * 0.8)
|
|
100
|
+
d.rounded_rectangle([px, py, px + pw, py + ph], radius=ph // 2, fill=hex_rgba(a.accent, 235))
|
|
101
|
+
d.text((px + pf.size // 2, py + int(pf.size * 0.25)), a.pill, font=pf.latin, fill=(255, 255, 255, 255))
|
|
102
|
+
if a.mark:
|
|
103
|
+
mf = Fonts(int(OUT_W * 0.05), a.font, a.cjk_font)
|
|
104
|
+
ms = int(mf.size * 1.6)
|
|
105
|
+
mx, my = OUT_W - ms - int(OUT_W * 0.06), box_bot - ms - int(OUT_W * 0.04)
|
|
106
|
+
d.rectangle([mx, my, mx + ms, my + ms], fill=hex_rgba(a.accent, 230))
|
|
107
|
+
font = mf.for_char(a.mark[0])
|
|
108
|
+
tw = d.textlength(a.mark, font=font)
|
|
109
|
+
d.text((mx + (ms - tw) / 2, my + (ms - mf.size) / 2 - mf.size * 0.1), a.mark, font=font,
|
|
110
|
+
fill=(255, 255, 255, 255))
|
|
111
|
+
|
|
112
|
+
img.convert("RGB").save(a.out, quality=94)
|
|
113
|
+
print(f"OK -> {a.out} (1080x1920). Run safe_zone_check.py --mode cover on it, then view it at thumbnail size.")
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
if __name__ == "__main__":
|
|
117
|
+
main()
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Check the machine before any video work: tools, filters, fonts, free disk space.
|
|
3
|
+
|
|
4
|
+
Usage: python3 preflight.py [--dir WORKDIR] [--min-free-gb 5]
|
|
5
|
+
Exit code 0 = ready, 1 = something is missing (read the report).
|
|
6
|
+
"""
|
|
7
|
+
import argparse
|
|
8
|
+
import shutil
|
|
9
|
+
import sys
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
from .svs_common import ffmpeg_has_filter, find_font, free_gb
|
|
13
|
+
except ImportError:
|
|
14
|
+
from svs_common import ffmpeg_has_filter, find_font, free_gb
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def main():
|
|
18
|
+
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
19
|
+
ap.add_argument("--dir", default=".", help="folder where outputs will be written")
|
|
20
|
+
ap.add_argument("--min-free-gb", type=float, default=5.0)
|
|
21
|
+
a = ap.parse_args()
|
|
22
|
+
|
|
23
|
+
ok = True
|
|
24
|
+
print("short-video-studio preflight\n")
|
|
25
|
+
|
|
26
|
+
for tool in ("ffmpeg", "ffprobe"):
|
|
27
|
+
found = shutil.which(tool)
|
|
28
|
+
print(f" [{'ok' if found else 'MISSING'}] {tool}" + (f" ({found})" if found else ""))
|
|
29
|
+
ok &= bool(found)
|
|
30
|
+
|
|
31
|
+
print(f" [ok] python {sys.version.split()[0]}")
|
|
32
|
+
for mod, why in (("numpy", "sharpest_frames, rep_counter, to_sdr"),
|
|
33
|
+
("PIL", "burn_cards, make_cover, safe_zone_check")):
|
|
34
|
+
try:
|
|
35
|
+
__import__(mod)
|
|
36
|
+
print(f" [ok] {mod}")
|
|
37
|
+
except ImportError:
|
|
38
|
+
pip = "Pillow" if mod == "PIL" else mod
|
|
39
|
+
print(f" [MISSING] {mod} -> python3 -m pip install {pip} (needed by {why})")
|
|
40
|
+
ok = False
|
|
41
|
+
|
|
42
|
+
if shutil.which("ffmpeg"):
|
|
43
|
+
z = ffmpeg_has_filter("zscale")
|
|
44
|
+
print(f" [{'ok' if z else 'info'}] ffmpeg zscale filter: "
|
|
45
|
+
+ ("fast HDR->SDR path available" if z else "not built in; to_sdr.py will use its numpy fallback (slower, same result)"))
|
|
46
|
+
|
|
47
|
+
for kind in ("latin", "cjk"):
|
|
48
|
+
f = find_font(kind)
|
|
49
|
+
print(f" [{'ok' if f else 'warn'}] {kind} font: {f or 'not found; pass --font / --cjk-font'}")
|
|
50
|
+
|
|
51
|
+
gb = free_gb(a.dir)
|
|
52
|
+
enough = gb >= a.min_free_gb
|
|
53
|
+
print(f" [{'ok' if enough else 'LOW'}] free disk at {a.dir}: {gb:.1f} GB (want >= {a.min_free_gb:g} GB)")
|
|
54
|
+
if not enough:
|
|
55
|
+
print(" Free space before rendering. Delete only your own temp/intermediate files;"
|
|
56
|
+
" never delete raw footage without the creator's explicit OK.")
|
|
57
|
+
ok = False
|
|
58
|
+
|
|
59
|
+
print("\nREADY" if ok else "\nNOT READY: fix the items above")
|
|
60
|
+
sys.exit(0 if ok else 1)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
if __name__ == "__main__":
|
|
64
|
+
main()
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Inspect a source clip before editing: size, fps, bit depth, colour format, HDR.
|
|
3
|
+
|
|
4
|
+
Rule: every source is probed first. HDR (HLG/PQ/Dolby Vision) footage must be
|
|
5
|
+
converted with to_sdr.py before any cut, card, still or cover is made, otherwise
|
|
6
|
+
colours wash out or blow out after export.
|
|
7
|
+
|
|
8
|
+
Usage: python3 probe_source.py CLIP [CLIP ...] [--json]
|
|
9
|
+
"""
|
|
10
|
+
import argparse
|
|
11
|
+
import json
|
|
12
|
+
|
|
13
|
+
try:
|
|
14
|
+
from .svs_common import (bit_depth, display_size, duration, fps, has_audio, hdr_kind,
|
|
15
|
+
probe, rotation, video_stream)
|
|
16
|
+
except ImportError:
|
|
17
|
+
from svs_common import (bit_depth, display_size, duration, fps, has_audio, hdr_kind,
|
|
18
|
+
probe, rotation, video_stream)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def describe(path: str) -> dict:
|
|
22
|
+
info = probe(path)
|
|
23
|
+
vs = video_stream(info)
|
|
24
|
+
w, h = display_size(vs)
|
|
25
|
+
br = info.get("format", {}).get("bit_rate")
|
|
26
|
+
d = {
|
|
27
|
+
"file": path,
|
|
28
|
+
"width": w, "height": h,
|
|
29
|
+
"aspect": f"{w}:{h}",
|
|
30
|
+
"is_vertical_9x16": abs(w / h - 9 / 16) < 0.02,
|
|
31
|
+
"fps": round(fps(vs), 3),
|
|
32
|
+
"duration_s": round(duration(info), 2),
|
|
33
|
+
"codec": vs.get("codec_name"),
|
|
34
|
+
"pix_fmt": vs.get("pix_fmt"),
|
|
35
|
+
"bit_depth": bit_depth(vs),
|
|
36
|
+
"color_primaries": vs.get("color_primaries"),
|
|
37
|
+
"color_transfer": vs.get("color_transfer"),
|
|
38
|
+
"color_space": vs.get("color_space"),
|
|
39
|
+
"rotation": rotation(vs),
|
|
40
|
+
"hdr": hdr_kind(vs),
|
|
41
|
+
"bitrate_mbps": round(int(br) / 1e6, 1) if br else None,
|
|
42
|
+
"has_audio": has_audio(info),
|
|
43
|
+
}
|
|
44
|
+
notes = []
|
|
45
|
+
if d["hdr"]:
|
|
46
|
+
notes.append(f"HDR source ({d['hdr']}). Run to_sdr.py FIRST; do not cut, grade or export stills from this file.")
|
|
47
|
+
elif d["bit_depth"] >= 10:
|
|
48
|
+
notes.append("10-bit SDR (log/flat profile likely). Lift shadows gently; do not crush blacks.")
|
|
49
|
+
if not d["is_vertical_9x16"]:
|
|
50
|
+
notes.append("Not 9:16. Plan a vertical crop; keep the subject's head and hands inside the frame.")
|
|
51
|
+
if d["fps"] >= 50:
|
|
52
|
+
notes.append(f"{d['fps']:g} fps: up to {d['fps'] / 30:.1f}x slow motion is clean at 30 fps output.")
|
|
53
|
+
if d["bitrate_mbps"] and d["bitrate_mbps"] < 8 and w >= 1080:
|
|
54
|
+
notes.append("Low bitrate source; avoid zooming in, it will look soft.")
|
|
55
|
+
if not d["has_audio"]:
|
|
56
|
+
notes.append("No audio track: rep_counter.py must use --mode motion.")
|
|
57
|
+
d["notes"] = notes
|
|
58
|
+
return d
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def main():
|
|
62
|
+
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
63
|
+
ap.add_argument("clips", nargs="+")
|
|
64
|
+
ap.add_argument("--json", action="store_true")
|
|
65
|
+
a = ap.parse_args()
|
|
66
|
+
out = [describe(c) for c in a.clips]
|
|
67
|
+
if a.json:
|
|
68
|
+
print(json.dumps(out, indent=2, ensure_ascii=False))
|
|
69
|
+
return
|
|
70
|
+
for d in out:
|
|
71
|
+
print(f"\n{d['file']}")
|
|
72
|
+
print(f" {d['width']}x{d['height']} {d['fps']:g} fps {d['duration_s']} s "
|
|
73
|
+
f"{d['codec']} {d['bit_depth']}-bit {d['bitrate_mbps']} Mbps")
|
|
74
|
+
print(f" colour: primaries={d['color_primaries']} transfer={d['color_transfer']} "
|
|
75
|
+
f"space={d['color_space']} rotation={d['rotation']}")
|
|
76
|
+
print(f" HDR: {d['hdr'] or 'no'} audio: {'yes' if d['has_audio'] else 'no'}")
|
|
77
|
+
for n in d["notes"]:
|
|
78
|
+
print(f" -> {n}")
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
if __name__ == "__main__":
|
|
82
|
+
main()
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Count repetitions (strikes, jumps, kicks, reps) from a clip's audio and/or motion.
|
|
3
|
+
|
|
4
|
+
An on-screen counter is a strong retention device, but a wrong number destroys
|
|
5
|
+
trust. Treat this output as a DRAFT: verify against the footage, and if the
|
|
6
|
+
creator's own count differs, theirs wins and you re-check.
|
|
7
|
+
|
|
8
|
+
Modes:
|
|
9
|
+
audio impact sounds (stick on target, feet landing, bag hits). Best when audible.
|
|
10
|
+
motion peaks of frame-to-frame movement. Use when there is no/unclear audio.
|
|
11
|
+
both runs both and reports where they agree (default).
|
|
12
|
+
|
|
13
|
+
Run it on the FINAL-speed edit if you plan to show the counter, so timestamps match.
|
|
14
|
+
|
|
15
|
+
Usage:
|
|
16
|
+
python3 rep_counter.py CLIP [--mode both] [--start S] [--end S] [--min-gap 0.25]
|
|
17
|
+
[--sensitivity 1.0] [--counter-start 0] [--counter-out counter.json]
|
|
18
|
+
[--label "{n}"] [--json]
|
|
19
|
+
"""
|
|
20
|
+
import argparse
|
|
21
|
+
import json
|
|
22
|
+
import subprocess
|
|
23
|
+
|
|
24
|
+
try:
|
|
25
|
+
from .svs_common import die, duration, fps, has_audio, need, need_numpy, probe, video_stream
|
|
26
|
+
except ImportError:
|
|
27
|
+
from svs_common import die, duration, fps, has_audio, need, need_numpy, probe, video_stream
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def pick_peaks(np, x, times, thresh, min_gap):
|
|
31
|
+
idx = [i for i in range(1, len(x) - 1) if x[i] >= thresh and x[i] >= x[i - 1] and x[i] > x[i + 1]]
|
|
32
|
+
idx.sort(key=lambda i: x[i], reverse=True)
|
|
33
|
+
chosen = []
|
|
34
|
+
for i in idx:
|
|
35
|
+
if all(abs(times[i] - times[j]) >= min_gap for j in chosen):
|
|
36
|
+
chosen.append(i)
|
|
37
|
+
return sorted(times[i] for i in chosen)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def robust_thresh(np, x, k):
|
|
41
|
+
med = float(np.median(x))
|
|
42
|
+
mad = float(np.median(np.abs(x - med))) or 1e-9
|
|
43
|
+
return med + k * 1.4826 * mad
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def audio_hits(np, clip, start, span, min_gap, sens):
|
|
47
|
+
sr, hop = 16000, 160
|
|
48
|
+
raw = subprocess.run(["ffmpeg", "-hide_banner", "-loglevel", "error", "-ss", str(start), "-t", str(span),
|
|
49
|
+
"-i", clip, "-vn", "-ac", "1", "-ar", str(sr), "-f", "f32le", "-"],
|
|
50
|
+
stdout=subprocess.PIPE, check=True).stdout
|
|
51
|
+
s = np.frombuffer(raw, dtype=np.float32)
|
|
52
|
+
if s.size < hop * 10:
|
|
53
|
+
return []
|
|
54
|
+
s = np.append(s[0], s[1:] - 0.97 * s[:-1]) # pre-emphasis: favours sharp transients
|
|
55
|
+
n = s.size // hop
|
|
56
|
+
e = (s[: n * hop].reshape(n, hop) ** 2).mean(axis=1)
|
|
57
|
+
loge = 10 * np.log10(e + 1e-10)
|
|
58
|
+
flux = np.maximum(0, loge[2:] - loge[:-2])
|
|
59
|
+
flux = np.concatenate([[0, 0], flux])
|
|
60
|
+
loud = loge > (np.median(loge) + 6)
|
|
61
|
+
flux = np.where(loud, flux, 0)
|
|
62
|
+
times = start + np.arange(n) * hop / sr
|
|
63
|
+
return pick_peaks(np, flux, times, robust_thresh(np, flux, 8 / sens), min_gap)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def motion_hits(np, clip, start, span, min_gap, sens, rate):
|
|
67
|
+
w, h = 160, 284
|
|
68
|
+
rate = min(rate, 60)
|
|
69
|
+
raw = subprocess.run(["ffmpeg", "-hide_banner", "-loglevel", "error", "-ss", str(start), "-t", str(span),
|
|
70
|
+
"-i", clip, "-vf", f"fps={rate},scale={w}:{h},format=gray",
|
|
71
|
+
"-f", "rawvideo", "-pix_fmt", "gray", "-"],
|
|
72
|
+
stdout=subprocess.PIPE, check=True).stdout
|
|
73
|
+
n = len(raw) // (w * h)
|
|
74
|
+
if n < 3:
|
|
75
|
+
return []
|
|
76
|
+
f = np.frombuffer(raw[: n * w * h], dtype=np.uint8).reshape(n, h, w).astype(np.float32)
|
|
77
|
+
m = np.abs(np.diff(f, axis=0)).mean(axis=(1, 2))
|
|
78
|
+
m = np.convolve(m, np.ones(3) / 3, mode="same")
|
|
79
|
+
times = start + (np.arange(len(m)) + 1) / rate
|
|
80
|
+
return pick_peaks(np, m, times, robust_thresh(np, m, 3 / sens), min_gap)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def main():
|
|
84
|
+
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
85
|
+
ap.add_argument("clip")
|
|
86
|
+
ap.add_argument("--mode", choices=["audio", "motion", "both"], default="both")
|
|
87
|
+
ap.add_argument("--start", type=float, default=0.0)
|
|
88
|
+
ap.add_argument("--end", type=float, default=None)
|
|
89
|
+
ap.add_argument("--min-gap", type=float, default=0.25, help="minimum seconds between two reps")
|
|
90
|
+
ap.add_argument("--sensitivity", type=float, default=1.0, help=">1 finds more hits, <1 fewer")
|
|
91
|
+
ap.add_argument("--counter-start", type=int, default=0, help="running total before this clip")
|
|
92
|
+
ap.add_argument("--counter-out", default=None, help="write a burn_cards.py JSON for an on-screen counter")
|
|
93
|
+
ap.add_argument("--label", default="{n}", help='counter text, e.g. "{n} / 11000"')
|
|
94
|
+
ap.add_argument("--sep", default=",", help='thousands separator in the label ("." for Turkish)')
|
|
95
|
+
ap.add_argument("--json", action="store_true")
|
|
96
|
+
a = ap.parse_args()
|
|
97
|
+
|
|
98
|
+
np = need_numpy()
|
|
99
|
+
need("ffmpeg")
|
|
100
|
+
info = probe(a.clip)
|
|
101
|
+
vs = video_stream(info)
|
|
102
|
+
end = a.end if a.end is not None else duration(info)
|
|
103
|
+
span = end - a.start
|
|
104
|
+
if span <= 0:
|
|
105
|
+
die("--end must be after --start")
|
|
106
|
+
|
|
107
|
+
res = {}
|
|
108
|
+
if a.mode in ("audio", "both"):
|
|
109
|
+
if has_audio(info):
|
|
110
|
+
res["audio"] = [round(t, 3) for t in audio_hits(np, a.clip, a.start, span, a.min_gap, a.sensitivity)]
|
|
111
|
+
elif a.mode == "audio":
|
|
112
|
+
die("clip has no audio; use --mode motion")
|
|
113
|
+
if a.mode in ("motion", "both"):
|
|
114
|
+
res["motion"] = [round(t, 3) for t in motion_hits(np, a.clip, a.start, span, a.min_gap, a.sensitivity, fps(vs))]
|
|
115
|
+
|
|
116
|
+
primary = "audio" if res.get("audio") else "motion"
|
|
117
|
+
hits = res.get(primary, [])
|
|
118
|
+
agree = None
|
|
119
|
+
if "audio" in res and "motion" in res and res["audio"]:
|
|
120
|
+
agree = sum(1 for t in res["audio"] if any(abs(t - u) <= 0.2 for u in res["motion"]))
|
|
121
|
+
|
|
122
|
+
if a.counter_out:
|
|
123
|
+
cards = []
|
|
124
|
+
all_t = [a.start] + hits
|
|
125
|
+
for i, t in enumerate(all_t):
|
|
126
|
+
t_end = all_t[i + 1] if i + 1 < len(all_t) else end
|
|
127
|
+
n = a.counter_start + i
|
|
128
|
+
if t_end - t > 0.01:
|
|
129
|
+
cards.append({"start": round(t, 3), "end": round(t_end, 3),
|
|
130
|
+
"lines": [a.label.format(n=f"{n:,}".replace(",", a.sep))]})
|
|
131
|
+
with open(a.counter_out, "w", encoding="utf-8") as fh:
|
|
132
|
+
json.dump({"style": {"size": 0.09, "y": 0.2, "color": "#FFFFFF", "accent": "#C9341F"},
|
|
133
|
+
"cards": cards}, fh, ensure_ascii=False, indent=2)
|
|
134
|
+
|
|
135
|
+
summary = {"primary": primary, "count": len(hits), "hits": hits,
|
|
136
|
+
"audio_count": len(res["audio"]) if "audio" in res else None,
|
|
137
|
+
"motion_count": len(res["motion"]) if "motion" in res else None,
|
|
138
|
+
"audio_motion_agree": agree,
|
|
139
|
+
"final_total": a.counter_start + len(hits)}
|
|
140
|
+
if a.json:
|
|
141
|
+
print(json.dumps(summary, indent=2))
|
|
142
|
+
return
|
|
143
|
+
print(f"Window {a.start:.2f}-{end:.2f}s")
|
|
144
|
+
if summary["audio_count"] is not None:
|
|
145
|
+
print(f" audio hits : {summary['audio_count']}")
|
|
146
|
+
if summary["motion_count"] is not None:
|
|
147
|
+
print(f" motion hits: {summary['motion_count']}")
|
|
148
|
+
if agree is not None:
|
|
149
|
+
print(f" audio hits confirmed by motion: {agree}/{summary['audio_count']}")
|
|
150
|
+
print(f" -> using {primary}: {len(hits)} reps; running total {a.counter_start} -> {summary['final_total']}")
|
|
151
|
+
print(" hits at: " + ", ".join(f"{t:.2f}" for t in hits[:60]) + (" ..." if len(hits) > 60 else ""))
|
|
152
|
+
if a.counter_out:
|
|
153
|
+
print(f" counter cards -> {a.counter_out} (burn with burn_cards.py)")
|
|
154
|
+
print("DRAFT COUNT: verify on the footage (fast reps blur together, echoes double-count).")
|
|
155
|
+
print("If the creator counted differently, use their number and re-check.")
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
if __name__ == "__main__":
|
|
159
|
+
main()
|