Skip to main content

English 简体中文

🎬 Movie Narrator

Python License CI PyPI Downloads

One Prompt → One Narrated Movie Video

Movie Narrator is an open-source toolkit that automatically generates movie recap videos with narration, subtitles, and rendered output from a simple command.


Features

  • 🎬 Generate movie recap scripts with LLMs
  • 🔊 Text-to-Speech narration (Edge-TTS by default)
  • 💬 Automatic SRT subtitle generation
  • 🌐 Multi-language subtitles (--subtitle-lang en translates narration cues via LLM and writes subtitle.<lang>.srt + subtitle.bilingual.srt)
  • 🖥️ Web UI — provided by the separate movie-narrator-web package (FastAPI + React browser app with form inputs, cooperative cancel, artifact download, and real-time progress via WebSocket)
  • 🎞️ Video rendering with MoviePy and FFmpeg
  • 📝 Script markdown export (script.md)
  • 🎵 Background music integration (BGM)
  • 🎬 Scene-level clip export
  • 📦 Metadata export
  • 🔌 Extensible pipeline architecture
  • 🐍 Pure Python implementation

Installation

Requirements

  • Python 3.10+
  • FFmpeg

Install FFmpeg

macOS

brew install ffmpeg

Ubuntu / Debian

sudo apt install ffmpeg

Windows

# Option 1: winget
winget install Gyan.FFmpeg

# Option 2: chocolatey
choco install ffmpeg

# Option 3: Manual download from https://ffmpeg.org/

Verify installation:

ffmpeg -version

Install Movie Narrator

From PyPI

pip install movie-narrator

From Source

git clone https://github.com/zcbacxc/movie-narrator.git
cd movie-narrator
pip install -e .

Optional extras

# Scene detection (PySceneDetect)
pip install "movie-narrator[media]"

# WhisperX + semantic search (requires PyTorch; Python < 3.14)
pip install "movie-narrator[ml]"

# Web UI (FastAPI + React) — separate package
pip install movie-narrator-web

# Everything
pip install "movie-narrator[full]"

Note on Python 3.14+: The [ml] extra (WhisperX + sentence-transformers) is currently gated to Python < 3.14 due to upstream dependency wheel availability. On Python 3.14+, pip install "movie-narrator[full]" will install all other extras and silently skip the ML components. The align and match pipeline steps will soft-degrade (see Soft steps) instead of failing.

For development:

pip install -e ".[dev]"

Quick Start

Prerequisites

  • LLM: Default uses local Ollama (ollama serve to start). Or configure remote LLM via .env file.
  • FFmpeg: Required for video rendering.

Basic Usage

# Generate a narrated movie video
mn create --movie "飞驰人生" --style "热血搞笑" --duration 60

# With custom voice and format
mn create --movie "飞驰人生" --voice "zh-CN-XiaoxiaoNeural" --format "9:16"

# Keep TTS cache for debugging
mn create --movie "飞驰人生" --keep-cache

CLI Options

# Basic usage
mn create --movie "飞驰人生" --style "热血搞笑" --duration 60

All 18 CLI flags are documented in examples/cli-usage.sh with usage examples for every scenario: basic, video/library, research/BGM/clips, multi-language subtitles, narration presets, and YAML config. Key flags: --movie/-m, --style/-s, --duration/-d, --voice/-v, --format/-f, --video, --library-dir, --research, --bgm, --no-bgm, --no-clips, --strict, --keep-cache, --retry, --subtitle-lang, --subtitle-mode, --narration-preset/-p, --config.

Job YAML config

# Drive a job from YAML (movie may live only in the file)
mn create --config examples/job.example.yaml

# CLI flags still win over YAML
mn create --config examples/job.example.yaml --movie "OtherTitle" --no-clips

When --config is not passed, the CLI auto-discovers a YAML config in priority order:

  1. cwd/job.yaml (project-level user config)
  2. Packaged examples/job.example.yaml (sensible defaults for new users)
  3. None (pure CLI args)

This means new users can run mn create --movie X without creating any config file — the example YAML provides default steps/params automatically.

See examples/job.example.yaml for the full whitelist: soft-step toggles under steps: (research, align, scene, match, bgm, export, translate), all 52 params: keys (scene detection, match, BGM, TTS pacing, translate, research, WhisperX, render, async, video sizes), and the multi-language subtitle top-level keys subtitle_lang / subtitle_mode. Relative video / bgm / library_dir paths resolve against the YAML file's directory. LLM credentials stay in .env / MN_* only.

