Editing Plans
VideoEdit represents a complete multi-segment editing plan:
- Extract one or more segments from source videos
- Apply per-segment transforms, then effects
- Concatenate processed segments
- Apply post-assembly transforms, then effects
This is the recommended API for JSON/LLM-generated editing plans.
At a Glance
- Use
segments[*].transformsfor transforms andsegments[*].effectsfor effects - Use
post_transformsfor transforms after concatenation - Use
post_effectsfor effects after concatenation (notpost_transforms) - Validate first with
edit.validate()beforeedit.run()when plans are generated dynamically
Quick Start
from videopython.editing import VideoEdit
plan = {
"segments": [
{
"source": "input.mp4",
"start": 5.0,
"end": 12.0,
"transforms": [
{"op": "crop", "args": {"width": 0.5, "height": 1.0, "mode": "center"}},
{"op": "resize", "args": {"width": 1080, "height": 1920}},
],
"effects": [
{"op": "blur", "args": {"mode": "constant", "iterations": 1}, "apply": {"start": 0.0, "stop": 1.0}}
],
},
{
"source": "input.mp4",
"start": 20.0,
"end": 28.0,
},
],
"post_effects": [
{"op": "color_adjust", "args": {"brightness": 0.05}}
],
}
edit = VideoEdit.from_dict(plan)
# Dry-run validation using VideoMetadata (no frame loading)
predicted = edit.validate()
print(predicted)
video = edit.run()
video.save("output.mp4")
# Or stream directly to file (constant memory, any video length):
edit.run_to_file("output.mp4", crf=20, preset="medium")
Streaming Mode (run_to_file)
run_to_file() streams frames one at a time from ffmpeg decode through per-frame effect processing to ffmpeg encode. Memory usage is constant (~250 MB) regardless of video length.
edit = VideoEdit.from_dict(plan)
edit.run_to_file("output.mp4", format="mp4", preset="medium", crf=20)
When all operations in the plan are streamable, frames are never fully loaded into memory. If any operation is not streamable, it falls back to the eager path (run() + save()) automatically.
Streamable operations (check x-streamable in json_schema() output):
- Transforms:
resize,crop,resample_fps - Effects:
color_adjust,blur_effect,zoom_effect,vignette,ken_burns,fade,full_image_overlay,text_overlay,volume_adjust
Non-streamable (triggers eager fallback):
- Transforms:
cut,cut_frames,speed_change,reverse,freeze_frame,picture_in_picture,silence_removal - Post-transforms on multi-segment plans
Use run() + save() when you need to inspect or modify the result in Python. Use run_to_file() for production pipelines processing long videos.
JSON Plan Format
Top-level shape:
{
"segments": [
{
"source": "path/to/video.mp4",
"start": 5.0,
"end": 15.0,
"transforms": [
{"op": "crop", "args": {"width": 1080, "height": 1920}}
],
"effects": [
{"op": "blur_effect", "args": {"mode": "constant", "iterations": 2}, "apply": {"start": 0.0, "stop": 3.0}}
]
}
],
"post_transforms": [
{"op": "resize", "args": {"width": 1080, "height": 1920}}
],
"post_effects": [
{"op": "color_adjust", "args": {"brightness": 0.05}}
]
}
Notes:
segmentsis required and must be non-empty.post_transformsandpost_effectsare optional.post_transformsaccepts only transform operations.post_effectsaccepts only effect operations.- Segment keys are strict (
source,start,end,transforms,effects). - Step keys are strict:
- transform step:
op, optionalargs - effect step:
op, optionalargs, optionalapply - Unknown top-level keys are ignored for forward compatibility.
Context Data
Some operations need side-channel data that shouldn't be part of the JSON plan (e.g. transcription for silence_removal). Pass it via the context parameter:
from videopython.editing import VideoEdit
edit = VideoEdit.from_dict(plan)
video = edit.run(context={"transcription": my_transcription})
Operations whose registry spec has the requires_transcript tag automatically receive context["transcription"] as a keyword argument. Other operations are unaffected.
Pipeline Order (Enforced)
VideoEdit always runs operations in this order:
- Per segment:
- transforms (in order)
- effects (in order)
- After concatenation:
- post transforms (in order)
- post effects (in order)
Callers do not control transform/effect interleaving. The model enforces this discipline.
Effect Time Semantics
- Segment effect
apply.start/apply.stopare relative to the segment timeline (segment starts at0). - Post effect
apply.start/apply.stopare relative to the assembled output timeline.
Validation and Compatibility Checks
VideoEdit.validate() performs a dry run using VideoMetadata:
- segment time bounds (
start,end) - transform metadata prediction (for transforms with registered
metadata_method) - effect time bounds
- concatenation compatibility (exact
fps, exact dimensions)
Validation returns the predicted final VideoMetadata on success and raises ValueError on invalid plans.
Validation behavior notes:
cutmetadata prediction mirrors runtime rounded frame slicing semantics (fractional seconds are rounded to frames).cropmetadata prediction mirrors runtime crop slicing behavior, including odd-size center crops and edge clipping.
JSON Parsing Behavior
Alias normalization
Input aliases are accepted (for example blur), but:
VideoEdit.to_dict()emits canonical operation IDs (for exampleblur_effect)VideoEdit.json_schema()lists canonical operation IDs only
Common parser constraints
resizerequires at least one non-null dimension (widthorheight)- valid:
{"op": "resize", "args": {"width": 320}} - valid:
{"op": "resize", "args": {"height": 180}} - invalid:
{"op": "resize"} - invalid:
{"op": "resize", "args": {"width": null, "height": null}}
Unsupported operations in JSON plans
The parser rejects operations that are not supported in VideoEdit JSON plans, including:
- transitions (
fade_transition,blur_transition, ...) - multi-source operations (
picture_in_picture,split_screen, ...) - registered operations that are not JSON-instantiable because required constructor args are excluded from registry specs (for example
ken_burns,full_image_overlay)
AI operations and lazy registration
AI operation specs are registered only after importing videopython.ai.
If a plan references AI ops (for example face_crop), import AI first:
import videopython.ai # registers AI ops
from videopython.editing import VideoEdit
edit = VideoEdit.from_dict(plan)
videopython.base does not auto-import AI modules.
Schema Generation (json_schema)
Use VideoEdit.json_schema() to get a parser-aligned JSON Schema for the current registry state. The schema is designed to be passed directly to LLM APIs as a tool definition or structured-output format.
from videopython.editing import VideoEdit
schema = VideoEdit.json_schema()
print(schema["properties"]["segments"]["minItems"]) # 1
Using the schema with LLMs
The schema encodes all structural rules - valid operation IDs, required fields, parameter types, and value constraints - so the LLM does not need to learn them from examples:
from videopython.editing import VideoEdit
schema = VideoEdit.json_schema()
# Pass as a tool/function schema to any LLM API:
# - OpenAI: tools=[{"type": "function", "function": {"parameters": schema}}]
# - Anthropic: tools=[{"input_schema": schema}]
# - Any structured-output API that accepts JSON Schema
For complete examples with OpenAI and Anthropic APIs, see the LLM Integration Guide.
Schema properties
- Built dynamically from the operation registry
- Canonical op IDs only (aliases omitted)
- Excludes unsupported categories/tags/non-JSON-instantiable ops
- Reflects current registration state (AI ops appear only if
videopython.aiwas imported) - Encodes parser-aligned constraints (for example
resizerequires at least one non-null dimension) - Includes rich value constraints (
minimum,maximum,exclusive_minimum,enum) for all parameters - Operations compatible with
run_to_file()streaming are marked with"x-streamable": true
Serialization (to_dict)
VideoEdit.to_dict() returns a canonical JSON-ready dict:
- canonical op IDs
- deep-copied step args / apply args
- stable output even if live operation instances are mutated after parsing
Multicam Editing (MultiCamEdit)
MultiCamEdit is for podcast-style multicam recordings: switch between synchronized
camera angles at specified cut points with transitions, and replace audio with an
external track.
Quick Start
from videopython.editing import MultiCamEdit, CutPoint
from videopython.base import FadeTransition
edit = MultiCamEdit(
sources={
"wide": "cam1.mp4",
"closeup1": "cam2.mp4",
"closeup2": "cam3.mp4",
},
audio_source="podcast_audio.aac",
cuts=[
CutPoint(time=0.0, camera="wide"),
CutPoint(time=15.0, camera="closeup1", transition=FadeTransition(0.5)),
CutPoint(time=45.0, camera="wide", transition=FadeTransition(0.5)),
CutPoint(time=60.0, camera="closeup2"),
],
)
video = edit.run()
video.save("podcast.mp4")
Data Model
sources: Named camera angles asdict[str, Path].cuts: Ordered list ofCutPoints. First cut must start attime=0.0. Each segment runs from itstimeuntil the next cut'stime(last segment runs to end of source).audio_source: Optional external audio file. IfNone, output is silent. Camera mic audio is always discarded.default_transition: Transition used between cuts when aCutPointhas no explicittransition. Defaults toInstantTransition(hard cut).
Requirements
- All sources must have identical fps and resolution.
- All sources must be synchronized (same start time and duration).
- Cuts must be in strictly ascending order.
Validation
Validate the plan and predict output metadata without loading video frames:
Validation accounts for duration consumed by fade/blur transitions.
JSON Schema
Use MultiCamEdit.json_schema() to get a JSON Schema describing valid plans. Pass it to an LLM API as a tool definition or structured-output format:
JSON Serialization
# Serialize
data = edit.to_dict()
# Deserialize
edit = MultiCamEdit.from_dict(data)
edit = MultiCamEdit.from_json('{"sources": {...}, "cuts": [...]}')
Premiere XML Export
Export a MultiCamEdit plan to FCP7 XML (xmeml) for direct import into
Adobe Premiere Pro:
from videopython.editing import MultiCamEdit, CutPoint, to_premiere_xml
edit = MultiCamEdit(
sources={"wide": "cam1.mp4", "closeup": "cam2.mp4"},
audio_source="podcast_audio.aac",
cuts=[
CutPoint(time=0.0, camera="wide"),
CutPoint(time=15.0, camera="closeup"),
CutPoint(time=45.0, camera="wide"),
],
)
xml = to_premiere_xml(edit)
Path("project.xml").write_text(xml)
Import in Premiere via File > Import and select the .xml file.
What gets exported
- Each cut becomes a
<clipitem>on the video track, directly referencing its source file. Source offsets are baked into thein/outpoints. - External audio becomes a single continuous clip on stereo audio tracks.
FadeTransitionbecomes a Cross Dissolve<transitionitem>on the video track.InstantTransitionis a hard cut (no transition element).
Known limitations
BlurTransitionhas no xmeml equivalent and is exported as a hard cut.- File paths are absolute
file://localhost/URLs. Not portable across machines without relinking media in Premiere. - Audio tracks assume stereo (2 channels).
API Reference
VideoEdit
VideoEdit
Represents a complete multi-segment video editing plan.
Source code in src/videopython/editing/video_edit.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 | |
to_dict
Serialize to canonical JSON-compatible dict.
Serialization uses _StepRecord snapshots as the source of truth. Mutating
live operation objects after parsing/construction does not affect output.
Source code in src/videopython/editing/video_edit.py
json_schema
classmethod
Return a JSON Schema for VideoEdit plans.
Source code in src/videopython/editing/video_edit.py
run
Execute the editing plan and return the final video.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
dict[str, Any] | None
|
Optional side-channel data for context-dependent operations.
Operations whose registry spec has a |
None
|
Source code in src/videopython/editing/video_edit.py
run_to_file
run_to_file(
output_path: str | Path,
format: ALLOWED_VIDEO_FORMATS = "mp4",
preset: ALLOWED_VIDEO_PRESETS = "medium",
crf: int = 23,
context: dict[str, Any] | None = None,
) -> Path
Execute the editing plan, streaming directly to a file.
Memory usage is O(1) w.r.t. video length for fully streamable pipelines. Falls back to eager mode (run + save) for non-streamable operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
|
str | Path
|
Destination file path. |
required |
format
|
ALLOWED_VIDEO_FORMATS
|
Output container format. |
'mp4'
|
preset
|
ALLOWED_VIDEO_PRESETS
|
x264 encoding preset. |
'medium'
|
crf
|
int
|
Constant rate factor (quality). |
23
|
context
|
dict[str, Any] | None
|
Optional side-channel data for context-dependent operations. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the output file. |
Source code in src/videopython/editing/video_edit.py
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
validate
Validate the editing plan without loading video data.
Requires source video files to be present on disk (uses VideoMetadata.from_path).
For validation without file access, use :meth:validate_with_metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
dict[str, Any] | None
|
Optional side-channel data for context-dependent operations.
Operations whose registry spec has a |
None
|
Source code in src/videopython/editing/video_edit.py
validate_with_metadata
validate_with_metadata(
source_metadata: VideoMetadata
| dict[str, VideoMetadata],
context: dict[str, Any] | None = None,
) -> VideoMetadata
Validate the editing plan using pre-built metadata instead of loading from file.
Same validation as validate() but accepts a VideoMetadata directly, avoiding the need for the source video file to be on disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_metadata
|
VideoMetadata | dict[str, VideoMetadata]
|
VideoMetadata for the source video (duration, dimensions, fps). For multi-source plans, pass a dict mapping source paths to their metadata. |
required |
context
|
dict[str, Any] | None
|
Optional side-channel data for context-dependent operations.
Operations whose registry spec has a |
None
|
Returns:
| Type | Description |
|---|---|
VideoMetadata
|
Predicted output VideoMetadata after all operations. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any validation check fails. |
Source code in src/videopython/editing/video_edit.py
SegmentConfig
SegmentConfig is still exported, but most users should construct plans via VideoEdit.from_dict(...) or VideoEdit.from_json(...).
SegmentConfig
dataclass
Configuration for a single video segment in an editing plan.
Source code in src/videopython/editing/video_edit.py
load_segment
load_segment(
fps: float | None = None,
width: int | None = None,
height: int | None = None,
) -> Video
Load the raw segment from disk (cut only, no transforms or effects).
Optional fps/width/height are applied during decoding via ffmpeg filters.
Source code in src/videopython/editing/video_edit.py
apply_operations
Apply per-segment transforms and effects to a loaded video.
Source code in src/videopython/editing/video_edit.py
process_segment
Load the segment and apply transforms then effects.
MultiCamEdit
MultiCamEdit
Multicam timeline editor for podcast-style recordings.
Switches between synchronized camera angles at specified cut points, joining segments with transitions and replacing audio with an external track (or silence).
Source code in src/videopython/editing/multicam.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 | |
source_duration
property
Timeline duration in seconds (minimum across all sources).
source_metas
property
Per-camera metadata keyed by source name.
run
Execute the multicam edit and return the final video.
Source code in src/videopython/editing/multicam.py
validate
Validate the plan and predict output metadata without loading frames.
Source code in src/videopython/editing/multicam.py
json_schema
classmethod
Return a JSON Schema for MultiCamEdit plans.
Source code in src/videopython/editing/multicam.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
to_dict
Serialize to a JSON-compatible dict.
Source code in src/videopython/editing/multicam.py
from_dict
classmethod
Deserialize from a dict.
Source code in src/videopython/editing/multicam.py
from_json
classmethod
Deserialize from a JSON string.
Source code in src/videopython/editing/multicam.py
CutPoint
CutPoint
dataclass
A camera switch point in a multicam timeline.
Attributes:
| Name | Type | Description |
|---|---|---|
time |
float
|
Seconds into the timeline where this cut happens. |
camera |
str
|
Key into the MultiCamEdit.sources dict. |
transition |
Transition | None
|
Transition to use when switching to this camera. None means use the MultiCamEdit.default_transition. |