Skip to main content

Minimal video generation and processing library.

Project description

videopython

PyPI Python License

Minimal, LLM-friendly Python library for programmatic video editing, processing, and AI video workflows.

Full documentation: videopython.com

Disclaimer: This project started as a hand-written hobby project, but most of the code is now produced by LLM agents. Humans still drive direction, approve changes, and own design decisions.

Installation

1. Install FFmpeg

# macOS
brew install ffmpeg

# Ubuntu / Debian
sudo apt-get install ffmpeg

# Windows (Chocolatey)
choco install ffmpeg

2. Install videopython

pip install videopython          # core video/audio editing
pip install "videopython[ai]"    # + local AI features (GPU recommended)

Python >=3.10, <3.14. AI features run locally - no cloud API keys required, but model weights are downloaded on first use.

Quick Start

Imperative editing

Every editing primitive is an Operation subclass — a Pydantic model whose fields ARE the JSON wire format. Apply one to a Video:

from videopython.base import Video
from videopython.editing import CutSeconds, Resize, Fade

video = Video.from_path("raw.mp4")
video = CutSeconds(start=10, end=25).apply(video)
video = Resize(width=1080, height=1920).apply(video)
video = Fade(mode="in", duration=0.5).apply(video)
video.save("output.mp4")

Concatenate clips with + (must share fps + dimensions):

combined = video_a + video_b

JSON editing plans

Define multi-segment edits as JSON — the format LLM-driven workflows generate against. VideoEdit.json_schema() returns the schema:

from videopython.editing import VideoEdit

plan = {
    "segments": [{
        "source": "raw.mp4",
        "start": 10.0,
        "end": 20.0,
        "operations": [
            {"op": "resize", "width": 1080, "height": 1920},
            {"op": "color_adjust", "saturation": 1.15, "contrast": 1.05},
            {"op": "fade", "mode": "in", "duration": 0.5,
             "window": {"stop": 0.5}},
        ],
    }],
}

edit = VideoEdit.from_dict(plan)
edit.validate()                  # dry-run via metadata, no frames loaded
edit.run_to_file("output.mp4")   # stream to disk, ~constant memory

run_to_file() pipes ffmpeg decode → per-frame effects → ffmpeg encode, so memory stays bounded even for hour-long sources. Use edit.run() instead if you want the result back in memory as a Video.

AI generation

from videopython.ai import TextToImage, ImageToVideo, TextToSpeech
from videopython.editing import Resize

image = TextToImage().generate_image("A cinematic mountain sunrise")
video = ImageToVideo().generate_video(image=image)
audio = TextToSpeech().generate_audio("Welcome to videopython.")

video = Resize(width=1080, height=1920).apply(video)
video.add_audio(audio).save("ai_video.mp4")

LLM & AI Agent Integration

The library is built for LLM-driven editing. Two surfaces matter:

1. Plan schema for tool / structured-output calls. VideoEdit.json_schema() returns a JSON Schema covering segments, post_operations, and a discriminated union over every registered Operation. Drop it into any LLM API:

from videopython.editing import VideoEdit

schema = VideoEdit.json_schema()
# Anthropic: tools=[{"name": "edit", "input_schema": schema}]
# OpenAI:    tools=[{"type": "function",
#                    "function": {"name": "edit", "parameters": schema}}]

Validate the LLM's output without touching the filesystem, then run it:

edit = VideoEdit.from_dict(plan)
edit.validate()                  # catches bad ops, time ranges, fps mismatches
edit.run_to_file("output.mp4")

2. Operation discovery for agent loops. Every registered op exposes its own Pydantic schema, so an agent can introspect what's available without hardcoded lists:

from videopython.editing import Operation, OpCategory

for op_id, cls in Operation.registry().items():
    print(f"{op_id}: {(cls.__doc__ or '').splitlines()[0]}")

schema = Operation.get("color_adjust").model_json_schema()  # per-op schema

Field constraints (minimum, maximum, enum, exclusiveMinimum, nullability) flow through to the schema, so LLMs that support constrained generation produce valid parameters on the first try.