Multi-language subtitles

# Translate narration cues to English and overlay them on the video
mn create --movie "Inception" --subtitle-lang en --subtitle-mode bilingual

# Or just write the translated SRT files (no on-screen change)
mn create --movie "Inception" --subtitle-lang en

When --subtitle-lang is set, generate_subtitle always writes three SRT files:

  • subtitle.srt — original narration (always present, subtitle_path invariant)
  • subtitle.<lang>.srt — translated (e.g. subtitle.en.srt)
  • subtitle.bilingual.srt — cue body f"{original}\n{translation}" (LF between lines)

--subtitle-mode chooses which file render_video reads:

Mode Overlay text source
original (default) subtitle.srt
translated subtitle.<lang>.srt (falls back to subtitle.srt with a warn if missing)
bilingual subtitle.bilingual.srt (same fallback)

Setting subtitle_mode=translated|bilingual without subtitle_lang raises JobConfigError at merge time. Failure policy: LLM retries MN_TRANSLATE_RETRIES times, then soft-degrades to filling the translation track with the original text and surfacing a warning.

Web UI

The Web UI is now a separate package. Install and launch it with:

# Install the standalone Web UI package
pip install movie-narrator-web

# Launch local browser app (default: http://127.0.0.1:8760)
mn-web

For full usage details (custom host/port, production build, development mode, form fields, and artifact download), see the movie-narrator-web repository.

Offline Demo (No LLM Required)

# CI=1 uses silent audio fallback, bypasses LLM and Edge-TTS
CI=1 mn create --movie "Demo" --duration 10

Other Commands

mn version   # Show version
mn --help    # Show help

Configuration

All settings use the MN_ prefix to avoid conflicts with other tools.

Via .env file (recommended)

~/.movie-narrator/.env is auto-created with default values on first run — edit it to configure LLM, TTS, and other settings. This file lives outside the package, so pip install/upgrade/uninstall never touches it. You can also create a project-level .env in your working directory for per-project overrides.

MN_LLM_BASE_URL=http://localhost:11434/v1
MN_LLM_API_KEY=ollama
MN_LLM_MODEL=qwen2.5:7b
MN_DEFAULT_VOICE=zh-CN-YunxiNeural

Via environment variables

# PowerShell
$env:MN_LLM_BASE_URL="http://localhost:11434/v1"
$env:MN_LLM_MODEL="qwen2.5:7b"
mn create --movie "飞驰人生" --duration 60
# Linux / macOS
export MN_LLM_BASE_URL=http://localhost:11434/v1
export MN_LLM_MODEL=qwen2.5:7b
mn create --movie "飞驰人生" --duration 60

Config lookup order

Priority Location Notes
1 Environment variables (MN_*) Highest
2 当前目录/.env Project-level
3 ~/.movie-narrator/.env User-level, never lost on pip install/upgrade/uninstall
4 Built-in defaults Local Ollama

Full reference

See .env.example for the complete list of all 24 environment variables (LLM + TTS infrastructure only). All pipeline behavior is configured via examples/job.example.yaml — 48 params keys covering scene detection, match, render, translate, BGM, WhisperX, async, and video sizes.

LLM Provider Guides

Movie Narrator works with any OpenAI-compatible LLM. New user? Check out the LLM Provider Guides for step-by-step registration and free-tier setup:

Provider Free Tier Best For
Ollama Completely free (local) Privacy, offline use
Zhipu (GLM) glm-4-flash unlimited free Zero-cost, no GPU
Alibaba Bailian 1M tokens per model Qwen flagship models
Xiaomi MiMo Limited-time free + ¥10 invite bonus LLM + TTS in one platform
SiliconFlow Free models + voucher credits Multi-model switching

Output

output/
└── 飞驰人生/
    ├── narration.mp3       # TTS narration audio
    ├── mixed.mp3            # Narration + BGM mix (when BGM enabled)
    ├── subtitle.srt
    ├── subtitle.<lang>.srt    # (when --subtitle-lang set; e.g. subtitle.en.srt)
    ├── subtitle.bilingual.srt # (when --subtitle-lang set; original + LF + translation per cue)
    ├── script.md
    ├── research.json        # (when --research)
    ├── matches.json         # (when video provided)
    ├── metadata.json
    ├── final.mp4
    └── clips/               # (when --no-clips not set)
