Metadata-Version: 2.4
Name: mediakit-cli
Version: 0.1.4
Summary: Agent-friendly CLI for watching videos, analyzing music, subtitling, dubbing and beat-synced editing.
Author: mediakit contributors
License-Expression: MIT
Project-URL: Homepage, https://github.com/Lee2277-t/mediakit
Project-URL: Repository, https://github.com/Lee2277-t/mediakit
Project-URL: Issues, https://github.com/Lee2277-t/mediakit/issues
Keywords: video,subtitles,ffmpeg,whisper,agent,mcp
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Topic :: Multimedia :: Video
Classifier: Topic :: Multimedia :: Sound/Audio
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.24
Requires-Dist: pillow>=10
Requires-Dist: pysubs2>=1.6
Provides-Extra: asr
Requires-Dist: faster-whisper>=1.0; extra == "asr"
Provides-Extra: vision
Requires-Dist: opencv-python>=4.8; extra == "vision"
Requires-Dist: scenedetect>=0.6; extra == "vision"
Requires-Dist: rapidocr-onnxruntime>=1.3; extra == "vision"
Provides-Extra: timeline
Requires-Dist: opentimelineio>=0.16; extra == "timeline"
Provides-Extra: dl
Requires-Dist: yt-dlp>=2024.1.1; extra == "dl"
Provides-Extra: music
Requires-Dist: librosa>=0.10; extra == "music"
Requires-Dist: scipy>=1.10; extra == "music"
Requires-Dist: soundfile>=0.12; extra == "music"
Provides-Extra: separate
Requires-Dist: audio-separator>=0.20; extra == "separate"
Provides-Extra: search
Requires-Dist: open-clip-torch>=2.20; extra == "search"
Provides-Extra: mcp
Requires-Dist: mcp>=1.0; extra == "mcp"
Provides-Extra: windows
Requires-Dist: pywin32>=306; sys_platform == "win32" and extra == "windows"
Provides-Extra: all
Requires-Dist: faster-whisper>=1.0; extra == "all"
Requires-Dist: opencv-python>=4.8; extra == "all"
Requires-Dist: scenedetect>=0.6; extra == "all"
Requires-Dist: rapidocr-onnxruntime>=1.3; extra == "all"
Requires-Dist: opentimelineio>=0.16; extra == "all"
Requires-Dist: yt-dlp>=2024.1.1; extra == "all"
Requires-Dist: librosa>=0.10; extra == "all"
Requires-Dist: scipy>=1.10; extra == "all"
Requires-Dist: soundfile>=0.12; extra == "all"
Requires-Dist: audio-separator>=0.20; extra == "all"
Requires-Dist: open-clip-torch>=2.20; extra == "all"
Requires-Dist: mcp>=1.0; extra == "all"
Requires-Dist: pywin32>=306; sys_platform == "win32" and extra == "all"
Provides-Extra: dev
Requires-Dist: pytest>=7.4; extra == "dev"
Requires-Dist: ruff>=0.4; extra == "dev"
Dynamic: license-file

# mediakit

**One CLI, 17 commands, JSON out — for agents that need to watch, listen, subtitle and cut.**

`mediakit` is a thin orchestration layer over mature media tools. It does not
reimplement decoding, ASR or scene detection; it calls them and returns
structured results an agent can reason about, plus an MCP server so the whole
toolkit can be attached to any MCP client.

```
$ mk watch clip.mp4 --out work/clip --lang zh --ocr
语言 zh · 4 镜头 · 12 关键帧 · 转写 8 段 · 画面文字 2 条
$ mk search work/clip/index "穿黑裙子的女孩在草地上" --top 3
   42.50s  score 0.311  ...
```

[中文说明](README.zh-CN.md)

## Why another wrapper?

Most tools are excellent at one step and then stop: PySceneDetect prints a
table, Whisper emits one long line, CLIP libraries return tensors. An agent
needs the opposite: short, composable commands with stable JSON, and no GUI.

| Upstream | What it does | What `mk` adds |
|---|---|---|
| PySceneDetect | shot boundaries | `contact.jpg`, `shots.json`, OTIO export |
| faster-whisper | segments + words | pause-based line breaking, width limits, 繁→简, karaoke, QA |
| ffmpeg | encode/cut/burn | one plan file, xfade + acrossfade, subtitle rescaling |
| RapidOCR | text boxes | frame sampling, de-dup, SRT output |
| CLIP | embeddings | index/search commands with thumbnails |
| librosa | tempo/beats | tempogram tempo prior, sections, chords, melody |
| VideoCaptioner | LLM subtitle polish | one command, local Ollama, bilingual output |

## Install

```bash
pip install "mediakit-cli[all]"     # everything
pip install mediakit-cli            # core only: probe, edit, auto, plan logic
```

`ffmpeg` must be on `PATH` (or set `MEDIAKIT_FFMPEG`). Optional groups:

The distribution is named `mediakit-cli`; the Python import package is
`mediakit_cli` (to avoid a collision with the unrelated PyPI package
`mediakit`). The CLI command is `mk` either way.