For ops that need side-channel data (e.g. silence_removal and add_subtitles need a Transcription), pass it via context:

edit.run(context={"transcription": my_transcription})

Docs: Editing Plans | Operations | LLM Integration Guide

Features

videopython.base - data containers + I/O (no AI dependencies)

Area Highlights
Video I/O Video, VideoMetadata, FrameIterator - load, save, inspect
Text rendering ImageText - generic PIL text-on-image primitive
Transcription Transcription, TranscriptionSegment, TranscriptionWord - data classes returned by transcription backends
Result types BoundingBox, DetectedFace, FaceTrack, SceneBoundary, AudioEvent, MotionInfo, ... - shared by editing and AI

videopython.audio - audio data container

Area Highlights
Audio Audio, AudioMetadata - load/save, overlay, concat, normalize, time-stretch, silence detection, segment classification

videopython.editing - editing primitives + plan runner

Area Highlights
Operation foundation Operation, Effect, TimeRange, OpCategory - Pydantic base + auto-registry + discriminated-union schema
Editing plans VideoEdit, SegmentConfig - JSON/LLM-friendly multi-segment plans with JSON Schema generation, dry-run validation, and streaming run_to_file
Transforms Cut (time/frame), resize, crop, FPS resampling, speed change, reverse, freeze frame, silence removal
Effects Blur, zoom, color grading, vignette, Ken Burns, image overlay, fade, text overlay, volume adjust
Subtitles TranscriptionOverlay - animated word-by-word subtitle rendering

API docs: Core | Video | Audio | Editing Plans | Operations | Transforms | Effects | Text

videopython.ai - local AI features (install with [ai])

Area Highlights
Generation TextToVideo, ImageToVideo, TextToImage, TextToSpeech, TextToMusic
Understanding AudioToText (transcription), AudioClassifier, SceneVLM (structured visual scene description), FaceTracker (per-shot face tracks)
Scene detection SemanticSceneDetector (neural scene boundaries)
Video analysis VideoAnalyzer - full-pipeline analysis combining multiple AI capabilities
Transforms FaceTrackingCrop
Dubbing VideoDubber - voice cloning and revoicing with timing sync

API docs: Generation | Understanding | Transforms | Dubbing

Examples

Development

See DEVELOPMENT.md for local setup, testing, and contribution workflow.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

videopython-0.33.2.tar.gz (144.4 kB view details)

Uploaded Source

Built Distribution

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

videopython-0.33.2-py3-none-any.whl (170.4 kB view details)

Uploaded Python 3

File details

Details for the file videopython-0.33.2.tar.gz.

File metadata

  • Download URL: videopython-0.33.2.tar.gz
  • Upload date:
  • Size: 144.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for videopython-0.33.2.tar.gz
Algorithm Hash digest
SHA256 855790903f9c5ff60f2e24dc8c38a9a0102ab5d9af3d7008fa1d19396bdefa4a
MD5 4008e77ee2b4fe02267bf42768f4f9c9
BLAKE2b-256 7efbbd6081404c61f095e7467d857b841648d94c2f3df52f893c8ffb14c50cd2

See more details on using hashes here.

Provenance

The following attestation bundles were made for videopython-0.33.2.tar.gz:

Publisher: publish.yml on BartWojtowicz/videopython

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

File details

Details for the file videopython-0.33.2-py3-none-any.whl.

File metadata

  • Download URL: videopython-0.33.2-py3-none-any.whl
  • Upload date:
  • Size: 170.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for videopython-0.33.2-py3-none-any.whl
Algorithm Hash digest
SHA256 134cecd108ed6cd39a0583147d67b653d29d9889a8481f6e2ca60d0c2fb85143
MD5 8ae40bc07d40a562eccaac89ed4635f5
BLAKE2b-256 a4046880f9bc03da75a3f508be272983d155077d5829974d8447d90ef23db8ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for videopython-0.33.2-py3-none-any.whl:

Publisher: publish.yml on BartWojtowicz/videopython

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

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page