File Description
narration.mp3 AI-generated narration audio
mixed.mp3 Narration + BGM overlay (when BGM enabled; otherwise narration.mp3 used directly)
subtitle.srt Synchronized subtitle file (original narration)
subtitle.<lang>.srt Translated subtitle (when --subtitle-lang set)
subtitle.bilingual.srt Bilingual subtitle (when --subtitle-lang set; cue body f"{src}\n{dst}")
script.md Human-readable script
research.json Movie research data (when --research)
metadata.json Segment timings, pipeline status, config
final.mp4 Rendered video (16:9 or 9:16)
matches.json Scene-to-segment clip matching (when video provided)
clips/ Per-segment clip .mp4 files (when --no-clips not set)

Pipeline

15-step sequential pipeline (see Architecture):

resolve_video → prepare_assets → research_plot → generate_script →
export_script_md → generate_voice → align_audio → detect_scenes →
match_clips → mix_bgm → translate_subtitles → generate_subtitle →
render_video → validate_deliverable → export_clips

Soft steps (research, align, scene detect, scene match, BGM, translate, clip export) gracefully skip or soft-degrade when optional dependencies are missing or upstream data is unavailable. Use --strict to abort instead.


Project Structure

movie-narrator/
├── src/movie_narrator/
│   ├── __init__.py          # Package metadata (__version__)
│   ├── cli.py               # Typer CLI entry point
│   ├── config.py            # Pydantic settings
│   ├── models.py            # Data models (Context, Status, etc.)
│   ├── pipeline/
│   │   ├── runner.py        # 15-step pipeline orchestrator
│   │   ├── resolve.py       # Source video resolution
│   │   ├── assets.py        # Asset validation
│   │   ├── research.py      # LLM movie research
│   │   ├── script.py        # LLM script generation
│   │   ├── script_export.py # Script markdown export
│   │   ├── tts.py           # TTS orchestration (uses tts/ package; caching + concurrency)
│   │   ├── align.py         # WhisperX audio alignment
│   │   ├── scenes.py        # PySceneDetect scene detection
│   │   ├── match.py         # Heuristic clip matching
│   │   ├── bgm.py           # Background music mixing
│   │   ├── translate.py     # Multi-language subtitle translation (LLM)
│   │   ├── subtitle.py      # SRT generation (single / translated / bilingual)
│   │   ├── render.py        # MoviePy 2.x video rendering
│   │   ├── qa.py            # Post-render deliverable QA (hard step)
│   │   ├── export_clips.py  # Per-segment clip export (direct ffmpeg)
│   │   ├── preflight.py     # Pre-run LLM/TTS validation (fail-fast)
│   │   └── errors.py        # PipelineStrictError, PipelineCancelled, RunController, StepAction
│   ├── workflow/
│   │   ├── schema.py        # JobConfig / JobSteps / JobParams
│   │   ├── load.py          # YAML loader + validation
│   │   ├── merge.py         # CLI > YAML > Settings merge
│   │   └── errors.py        # JobConfigError
│   ├── tts/                     # TTS abstraction layer
│   │   ├── __init__.py          # re-exports public API
│   │   ├── protocol.py          # TTSProvider ABC
│   │   ├── base.py              # BaseTTSProvider (CI silent fallback), is_ci()
│   │   ├── edge.py              # EdgeTTSProvider
│   │   ├── openai_provider.py   # OpenAITTSProvider (voice whitelist, lazy SDK)
│   │   ├── mimo_provider.py     # MimoTTSProvider (3 models: named voice, voice clone, voice design)
│   │   ├── factory.py           # get_tts_provider(settings)
│   │   └── cache.py             # TTSCacheKey, cache_path_for, PROVIDER_CACHE_VERSIONS
│   ├── utils/
│   │   ├── async_utils.py   # Sync/async bridge
│   │   ├── console.py       # Console Protocol + PlainConsole + build_console
│   │   ├── environment.py   # Environment collection
│   │   ├── errors.py        # ConfigError (cross-cutting config-error class)
│   │   ├── font.py          # CJK font fallback
│   │   ├── json_parser.py   # LLM JSON extraction (with truncation recovery)
│   │   ├── llm.py           # OpenAI client wrapper
│   │   ├── log.py           # AppLogger (file logging layer)
│   │   ├── metadata_export.py # metadata.json builder
│   │   ├── optional_deps.py # Optional dependency probing
│   │   ├── prompts.py       # Prompt templates
│   │   ├── retention.py     # Log file retention
│   │   ├── audio_mix.py     # Audio normalize + BGM ducking (pydub)
│   │   ├── deliverable_qa.py # ffprobe/ffmpeg media probing + QA rules
│   │   └── video_layout.py  # Cover/contain crop+resize geometry
├── tests/
│   ├── test_context.py
│   ├── test_settings.py
│   ├── test_errors.py
│   ├── test_align.py
│   ├── test_assets.py
│   ├── test_bgm.py
│   ├── test_cli_config.py
│   ├── test_cli_resolve.py
│   ├── test_match.py
│   ├── test_optional_deps.py
│   ├── test_render_real.py
│   ├── test_research.py
│   ├── test_resolve.py
│   ├── test_runner_strict.py
│   ├── test_runner_workflow_metadata.py
│   ├── test_scenes.py
│   ├── test_script_export.py
│   ├── test_translate.py
│   ├── test_json_parser.py
│   ├── test_pipeline_cancel.py
│   ├── test_workflow_steps.py
│   ├── test_audio_mix.py
│   ├── test_deliverable_qa.py
│   ├── test_qa.py
│   ├── test_text_image.py
│   └── test_video_layout.py
├── docs/
├── assets/
└── .github/workflows/