| Extra | Enables | Install |
|---|---|---|
| `asr` | `subs`, `watch`, `lyrics` | `faster-whisper` |
| `vision` | `shots`, `shotcard`, `ocr` | OpenCV, PySceneDetect, RapidOCR |
| `music` | `music` | librosa |
| `search` | `index`, `search` | open_clip + ViT-B-32 weights |
| `separate` | `lyrics --separate` | audio-separator |
| `mcp` | `mediakit-mcp` | MCP SDK |
| `windows` | `dub`, `voices` | pywin32 + SAPI |
| `timeline` | `shots --otio` | OpenTimelineIO |

Environment overrides: `MEDIAKIT_FFMPEG`, `MEDIAKIT_AUDIO_SEPARATOR`,
`MEDIAKIT_VIDEOCAPTIONER`, `MEDIAKIT_OLLAMA_BASE`, `MEDIAKIT_VLM_MODEL`.

## Commands

```bash
# look
mk probe    a.mp4
mk watch    a.mp4 --out work/a --lang zh --ocr
mk frames   a.mp4 --n 12 --out work/a/frames
mk ocr      a.mp4 --out work/a/ocr --every 2
mk index    a.mp4 --out work/a/index
mk search   work/a/index "a girl running on grass"

# listen
mk music    song.mp3 --chords --melody --engine beat-this
mk lyrics   song.mp3 --out work/lyrics --lang ja

# dissect
mk shots    a.mp4 --out work/a --otio
mk shotcard a.mp4 --out work/a/card --vlm

# subtitle
mk subs     a.mp4 --lang zh --out work/a --size 1080x1920 --max-chars 12 --karaoke --qa
mk subqa    work/a/subs.srt
mk polish   work/a/subs.srt --out work/a/polished.srt
mk voices
mk dub      a.mp4 --srt work/a/subs.srt --out work/dub.mp4 --voice Huihui --mix-original

# cut
mk edit     work/plan.json --out work/final.mp4
mk auto     --music bgm.mp3 --src footage --out work/mv.mp4 --transition fade
```

Every command accepts `--json`. Without it you get a short human summary.

### `mk auto` — beat-synced montage

Analyzes the track, decides how many beats per cut per section (quiet sections
get longer cuts, loud ones shorter), picks shots from a folder, snaps cuts to
beats and renders `xfade` transitions with matching `acrossfade` audio.

```bash
mk auto --music bgm.mp3 --src footage --out mv.mp4 \
        --size 1080x1920 --fit crop --transition fade --seed 7
mk auto --music bgm.mp3 --src footage --out mv.mp4 --plan-only   # plan only
```

## MCP server

```json
{
  "mcpServers": {
    "mediakit": { "command": "mediakit-mcp" }
  }
}
```

12 tools: `probe`, `shots`, `music`, `subs`, `ocr`, `shotcard`, `index`,
`search`, `lyrics`, `dub`, `edit`, `auto`.

## Measured, not assumed

Numbers below were produced on a local machine (CPU) with the benchmark
scripts in `tools/`. They are small-sample results, not leaderboard claims.

| Area | Result |
|---|---|
| Shot detection | 3 hard cuts detected at exactly 4.00s / 8.00s |
| Subtitles | 16.5s Chinese speech → 9 lines, traditional→simplified, width capped |
| Karaoke | `\kf` per word; at 0.2s 65% of subtitle pixels still unsung color |
| OCR | read burned subtitles back as 「大家晚上好。」and merged into SRT |
| Retrieval (synthetic, 8 segments) | recall@1 75% descriptive / 88% short, recall@3 100% |
| Retrieval (real footage, 8 clips) | recall@1 75%, recall@3 100% |
| Lyric CER vs reference subs | mix 89.7% → vocals 60.3% (small) → **54.4% (medium)** |
| Tempo correction | librosa default 103.36 BPM was a 4:3 artifact; tempogram prior → 80.75 BPM |
| Montage | 7 segments from a 20s track; 18.50s with 6×0.25s fades |
| Audio crossfade | 3×2s clips + 0.25s fade + keep_audio → 5.50s, audio kept |
| Dubbing | 9 lines → 18.60s output, full length, 2ch/48kHz |

## Known limits

- Retrieval benchmarks are small (8 segments/clips) and CLIP is
  phrasing-sensitive; low-information frames (pure white/black) fail.
- Singing transcription is still hard: 54% CER is the good case.
- `dub` uses Windows SAPI — robotic, and long lines are time-compressed at most 2×.
- VLM shot descriptions were validated on a handful of frames.
- `beat_this` and librosa often disagree by a few BPM; the package now anchors
  tempo with a tempogram prior but does not prove which tracker is musically right.
- Transition handling assumes hard cuts when detecting shots.

## Layout

```
mediakit_cli/        package (17 modules + MCP server)
tools/           benchmarks: retrieval, lyrics CER, tempo
docs/            architecture and data contracts
examples/        sample edit plan
tests/           unit tests for pure logic
```

## Publishing

Releases go to PyPI from GitHub Actions with **Trusted Publishing** — no API
token is stored anywhere.

One-time setup on PyPI (project → Publishing → Add a publisher):

| Field | Value |
|---|---|
| Owner | `Lee2277-t` |
| Repository | `mediakit` |
| Workflow | `publish.yml` |
| Environment | `pypi` |

Then publish by pushing a tag that matches `pyproject.toml`:

```bash
git tag v0.1.4
git push origin v0.1.4
```

The workflow refuses to publish if the tag and the package version disagree.

## License

MIT
