Transforms
Transforms are Operation subclasses that produce a new Video from a
single input video. They may change dimensions, fps, duration, or frame
count. See Operations for the base contract.
Usage
from videopython.base import Video
from videopython.editing import Resize, Crop, CutSeconds
video = Video.from_path("input.mp4")
video = CutSeconds(start=0.0, end=10.0).apply(video)
video = Crop(width=0.5, height=0.5).apply(video) # 50% center crop
video = Resize(width=1280, height=720).apply(video)
video.save("output.mp4")
Inside a VideoEdit plan, transforms go in the operations list with
their fields inline:
plan = {
"segments": [{
"source": "input.mp4",
"start": 0,
"end": 10,
"operations": [
{"op": "crop", "width": 0.5, "height": 0.5},
{"op": "resize", "width": 1280, "height": 720},
],
}]
}
Available Transforms
| op | Class | Streamable | Notes |
|---|---|---|---|
cut_frames |
CutFrames |
no | Cut by frame range |
cut |
CutSeconds |
no | Cut by time range |
resize |
Resize |
yes | Resize, optional aspect-preserving |
resample_fps |
ResampleFPS |
yes | Change frame rate |
crop |
Crop |
yes | Pixel or normalized 0–1 fractions |
speed_change |
SpeedChange |
no | Constant or ramping speed |
reverse |
Reverse |
no | Reverse playback |
freeze_frame |
FreezeFrame |
no | Hold a frame for a duration |
silence_removal |
SilenceRemoval |
no | Requires transcription context |
Crop Coordinates
Crop accepts pixel ints or normalized 0–1 floats. Floats in (0, 1]
are treated as fractions of source dimensions; everything else is
interpreted as a pixel count.
from videopython.editing import Crop, CropMode
Crop(width=640, height=480).apply(video) # pixels
Crop(width=0.5, height=0.5).apply(video) # 50% center crop
Crop(width=0.5, height=1.0, x=0.5, y=0.0, mode=CropMode.CUSTOM).apply(video)
Context-Dependent Transforms
SilenceRemoval declares requires = ("transcription",). Inside a
VideoEdit, pass it via context; standalone, pass it directly to
apply:
edit.run(context={"transcription": my_transcription})
# or
SilenceRemoval().apply(video, transcription=my_transcription)
API Reference
CutSeconds
CutSeconds
Bases: Operation
Cuts video to a specific time range in seconds.
Source code in src/videopython/editing/transforms.py
CutFrames
CutFrames
Bases: Operation
Cuts video to a specific frame range.
Source code in src/videopython/editing/transforms.py
Resize
Resize
Bases: Operation
Resizes video to specified dimensions, preserving aspect ratio if only one dimension is given.
Source code in src/videopython/editing/transforms.py
ResampleFPS
ResampleFPS
Bases: Operation
Resamples video to a different frame rate, upsampling or downsampling as needed.
Source code in src/videopython/editing/transforms.py
Crop
Crop
Bases: Operation
Crops the frame to a smaller region.
Accepts pixel values (int) or normalized 0-1 fractions (float). For
example, width=0.5 crops to 50% of the original width.
Source code in src/videopython/editing/transforms.py
CropMode
CropMode
SpeedChange
SpeedChange
Bases: Operation
Speeds up or slows down video playback, optionally ramping between two speeds.
Source code in src/videopython/editing/transforms.py
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 | |
Reverse
Reverse
Bases: Operation
Plays the video backwards, with optional audio reversal.
Source code in src/videopython/editing/transforms.py
FreezeFrame
FreezeFrame
Bases: Operation
Pauses video at a specific moment by holding a single frame.
Source code in src/videopython/editing/transforms.py
SilenceRemoval
SilenceRemoval
Bases: Operation
Cuts or fast-forwards through silent gaps between speech.
Uses word-level transcription timestamps to identify silent sections and either removes them entirely or speeds them up.
Source code in src/videopython/editing/transforms.py
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 | |
For AI-powered transforms (face tracking, auto-framing), see AI Transforms.