Roadmap

v0.1.x — Core Pipeline ✅

  • CLI interface (mn create, mn version)
  • LLM script generation with JSON output
  • Edge-TTS narration with concurrent generation
  • SRT subtitle generation with millisecond precision
  • MoviePy video rendering (16:9 / 9:16)
  • TTS result caching with content-addressable keys
  • Metadata export (JSON)
  • CI pipeline (unit tests + smoke test)

v0.2.x — Scene & Media ✅

  • Research agent for movie plot research (--research)
  • WhisperX audio-text alignment
  • Scene detection from movie videos
  • Automatic clip matching based on script
  • Semantic scene search (embedding-based, requires [ml])
  • Background music integration (BGM mixing)
  • Script markdown export (script.md)
  • Scene-level clip output (clips/)

v0.3.x — Platform & Workflow ✅

  • Declarative workflow config for soft-step toggles + params
  • YAML-based job configuration (mn create --config)
  • Console / structured-step-state logging refactor (ctx.services.console, StepState)
  • Multi-language subtitle support (--subtitle-lang / --subtitle-mode; LLM translation with retry-then-soft-degrade; subtitle.<lang>.srt + subtitle.bilingual.srt outputs)
  • Web UI (Gradio local browser app via mn web; cooperative cancel; requires [web] extra) (v0.4.10: refactored to FastAPI + React; later split into independent repo movie-narrator-web)

v0.4.x — TTS Abstraction & Infrastructure ✅

  • Web UI rewrite: Gradio → FastAPI + React 18 + WebSocket (v0.4.10; later split into independent repo movie-narrator-web)
  • TTS provider abstraction (TTSProvider protocol, Edge + OpenAI + MiMo backends)
  • Provider selection via MN_TTS_PROVIDER (edge / openai / mimo)
  • OpenAI TTS support (voice whitelist, credential fallback, lazy SDK import)
  • MiMo TTS support (3 models: named voice, voice clone, voice design; limited-time free)
  • Cache key upgrade (sha256, 7 dimensions, two-level fan-out, per-provider version map)
  • CI temp-file isolation (silent audio never enters cache)
  • is_ci() single source of truth for CI detection
  • ConfigError cross-cutting error class
  • MoviePy 1.x → 2.x upgrade (Python 3.13+ compatibility)
  • Preflight LLM/TTS validation before pipeline execution
  • Step-level retry mechanism (--retry flag, StepAction enum)
  • Auto-create ~/.movie-narrator/.env on first run
  • export_clips direct ffmpeg subprocess (design choice, not workaround)
  • Config system overhaul: strict env/yaml boundary — .env (Settings) contains 21 LLM + TTS infrastructure fields only; job.yaml (params) contains all 32 pipeline behavior keys; YAML auto-discovery (--config not passed → cwd/job.yaml → packaged example); .env.example and job.example.yaml are the single sources of truth; no code constants module — inline literals match example files

v0.5.x — Ecosystem

