Metadata-Version: 2.4
Name: opencontext-video
Version: 0.1.1
Summary: Turn video and images into evidence-linked developer context for text-only AI
Author: OpenContext contributors
License-Expression: MIT
Project-URL: Homepage, https://github.com/kylosonic/opencontext
Project-URL: Repository, https://github.com/kylosonic/opencontext
Project-URL: Issues, https://github.com/kylosonic/opencontext/issues
Keywords: video,transcription,ocr,developer-context,ai
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Multimedia :: Video
Requires-Python: >=3.13
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx
Requires-Dist: imageio-ffmpeg
Requires-Dist: pillow
Requires-Dist: pydantic
Requires-Dist: pypdfium2
Requires-Dist: python-dotenv
Provides-Extra: dev
Requires-Dist: build; extra == "dev"
Requires-Dist: mcp<3,>=2.3; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Requires-Dist: twine; extra == "dev"
Provides-Extra: agent
Requires-Dist: mcp<3,>=2.3; extra == "agent"
Provides-Extra: local
Requires-Dist: faster-whisper; extra == "local"
Requires-Dist: av<19,>=11; extra == "local"
Dynamic: license-file

# opencontext-video

The OpenContext media processing worker. It ingests uploaded videos, still
images, image sets, and PDFs, then runs the media-to-context pipeline:
extracting audio and frames, rendering PDF pages, transcribing speech when
present, applying vision and OCR, aligning results on a shared timeline, and
producing evidence-linked developer context.

The worker polls the OpenContext API, processes jobs through resumable stages,
and stores timestamped transcript, visual, and OCR evidence in the result
payload. Text claims carry stable evidence IDs and certainty labels in both
Markdown and JSON exports.

## Install

```bash
pip install opencontext-video
```

For local speech recognition:

```bash
pip install "opencontext-video[local]"
```

The `local` extra pins PyAV below 19 because Faster Whisper 1.2.1 still passes
the removed `metadata_errors` argument to `av.open()`. Remove the pin after
Faster Whisper publishes a release compatible with PyAV 19+.

## CLI

Analyze a local video without running the web app or database:

```bash
opencontext analyze video.mp4 --out context.md --json context.json
```

Still images use the same command and output contract:

```bash
opencontext analyze mockup.png --out context.md --json context.json
```

PDFs up to 30 pages use the same output contract and combine embedded text with
rendered-page vision evidence:

```bash
opencontext analyze reference.pdf --out context.md --json context.json
```

The web upload flow can submit up to 10 images as one ordered image-set job with
cross-image comparisons. CLI batch mode analyzes each file independently and
keeps collision-safe per-file outputs.

Use `--offline` to run the full extraction and export path with clearly labeled
fixture transcription and vision output:

```bash
opencontext analyze video.mp4 --offline --out context.md --json context.json
```

The CLI accepts `LOW`, `MEDIUM`, or `HIGH` via `--detail-level`, and provider
overrides via `--transcription-provider`, `--vision-provider`, and
`--text-provider`.

Analyze every supported file in a directory:

```bash
opencontext analyze ./recordings --output-dir ./context --offline
```

Batch mode writes collision-safe `<name>.md` and `<name>.json` pairs and prints
a JSON summary with success and failure counts. It continues after an invalid
input, preserves outputs that already succeeded, and exits non-zero when any
item fails. Use `--quiet` to suppress the summary.

Turn an existing result into a repository-aware implementation brief:

```bash
opencontext brief context.json --repo ../my-app \
  --task "Implement the recorded settings flow" --out implementation-brief.md
```

The brief preserves evidence IDs, detects repository languages and manifests,
and separates observed behavior from inferred or uncertain claims.

Score a context result against a ground-truth evaluation item:

```bash
opencontext evaluate context.json \
  --truth docs/evaluation/fixture-dataset.json \
  --model-name fixture --model-version 1 \
  --measurement-kind fixture-baseline --out evaluation.json
```

The report includes transcript WER/CER, OCR precision/recall/F1, and visual
keyword recall. Fixture, smoke-test, and measured runs remain separately labeled.

Check the local runtime and configured providers before submitting a job:

```bash
opencontext doctor --offline
opencontext doctor --offline --json
```

The report labels each item `OK`, `MISSING`, or `UNVERIFIED` without printing
API keys or tokens. Network checks are opt-in with `--check-network` and use a
three-second timeout. `--json` emits one document containing an overall `ok`
value and ordered checks for setup scripts and CI preflight checks.

When configuring `TRANSCRIPTION_PROVIDER=faster_whisper` as in `.env.example`,
install the `local` extra alongside `dev`:

```bash
cd workers/processor
python -m venv .venv
# Windows
.venv/Scripts/python -m pip install -e ".[dev,local]"
.venv/Scripts/python -m oc_worker.main
# macOS/Linux
.venv/bin/python -m pip install -e ".[dev,local]"
.venv/bin/python -m oc_worker.main
```

Use `--once` to claim and process at most one job, which is useful for
integration tests and cron-style deployments:

```bash
python -m oc_worker.main --once
```

Set `WORKER_API_TOKEN` to the same value used by the web app before starting
the worker. Provider settings are read from the worker process environment.

## Local providers

- `TRANSCRIPTION_PROVIDER=faster_whisper` runs speech recognition locally;
  install the `local` extra and allow the first model download.
- `TRANSCRIPTION_PROVIDER=openai_audio` sends extracted WAV audio to an
  audio-capable OpenAI-compatible chat model through the same `OPENAI_BASE_URL`
  and API-key settings used for hosted vision.
- `VISION_PROVIDER=ollama` remains available for a local Ollama server.
- `VISION_PROVIDER=openai_compatible` can call OpenCode Go with
  `OPENAI_BASE_URL=https://opencode.ai/inference/go/openai/v1`,
  `OPENCODE_API_KEY`, and an image-capable `VISION_MODEL`. Each claimed job
  receives an independent `x-opencode-session` identifier so one job cannot
  exhaust another job's session quota or share conversation state.
- `VISION_PROVIDER=gemini` uses `GEMINI_API_KEY`, an image-capable
  `VISION_MODEL`, and `GEMINI_BASE_URL` for native Gemini image analysis.
  `VISION_TIMEOUT_SECONDS` bounds the request.
- `VISION_CONCURRENCY` bounds simultaneous image analysis calls. Use `1` for
  rate-limited upstream accounts. Transient provider errors retry up to three
  times with short backoff. A longer `Retry-After` defers the whole job so the
  worker can continue with other queued work.
- `VISION_MAX_FRAMES` sets the maximum number of evenly sampled video/PDF
  frames sent to the vision provider per job (default 60). Image sets are
  already limited to 10 source images.
- `OCR_PROVIDER=tesseract` extracts text independently with the local
  Tesseract binary. `OCR_PROVIDER=vision` keeps the compatibility behavior of
  deriving OCR rows from the vision provider's `visibleText`.
- `TRANSCRIPTION_PROVIDER=fixture` and `VISION_PROVIDER=fixture` provide
  deterministic, clearly labeled output for offline tests. They do not run
  speech recognition or computer vision and should not be used to claim real
  analysis quality.

The generated-media integration tests in `tests/test_e2e_fixture.py` invoke
real FFmpeg and PDFium for probing, audio and frame extraction, still-image
conversion, image sets, and PDF page rendering, while using fixture providers
for inference.

## Real OpenCode Go vision smoke test

The hosted vision test is opt-in because it calls an external API:

```bash
export OPENCODE_API_KEY=...
export OPENAI_BASE_URL=https://opencode.ai/inference/go/openai/v1
export VISION_MODEL=hy4-flash-free
OPENCONTEXT_OPENCODE_E2E=1 pytest tests/test_opencode_vision_smoke.py -q
```

The test verifies the model catalog accepts image input, analyzes a generated
frame, and runs a synthetic checkout reference through the full image pipeline.
It requires the model to recover at least two of the expected UI/OCR labels.
This is a setup smoke test, not evidence of broad model quality.

## Real OpenCode Go audio smoke test

```bash
export OPENCODE_API_KEY=...
export OPENAI_BASE_URL=https://opencode.ai/inference/go/openai/v1
export TRANSCRIPTION_MODEL=mimo-v2.6-pro
OPENCONTEXT_OPENCODE_AUDIO_E2E=1 pytest tests/test_opencode_audio_smoke.py -q
```

This checks model-catalog audio support and transcribes the attributed Harvard
sentence recording committed under `docs/evaluation/`.

## MCP server

Install the agent extra:

```bash
pip install "opencontext-video[agent]"
opencontext-mcp
```

The stdio MCP server exposes:

- `analyze_media` — analyze a local video or image and return an evidence-linked
  brief.
- `analyze_video` and `analyze_image` — explicit compatibility entry points.
- `implementation_brief` — convert an existing context JSON result into a brief.
- `context_evidence` — return the bounded evidence ledger.

Example client configuration:

```json
{
  "mcpServers": {
    "opencontext": {
      "command": "opencontext-mcp",
      "args": []
    }
  }
}
```
