mediakit-cli 0.1.2__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.
- mediakit_cli/__init__.py +5 -0
- mediakit_cli/__main__.py +4 -0
- mediakit_cli/auto.py +217 -0
- mediakit_cli/cli.py +665 -0
- mediakit_cli/config.py +68 -0
- mediakit_cli/dub.py +174 -0
- mediakit_cli/edit.py +280 -0
- mediakit_cli/index.py +101 -0
- mediakit_cli/lyrics.py +92 -0
- mediakit_cli/mcp_server.py +162 -0
- mediakit_cli/music.py +226 -0
- mediakit_cli/ocr.py +129 -0
- mediakit_cli/polish.py +85 -0
- mediakit_cli/probe.py +89 -0
- mediakit_cli/shotcard.py +133 -0
- mediakit_cli/shots.py +109 -0
- mediakit_cli/subs.py +349 -0
- mediakit_cli/util.py +111 -0
- mediakit_cli/vlm.py +88 -0
- mediakit_cli/watch.py +119 -0
- mediakit_cli-0.1.2.dist-info/METADATA +221 -0
- mediakit_cli-0.1.2.dist-info/RECORD +26 -0
- mediakit_cli-0.1.2.dist-info/WHEEL +5 -0
- mediakit_cli-0.1.2.dist-info/entry_points.txt +3 -0
- mediakit_cli-0.1.2.dist-info/licenses/LICENSE +21 -0
- mediakit_cli-0.1.2.dist-info/top_level.txt +1 -0
mediakit_cli/util.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import subprocess
|
|
5
|
+
import sys
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from .config import find_tool
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _bootstrap_stdout() -> None:
|
|
12
|
+
for stream in (sys.stdout, sys.stderr):
|
|
13
|
+
try:
|
|
14
|
+
stream.reconfigure(encoding="utf-8", errors="replace")
|
|
15
|
+
except Exception:
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
_bootstrap_stdout()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
FFMPEG = find_tool("ffmpeg")
|
|
23
|
+
FFPROBE = find_tool("ffprobe")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def run_cmd(args, timeout: int = 3600):
|
|
27
|
+
return subprocess.run(
|
|
28
|
+
[str(a) for a in args],
|
|
29
|
+
capture_output=True,
|
|
30
|
+
text=True,
|
|
31
|
+
encoding="utf-8",
|
|
32
|
+
errors="replace",
|
|
33
|
+
timeout=timeout,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def ffmpeg(*args, timeout: int = 3600, cwd=None):
|
|
38
|
+
if not FFMPEG:
|
|
39
|
+
raise RuntimeError("找不到 ffmpeg:请安装后把 bin 目录加进 PATH")
|
|
40
|
+
p = subprocess.run(
|
|
41
|
+
[str(a) for a in [FFMPEG, "-y", "-hide_banner", "-loglevel", "error", *args]],
|
|
42
|
+
capture_output=True,
|
|
43
|
+
text=True,
|
|
44
|
+
encoding="utf-8",
|
|
45
|
+
errors="replace",
|
|
46
|
+
timeout=timeout,
|
|
47
|
+
cwd=str(cwd) if cwd else None,
|
|
48
|
+
)
|
|
49
|
+
if p.returncode != 0:
|
|
50
|
+
tail = (p.stderr or "").strip().splitlines()[-6:]
|
|
51
|
+
raise RuntimeError("ffmpeg 失败: " + " | ".join(tail))
|
|
52
|
+
return p
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def ffprobe_json(path):
|
|
56
|
+
if not FFPROBE:
|
|
57
|
+
return None
|
|
58
|
+
p = run_cmd(
|
|
59
|
+
[FFPROBE, "-v", "error", "-print_format", "json", "-show_format", "-show_streams", str(path)]
|
|
60
|
+
)
|
|
61
|
+
if p.returncode != 0:
|
|
62
|
+
return None
|
|
63
|
+
try:
|
|
64
|
+
return json.loads(p.stdout)
|
|
65
|
+
except Exception:
|
|
66
|
+
return None
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def dumps(obj) -> str:
|
|
70
|
+
return json.dumps(obj, ensure_ascii=False, indent=2)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def out_json(obj) -> None:
|
|
74
|
+
sys.stdout.write(dumps(obj) + "\n")
|
|
75
|
+
sys.stdout.flush()
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def ensure_dir(path) -> Path:
|
|
79
|
+
p = Path(path)
|
|
80
|
+
p.mkdir(parents=True, exist_ok=True)
|
|
81
|
+
return p
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def media_path(path, must_exist: bool = True) -> Path:
|
|
85
|
+
p = Path(path).expanduser().resolve()
|
|
86
|
+
if must_exist and not p.exists():
|
|
87
|
+
raise FileNotFoundError(f"找不到文件: {p}")
|
|
88
|
+
return p
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def grab_frame(src, t_sec: float, dst, width: int = 960) -> Path:
|
|
92
|
+
dst = Path(dst)
|
|
93
|
+
ensure_dir(dst.parent)
|
|
94
|
+
ffmpeg(
|
|
95
|
+
"-ss", f"{max(t_sec, 0):.3f}",
|
|
96
|
+
"-i", src,
|
|
97
|
+
"-frames:v", "1",
|
|
98
|
+
"-vf", f"scale={width}:-2",
|
|
99
|
+
"-q:v", "3",
|
|
100
|
+
dst,
|
|
101
|
+
)
|
|
102
|
+
return dst
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def human_duration(sec: float) -> str:
|
|
106
|
+
sec = float(sec or 0)
|
|
107
|
+
m, s = divmod(sec, 60)
|
|
108
|
+
h, m = divmod(int(m), 60)
|
|
109
|
+
if h:
|
|
110
|
+
return f"{h}:{m:02d}:{s:05.2f}"
|
|
111
|
+
return f"{m:.0f}:{s:05.2f}"
|
mediakit_cli/vlm.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import base64
|
|
4
|
+
import json
|
|
5
|
+
import re
|
|
6
|
+
import urllib.request
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from .config import ollama_base, ollama_chat_url, vlm_model
|
|
10
|
+
|
|
11
|
+
PROMPT = (
|
|
12
|
+
"你是分镜分析助手。看这张视频截图,只输出一个 JSON 对象,不要解释、不要代码块:\n"
|
|
13
|
+
'{"shot_size":"远景/全景/中景/近景/特写 之一",'
|
|
14
|
+
'"camera":"平视/俯视/仰视/倾斜 之一",'
|
|
15
|
+
'"motion":"静止/轻微/明显 之一",'
|
|
16
|
+
'"mood":"一个中文词",'
|
|
17
|
+
'"caption":"不超过20个字的中文画面描述"}'
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _opener():
|
|
22
|
+
# Local loopback must bypass any configured proxy.
|
|
23
|
+
return urllib.request.build_opener(urllib.request.ProxyHandler({}))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _post(payload: dict, endpoint: str, timeout: int = 180) -> dict:
|
|
27
|
+
req = urllib.request.Request(
|
|
28
|
+
endpoint,
|
|
29
|
+
data=json.dumps(payload).encode("utf-8"),
|
|
30
|
+
headers={"Content-Type": "application/json"},
|
|
31
|
+
)
|
|
32
|
+
with _opener().open(req, timeout=timeout) as resp:
|
|
33
|
+
return json.loads(resp.read().decode("utf-8"))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _parse_json(text: str) -> dict:
|
|
37
|
+
text = text.strip()
|
|
38
|
+
text = re.sub(r"^```(?:json)?|```$", "", text, flags=re.MULTILINE).strip()
|
|
39
|
+
start, end = text.find("{"), text.rfind("}")
|
|
40
|
+
if start >= 0 and end > start:
|
|
41
|
+
try:
|
|
42
|
+
return json.loads(text[start:end + 1])
|
|
43
|
+
except Exception:
|
|
44
|
+
pass
|
|
45
|
+
return {"raw": text[:300]}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def describe_image(
|
|
49
|
+
image_path,
|
|
50
|
+
model: str | None = None,
|
|
51
|
+
endpoint: str | None = None,
|
|
52
|
+
timeout: int = 180,
|
|
53
|
+
) -> dict:
|
|
54
|
+
model = model or vlm_model()
|
|
55
|
+
endpoint = endpoint or ollama_chat_url()
|
|
56
|
+
p = Path(image_path)
|
|
57
|
+
b64 = base64.b64encode(p.read_bytes()).decode("ascii")
|
|
58
|
+
payload = {
|
|
59
|
+
"model": model,
|
|
60
|
+
"messages": [
|
|
61
|
+
{
|
|
62
|
+
"role": "user",
|
|
63
|
+
"content": [
|
|
64
|
+
{"type": "text", "text": PROMPT},
|
|
65
|
+
{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{b64}"}},
|
|
66
|
+
],
|
|
67
|
+
}
|
|
68
|
+
],
|
|
69
|
+
"max_tokens": 300,
|
|
70
|
+
"temperature": 0.2,
|
|
71
|
+
"stream": False,
|
|
72
|
+
}
|
|
73
|
+
data = _post(payload, endpoint, timeout=timeout)
|
|
74
|
+
text = ((data.get("choices") or [{}])[0].get("message") or {}).get("content") or ""
|
|
75
|
+
result = _parse_json(text)
|
|
76
|
+
result["model"] = model
|
|
77
|
+
return result
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def available(model: str | None = None) -> bool:
|
|
81
|
+
model = model or vlm_model()
|
|
82
|
+
try:
|
|
83
|
+
req = urllib.request.Request(ollama_base().rsplit("/v1", 1)[0] + "/api/tags")
|
|
84
|
+
with _opener().open(req, timeout=3) as resp:
|
|
85
|
+
data = json.loads(resp.read().decode("utf-8"))
|
|
86
|
+
return any(m.get("name", "").startswith(model) for m in data.get("models", []))
|
|
87
|
+
except Exception:
|
|
88
|
+
return False
|
mediakit_cli/watch.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import sys
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from .probe import has_audio, probe
|
|
8
|
+
from .shots import contact_sheet, detect_shots
|
|
9
|
+
from .subs import build_lines, transcribe, write_subtitles
|
|
10
|
+
from .util import ensure_dir, grab_frame
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _pick_times(shots: list, max_frames: int) -> list:
|
|
14
|
+
duration = max(s["end"] for s in shots) if shots else 0.0
|
|
15
|
+
if len(shots) <= 1:
|
|
16
|
+
n = min(max_frames, max(3, int(duration // 2) or 3))
|
|
17
|
+
return [round(duration * (i + 1) / (n + 1), 3) for i in range(n)]
|
|
18
|
+
picked = shots
|
|
19
|
+
if len(shots) > max_frames:
|
|
20
|
+
step = len(shots) / float(max_frames)
|
|
21
|
+
picked = [shots[min(int(i * step), len(shots) - 1)] for i in range(max_frames)]
|
|
22
|
+
return [round((s["start"] + s["end"]) / 2, 3) for s in picked]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def build_card(
|
|
26
|
+
path,
|
|
27
|
+
out_dir,
|
|
28
|
+
lang: str | None = None,
|
|
29
|
+
model: str = "small",
|
|
30
|
+
max_frames: int = 12,
|
|
31
|
+
do_asr: bool = True,
|
|
32
|
+
do_subs: bool = True,
|
|
33
|
+
do_ocr: bool = False,
|
|
34
|
+
progress=None,
|
|
35
|
+
) -> dict:
|
|
36
|
+
note = progress or (lambda *_: None)
|
|
37
|
+
info = probe(path)
|
|
38
|
+
note("probe ok")
|
|
39
|
+
|
|
40
|
+
shots = detect_shots(path)
|
|
41
|
+
note(f"shots: {len(shots)}")
|
|
42
|
+
|
|
43
|
+
out = ensure_dir(out_dir)
|
|
44
|
+
frames_dir = ensure_dir(out / "frames")
|
|
45
|
+
times = _pick_times(shots, max_frames)
|
|
46
|
+
frames = []
|
|
47
|
+
for i, t in enumerate(times, 1):
|
|
48
|
+
dst = frames_dir / f"f{i:03d}.jpg"
|
|
49
|
+
try:
|
|
50
|
+
grab_frame(path, t, dst, width=960)
|
|
51
|
+
frames.append({"t": t, "path": str(dst)})
|
|
52
|
+
except Exception as exc:
|
|
53
|
+
note(f"frame {i} failed: {exc}")
|
|
54
|
+
|
|
55
|
+
sheet = None
|
|
56
|
+
try:
|
|
57
|
+
sheet = contact_sheet(path, shots, out / "contact.jpg", limit=9)
|
|
58
|
+
except Exception as exc:
|
|
59
|
+
note(f"contact sheet failed: {exc}")
|
|
60
|
+
|
|
61
|
+
onscreen = None
|
|
62
|
+
if do_ocr:
|
|
63
|
+
from .ocr import ocr_image
|
|
64
|
+
|
|
65
|
+
onscreen = []
|
|
66
|
+
for fr in frames:
|
|
67
|
+
try:
|
|
68
|
+
texts = ocr_image(fr["path"])
|
|
69
|
+
except Exception as exc:
|
|
70
|
+
note(f"ocr failed at {fr['t']}: {exc}")
|
|
71
|
+
texts = []
|
|
72
|
+
onscreen.append({"t": fr["t"], "texts": texts})
|
|
73
|
+
note(f"ocr ok: {sum(len(x['texts']) for x in onscreen)} 条文字")
|
|
74
|
+
|
|
75
|
+
transcript, subs_files, asr_error = [], {}, None
|
|
76
|
+
if do_asr and has_audio(info):
|
|
77
|
+
try:
|
|
78
|
+
note(f"asr: model={model} lang={lang or 'auto'}")
|
|
79
|
+
asr = transcribe(path, language=lang, model=model)
|
|
80
|
+
transcript = asr["segments"]
|
|
81
|
+
if do_subs:
|
|
82
|
+
lines = build_lines(asr)
|
|
83
|
+
subs_files = write_subtitles(lines, out, stem="subs")
|
|
84
|
+
note(f"asr ok: {len(transcript)} segments")
|
|
85
|
+
except Exception as exc: # network / model failure should not kill the card
|
|
86
|
+
asr_error = str(exc)
|
|
87
|
+
note(f"asr failed: {exc}")
|
|
88
|
+
|
|
89
|
+
card = {
|
|
90
|
+
"probe": info,
|
|
91
|
+
"shots": shots,
|
|
92
|
+
"keyframes": frames,
|
|
93
|
+
"transcript": transcript,
|
|
94
|
+
"onscreen": onscreen,
|
|
95
|
+
"files": {
|
|
96
|
+
"dir": str(out),
|
|
97
|
+
"contact": str(sheet) if sheet else None,
|
|
98
|
+
"subtitles": subs_files,
|
|
99
|
+
"card": str(out / "card.json"),
|
|
100
|
+
},
|
|
101
|
+
"asr_error": asr_error,
|
|
102
|
+
"generator": "mediakit watch",
|
|
103
|
+
}
|
|
104
|
+
(out / "card.json").write_text(json.dumps(card, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
105
|
+
return card
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def main_watch(args) -> dict:
|
|
109
|
+
card = build_card(
|
|
110
|
+
args.file,
|
|
111
|
+
args.out,
|
|
112
|
+
lang=args.lang,
|
|
113
|
+
model=args.model,
|
|
114
|
+
max_frames=args.frames,
|
|
115
|
+
do_asr=not args.no_asr,
|
|
116
|
+
do_subs=not args.no_subs,
|
|
117
|
+
progress=(lambda m: print(f"[watch] {m}", file=sys.stderr)),
|
|
118
|
+
)
|
|
119
|
+
return card
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mediakit-cli
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: Agent-friendly CLI for watching videos, analyzing music, subtitling, dubbing and beat-synced editing.
|
|
5
|
+
Author: mediakit contributors
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/your-name/mediakit
|
|
8
|
+
Keywords: video,subtitles,ffmpeg,whisper,agent,mcp
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Topic :: Multimedia :: Video
|
|
12
|
+
Classifier: Topic :: Multimedia :: Sound/Audio
|
|
13
|
+
Requires-Python: >=3.10
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: numpy>=1.24
|
|
17
|
+
Requires-Dist: pillow>=10
|
|
18
|
+
Requires-Dist: pysubs2>=1.6
|
|
19
|
+
Provides-Extra: asr
|
|
20
|
+
Requires-Dist: faster-whisper>=1.0; extra == "asr"
|
|
21
|
+
Provides-Extra: vision
|
|
22
|
+
Requires-Dist: opencv-python>=4.8; extra == "vision"
|
|
23
|
+
Requires-Dist: scenedetect>=0.6; extra == "vision"
|
|
24
|
+
Requires-Dist: rapidocr-onnxruntime>=1.3; extra == "vision"
|
|
25
|
+
Provides-Extra: timeline
|
|
26
|
+
Requires-Dist: opentimelineio>=0.16; extra == "timeline"
|
|
27
|
+
Provides-Extra: dl
|
|
28
|
+
Requires-Dist: yt-dlp>=2024.1.1; extra == "dl"
|
|
29
|
+
Provides-Extra: music
|
|
30
|
+
Requires-Dist: librosa>=0.10; extra == "music"
|
|
31
|
+
Requires-Dist: scipy>=1.10; extra == "music"
|
|
32
|
+
Requires-Dist: soundfile>=0.12; extra == "music"
|
|
33
|
+
Provides-Extra: separate
|
|
34
|
+
Requires-Dist: audio-separator>=0.20; extra == "separate"
|
|
35
|
+
Provides-Extra: search
|
|
36
|
+
Requires-Dist: open-clip-torch>=2.20; extra == "search"
|
|
37
|
+
Provides-Extra: mcp
|
|
38
|
+
Requires-Dist: mcp>=1.0; extra == "mcp"
|
|
39
|
+
Provides-Extra: windows
|
|
40
|
+
Requires-Dist: pywin32>=306; sys_platform == "win32" and extra == "windows"
|
|
41
|
+
Provides-Extra: all
|
|
42
|
+
Requires-Dist: faster-whisper>=1.0; extra == "all"
|
|
43
|
+
Requires-Dist: opencv-python>=4.8; extra == "all"
|
|
44
|
+
Requires-Dist: scenedetect>=0.6; extra == "all"
|
|
45
|
+
Requires-Dist: rapidocr-onnxruntime>=1.3; extra == "all"
|
|
46
|
+
Requires-Dist: opentimelineio>=0.16; extra == "all"
|
|
47
|
+
Requires-Dist: yt-dlp>=2024.1.1; extra == "all"
|
|
48
|
+
Requires-Dist: librosa>=0.10; extra == "all"
|
|
49
|
+
Requires-Dist: scipy>=1.10; extra == "all"
|
|
50
|
+
Requires-Dist: soundfile>=0.12; extra == "all"
|
|
51
|
+
Requires-Dist: audio-separator>=0.20; extra == "all"
|
|
52
|
+
Requires-Dist: open-clip-torch>=2.20; extra == "all"
|
|
53
|
+
Requires-Dist: mcp>=1.0; extra == "all"
|
|
54
|
+
Requires-Dist: pywin32>=306; sys_platform == "win32" and extra == "all"
|
|
55
|
+
Provides-Extra: dev
|
|
56
|
+
Requires-Dist: pytest>=7.4; extra == "dev"
|
|
57
|
+
Requires-Dist: ruff>=0.4; extra == "dev"
|
|
58
|
+
Dynamic: license-file
|
|
59
|
+
|
|
60
|
+
# mediakit
|
|
61
|
+
|
|
62
|
+
**One CLI, 17 commands, JSON out — for agents that need to watch, listen, subtitle and cut.**
|
|
63
|
+
|
|
64
|
+
`mediakit` is a thin orchestration layer over mature media tools. It does not
|
|
65
|
+
reimplement decoding, ASR or scene detection; it calls them and returns
|
|
66
|
+
structured results an agent can reason about, plus an MCP server so the whole
|
|
67
|
+
toolkit can be attached to any MCP client.
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
$ mk watch clip.mp4 --out work/clip --lang zh --ocr
|
|
71
|
+
语言 zh · 4 镜头 · 12 关键帧 · 转写 8 段 · 画面文字 2 条
|
|
72
|
+
$ mk search work/clip/index "穿黑裙子的女孩在草地上" --top 3
|
|
73
|
+
42.50s score 0.311 ...
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
[中文说明](README.zh-CN.md)
|
|
77
|
+
|
|
78
|
+
## Why another wrapper?
|
|
79
|
+
|
|
80
|
+
Most tools are excellent at one step and then stop: PySceneDetect prints a
|
|
81
|
+
table, Whisper emits one long line, CLIP libraries return tensors. An agent
|
|
82
|
+
needs the opposite: short, composable commands with stable JSON, and no GUI.
|
|
83
|
+
|
|
84
|
+
| Upstream | What it does | What `mk` adds |
|
|
85
|
+
|---|---|---|
|
|
86
|
+
| PySceneDetect | shot boundaries | `contact.jpg`, `shots.json`, OTIO export |
|
|
87
|
+
| faster-whisper | segments + words | pause-based line breaking, width limits, 繁→简, karaoke, QA |
|
|
88
|
+
| ffmpeg | encode/cut/burn | one plan file, xfade + acrossfade, subtitle rescaling |
|
|
89
|
+
| RapidOCR | text boxes | frame sampling, de-dup, SRT output |
|
|
90
|
+
| CLIP | embeddings | index/search commands with thumbnails |
|
|
91
|
+
| librosa | tempo/beats | tempogram tempo prior, sections, chords, melody |
|
|
92
|
+
| VideoCaptioner | LLM subtitle polish | one command, local Ollama, bilingual output |
|
|
93
|
+
|
|
94
|
+
## Install
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
pip install "mediakit-cli[all]" # everything
|
|
98
|
+
pip install mediakit-cli # core only: probe, edit, auto, plan logic
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
`ffmpeg` must be on `PATH` (or set `MEDIAKIT_FFMPEG`). Optional groups:
|
|
102
|
+
|
|
103
|
+
The distribution is named `mediakit-cli`; the Python import package is
|
|
104
|
+
`mediakit_cli` (to avoid a collision with the unrelated PyPI package
|
|
105
|
+
`mediakit`). The CLI command is `mk` either way.
|
|
106
|
+
|
|
107
|
+
| Extra | Enables | Install |
|
|
108
|
+
|---|---|---|
|
|
109
|
+
| `asr` | `subs`, `watch`, `lyrics` | `faster-whisper` |
|
|
110
|
+
| `vision` | `shots`, `shotcard`, `ocr` | OpenCV, PySceneDetect, RapidOCR |
|
|
111
|
+
| `music` | `music` | librosa |
|
|
112
|
+
| `search` | `index`, `search` | open_clip + ViT-B-32 weights |
|
|
113
|
+
| `separate` | `lyrics --separate` | audio-separator |
|
|
114
|
+
| `mcp` | `mediakit-mcp` | MCP SDK |
|
|
115
|
+
| `windows` | `dub`, `voices` | pywin32 + SAPI |
|
|
116
|
+
| `timeline` | `shots --otio` | OpenTimelineIO |
|
|
117
|
+
|
|
118
|
+
Environment overrides: `MEDIAKIT_FFMPEG`, `MEDIAKIT_AUDIO_SEPARATOR`,
|
|
119
|
+
`MEDIAKIT_VIDEOCAPTIONER`, `MEDIAKIT_OLLAMA_BASE`, `MEDIAKIT_VLM_MODEL`.
|
|
120
|
+
|
|
121
|
+
## Commands
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
# look
|
|
125
|
+
mk probe a.mp4
|
|
126
|
+
mk watch a.mp4 --out work/a --lang zh --ocr
|
|
127
|
+
mk frames a.mp4 --n 12 --out work/a/frames
|
|
128
|
+
mk ocr a.mp4 --out work/a/ocr --every 2
|
|
129
|
+
mk index a.mp4 --out work/a/index
|
|
130
|
+
mk search work/a/index "a girl running on grass"
|
|
131
|
+
|
|
132
|
+
# listen
|
|
133
|
+
mk music song.mp3 --chords --melody --engine beat-this
|
|
134
|
+
mk lyrics song.mp3 --out work/lyrics --lang ja
|
|
135
|
+
|
|
136
|
+
# dissect
|
|
137
|
+
mk shots a.mp4 --out work/a --otio
|
|
138
|
+
mk shotcard a.mp4 --out work/a/card --vlm
|
|
139
|
+
|
|
140
|
+
# subtitle
|
|
141
|
+
mk subs a.mp4 --lang zh --out work/a --size 1080x1920 --max-chars 12 --karaoke --qa
|
|
142
|
+
mk subqa work/a/subs.srt
|
|
143
|
+
mk polish work/a/subs.srt --out work/a/polished.srt
|
|
144
|
+
mk voices
|
|
145
|
+
mk dub a.mp4 --srt work/a/subs.srt --out work/dub.mp4 --voice Huihui --mix-original
|
|
146
|
+
|
|
147
|
+
# cut
|
|
148
|
+
mk edit work/plan.json --out work/final.mp4
|
|
149
|
+
mk auto --music bgm.mp3 --src footage --out work/mv.mp4 --transition fade
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Every command accepts `--json`. Without it you get a short human summary.
|
|
153
|
+
|
|
154
|
+
### `mk auto` — beat-synced montage
|
|
155
|
+
|
|
156
|
+
Analyzes the track, decides how many beats per cut per section (quiet sections
|
|
157
|
+
get longer cuts, loud ones shorter), picks shots from a folder, snaps cuts to
|
|
158
|
+
beats and renders `xfade` transitions with matching `acrossfade` audio.
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
mk auto --music bgm.mp3 --src footage --out mv.mp4 \
|
|
162
|
+
--size 1080x1920 --fit crop --transition fade --seed 7
|
|
163
|
+
mk auto --music bgm.mp3 --src footage --out mv.mp4 --plan-only # plan only
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## MCP server
|
|
167
|
+
|
|
168
|
+
```json
|
|
169
|
+
{
|
|
170
|
+
"mcpServers": {
|
|
171
|
+
"mediakit": { "command": "mediakit-mcp" }
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
12 tools: `probe`, `shots`, `music`, `subs`, `ocr`, `shotcard`, `index`,
|
|
177
|
+
`search`, `lyrics`, `dub`, `edit`, `auto`.
|
|
178
|
+
|
|
179
|
+
## Measured, not assumed
|
|
180
|
+
|
|
181
|
+
Numbers below were produced on a local machine (CPU) with the benchmark
|
|
182
|
+
scripts in `tools/`. They are small-sample results, not leaderboard claims.
|
|
183
|
+
|
|
184
|
+
| Area | Result |
|
|
185
|
+
|---|---|
|
|
186
|
+
| Shot detection | 3 hard cuts detected at exactly 4.00s / 8.00s |
|
|
187
|
+
| Subtitles | 16.5s Chinese speech → 9 lines, traditional→simplified, width capped |
|
|
188
|
+
| Karaoke | `\kf` per word; at 0.2s 65% of subtitle pixels still unsung color |
|
|
189
|
+
| OCR | read burned subtitles back as 「大家晚上好。」and merged into SRT |
|
|
190
|
+
| Retrieval (synthetic, 8 segments) | recall@1 75% descriptive / 88% short, recall@3 100% |
|
|
191
|
+
| Retrieval (real footage, 8 clips) | recall@1 75%, recall@3 100% |
|
|
192
|
+
| Lyric CER vs reference subs | mix 89.7% → vocals 60.3% (small) → **54.4% (medium)** |
|
|
193
|
+
| Tempo correction | librosa default 103.36 BPM was a 4:3 artifact; tempogram prior → 80.75 BPM |
|
|
194
|
+
| Montage | 7 segments from a 20s track; 18.50s with 6×0.25s fades |
|
|
195
|
+
| Audio crossfade | 3×2s clips + 0.25s fade + keep_audio → 5.50s, audio kept |
|
|
196
|
+
| Dubbing | 9 lines → 18.60s output, full length, 2ch/48kHz |
|
|
197
|
+
|
|
198
|
+
## Known limits
|
|
199
|
+
|
|
200
|
+
- Retrieval benchmarks are small (8 segments/clips) and CLIP is
|
|
201
|
+
phrasing-sensitive; low-information frames (pure white/black) fail.
|
|
202
|
+
- Singing transcription is still hard: 54% CER is the good case.
|
|
203
|
+
- `dub` uses Windows SAPI — robotic, and long lines are time-compressed at most 2×.
|
|
204
|
+
- VLM shot descriptions were validated on a handful of frames.
|
|
205
|
+
- `beat_this` and librosa often disagree by a few BPM; the package now anchors
|
|
206
|
+
tempo with a tempogram prior but does not prove which tracker is musically right.
|
|
207
|
+
- Transition handling assumes hard cuts when detecting shots.
|
|
208
|
+
|
|
209
|
+
## Layout
|
|
210
|
+
|
|
211
|
+
```
|
|
212
|
+
mediakit_cli/ package (17 modules + MCP server)
|
|
213
|
+
tools/ benchmarks: retrieval, lyrics CER, tempo
|
|
214
|
+
docs/ architecture and data contracts
|
|
215
|
+
examples/ sample edit plan
|
|
216
|
+
tests/ unit tests for pure logic
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## License
|
|
220
|
+
|
|
221
|
+
MIT
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
mediakit_cli/__init__.py,sha256=HVBRMvS0AJIvoyg-duZ_VhVdjMBNgkT-8CdqCQzRCXI,126
|
|
2
|
+
mediakit_cli/__main__.py,sha256=MHKZ_ae3fSLGTLUUMOx15fWdeOnJSHhq-zslRP5F5Lc,79
|
|
3
|
+
mediakit_cli/auto.py,sha256=DXUbwWD0cUqq_WAh0tfSlqfwlJkT_GOaa9iYdlCDo1g,7288
|
|
4
|
+
mediakit_cli/cli.py,sha256=dHGoUqo2UG_KMpa6rQz79yBB2cvz5N78KRhGoamG0TI,25170
|
|
5
|
+
mediakit_cli/config.py,sha256=uaDv2KlxjZBuBNqn3XdVDHlnLjuT9dShBZiaFPOQOb8,2005
|
|
6
|
+
mediakit_cli/dub.py,sha256=lZ-RjGgYVIVDzMWSsA6ovBhssB-YShRcVMMXcTn4Ht4,5149
|
|
7
|
+
mediakit_cli/edit.py,sha256=R4hR9zBjPs2sjb0NMhYH9XlzjcrAGJ0N8IAKU-uxuCg,9181
|
|
8
|
+
mediakit_cli/index.py,sha256=E8dEwxe77NsbfjVuKrSPOP-OsRHS-mz_AMw31CSW0kA,3410
|
|
9
|
+
mediakit_cli/lyrics.py,sha256=5D1u5lmlvBdDnWPZ48127eDbNFHbOAnK1HEGobK7Rr8,2786
|
|
10
|
+
mediakit_cli/mcp_server.py,sha256=5G3FCk9Lkpk0sgKBUVQq33HJDEdxPEKsoRYHq247Djs,4893
|
|
11
|
+
mediakit_cli/music.py,sha256=ntxwgtFeNDYx0FAkaEMT-lgbpOd7u-VwSMuvhZ0CLHE,7998
|
|
12
|
+
mediakit_cli/ocr.py,sha256=_tmVRuZG6WO_K7js-Lfm3Gu8sJIh4r5nF_D6ywqRBQo,3531
|
|
13
|
+
mediakit_cli/polish.py,sha256=lxIYGxlgMTPjmC2G9CQdQMxFMDixvJEOiBxwqorYEPA,2374
|
|
14
|
+
mediakit_cli/probe.py,sha256=DtZDyoqShgejcHhC6BDxU0IMx68I_qcZyCVl_U69X18,2930
|
|
15
|
+
mediakit_cli/shotcard.py,sha256=YDErV5kqzb6wsgetkefGZPVwxcXFKI0j39pZDyHnYiM,5111
|
|
16
|
+
mediakit_cli/shots.py,sha256=JrlkE1SznnGOPLgXFpJOiC18Xf1vABVHaOAR1KGSq0Q,3684
|
|
17
|
+
mediakit_cli/subs.py,sha256=c-_Snabt9JxmnjPVJBev9VHoQ9fGF52JUdjrrSqeClM,10641
|
|
18
|
+
mediakit_cli/util.py,sha256=Vkt4wQAffoXednSdkh04bYa8ov8qGw4mremrUMzIMl8,2570
|
|
19
|
+
mediakit_cli/vlm.py,sha256=FCzNliEuP01S0pJkG1MAPtp8TgFIIWVdvTwMt8jpMIQ,2777
|
|
20
|
+
mediakit_cli/watch.py,sha256=FsHWwEcmrNP_3KJ0RNaLyhxsmgUFB-EfZ_EKknkB0zg,3686
|
|
21
|
+
mediakit_cli-0.1.2.dist-info/licenses/LICENSE,sha256=0isUMG3yzBtnfZ7w8nzja_X6yDdNr_PAEcP1dZpwbn0,1078
|
|
22
|
+
mediakit_cli-0.1.2.dist-info/METADATA,sha256=-DQc6ilRtz8hmoc6WhtJZH0NRFmrbAo4sgfW0e2LYM8,8770
|
|
23
|
+
mediakit_cli-0.1.2.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
24
|
+
mediakit_cli-0.1.2.dist-info/entry_points.txt,sha256=zZMsLn9cUGuxscHx5UsJVe2esvKc_cqloquYjzeeeNE,89
|
|
25
|
+
mediakit_cli-0.1.2.dist-info/top_level.txt,sha256=iTZIARUWqeR-vvJzkC059nE1l8wkZ0tsP1S1TxWu284,13
|
|
26
|
+
mediakit_cli-0.1.2.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 mediakit contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mediakit_cli
|