Goal: Freeze the public API surface (Pipeline, Workflow, Plugin, SDK) before Cloud features depend on it.

  • Plugin API — StepRegistry + ProviderRegistry with @register_step / @register_provider decorators (#91)
  • Python SDK — from movie_narrator import ... with stable contract.py surface (#92)
  • Plugin discovery via importlib.metadata entry points (movie_narrator.plugins group) (#92)
  • Services.logger for structured logging in plugins (#92)
  • Out-of-tree example plugin (examples/plugins/watermark/) (#92)
  • WP6 scene filtering — intro skip, dark frame detection, highlight window (#93)
  • WebUI split — movie-narrator-web standalone repo, core engine is now pure CLI (#94, #95)

SDK and Plugin API are designed together — both must stabilize in the same release.

v0.6.x — Cloud (Planned)

  • Remote inference (offload LLM / TTS / rendering to cloud workers)
  • Distributed rendering (split video segments across nodes)
  • Task queue (async job submission, progress polling, retry)
  • Web service deployment (REST API, authentication, multi-tenant)

Documentation


License

Licensed under the AGPL-3.0 License.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

movie_narrator-0.5.2.tar.gz (227.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

movie_narrator-0.5.2-py3-none-any.whl (163.2 kB view details)

Uploaded Python 3

File details

Details for the file movie_narrator-0.5.2.tar.gz.

File metadata

  • Download URL: movie_narrator-0.5.2.tar.gz
  • Upload date:
  • Size: 227.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for movie_narrator-0.5.2.tar.gz
Algorithm Hash digest
SHA256 826c3b08c535985b98e1a7ea4d00ea8871031fe3e73dfcd97728c118a714116f
MD5 5acbe532cbed50c4c0313eb596ba52c2
BLAKE2b-256 d8fb4e1433f93691578476e7dfa9ab091e1317d2b54ce88b94a04e4ff2216155

See more details on using hashes here.

Provenance

The following attestation bundles were made for movie_narrator-0.5.2.tar.gz:

Publisher: publish.yml on zcbacxc/movie-narrator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file movie_narrator-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: movie_narrator-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 163.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for movie_narrator-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0a1d260a6afc4b588aac6816dd6262f0bf602443aa8e0bfb177ae9e925dac9b0
MD5 129162971fe2a78dba8fd0369c14355f
BLAKE2b-256 78a964d0d24c3b94a35fa0081d931cbb903a8908e354f7a17f1b1cb8a9ce2eca

See more details on using hashes here.

Provenance

The following attestation bundles were made for movie_narrator-0.5.2-py3-none-any.whl:

Publisher: publish.yml on zcbacxc/movie-narrator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

1.5.2

2 files

1.5.1

2 files

1.5.0

2 files

1.4.2

2 files

1.4.1

2 files

1.4.0

2 files

1.3.2

2 files

1.3.1

2 files

1.3.0

2 files

1.2.1

2 files

1.2.0

2 files

1.1.0

2 files

1.0.0

2 files

0.9.7

2 files

0.9.6

2 files

0.9.5

2 files

0.9.4

2 files

0.9.3

2 files

0.9.2

2 files

0.9.1

2 files

0.8.4

2 files

0.8.3

2 files

0.8.2

2 files

0.8.1

2 files

0.8.0

2 files

0.7.5

2 files

0.7.4

2 files

0.7.3

2 files

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

0.6.1

2 files

0.6.0

2 files

0.5.12

2 files

0.5.11

2 files

0.5.10

2 files

0.5.9

2 files

0.5.8

2 files

0.5.7

2 files

0.5.6

2 files

0.5.5

2 files

0.5.4

2 files

0.5.3

2 files

This release

0.5.2 This release

2 files

0.5.1

2 files

0.5.0

2 files

0.4.27

2 files

0.4.26

2 files

0.4.25

2 files

0.4.24

2 files

0.4.23

2 files

0.4.22

2 files

0.4.21

2 files

0.4.20

2 files

0.4.19

2 files

0.4.18

2 files

0.4.17

2 files

0.4.16

2 files

0.4.15

2 files

0.4.14

2 files

0.4.12

2 files

0.4.11

2 files

0.4.10

2 files

0.4.9

2 files

0.4.8

2 files

0.4.7

2 files

0.4.6

2 files

0.4.5

2 files

0.4.4

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.3.5

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

0.2.7

2 files

0.2.6

2 files

0.2.5

2 files

0.2.4

2 files

0.2.3

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page