Editing Plans (VideoEdit)
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.base 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")
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.
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, split_screen), import AI first:
import videopython.ai # registers AI ops
from videopython.base 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:
from videopython.base import VideoEdit
schema = VideoEdit.json_schema()
print(schema["properties"]["segments"]["minItems"]) # 1
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)
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
API Reference
VideoEdit
VideoEdit
Represents a complete multi-segment video editing plan.
Source code in src/videopython/base/edit.py
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 | |
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/base/edit.py
json_schema
classmethod
Return a JSON Schema for VideoEdit plans.
Source code in src/videopython/base/edit.py
run
Execute the editing plan and return the final video.
Source code in src/videopython/base/edit.py
validate
Validate the editing plan without loading video data.
Source code in src/videopython/base/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/base/edit.py
process_segment
Load the segment and apply transforms then effects.