Transforms
Transformations modify video frames (cutting, resizing, resampling).
Fluent API
Chain transformations directly on Video objects:
from videopython.base import Video
# Chain multiple transformations
video = Video.from_path("input.mp4").cut(0, 10).resize(1280, 720).resample_fps(30)
# Validate operations before executing (using metadata)
output_meta = video.metadata.cut(0, 10).resize(1280, 720).resample_fps(30)
print(f"Output will be: {output_meta}")
Available Methods
| Video Method | VideoMetadata Method | Description |
|---|---|---|
video.cut(start, end) |
meta.cut(start, end) |
Cut by time range (seconds) |
video.cut_frames(start, end) |
meta.cut_frames(start, end) |
Cut by frame range |
video.resize(width, height) |
meta.resize(width, height) |
Resize dimensions |
video.crop(width, height) |
meta.crop(width, height) |
Center crop |
video.resample_fps(fps) |
meta.resample_fps(fps) |
Change frame rate |
video.transition_to(other, t) |
meta.transition_to(other, time) |
Combine videos |
video.ken_burns(start, end, easing) |
- | Pan-and-zoom effect |
video.picture_in_picture(overlay, ...) |
- | Overlay video as PiP |
Reverse().apply(video) |
- | Reverse playback order |
FreezeFrame(t, d).apply(video) |
- | Hold a frame for a duration |
SilenceRemoval().apply(video, transcription=t) |
- | Remove/speed up silent gaps |
Transformation (Base Class)
Transformation
CutSeconds
CutSeconds
Bases: Transformation
Cuts video to a specific time range in seconds.
Source code in src/videopython/base/transforms.py
__init__
Initialize time-based cutter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
float | int
|
Start time in seconds. |
required |
end
|
float | int
|
End time in seconds. |
required |
CutFrames
CutFrames
Bases: Transformation
Cuts video to a specific frame range.
Source code in src/videopython/base/transforms.py
__init__
Initialize frame cutter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
int
|
Start frame index (inclusive). |
required |
end
|
int
|
End frame index (exclusive). |
required |
Resize
Resize
Bases: Transformation
Resizes video to specified dimensions, maintaining aspect ratio if only one dimension is provided.
Source code in src/videopython/base/transforms.py
__init__
Initialize resizer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int | None
|
Target width in pixels, or None to maintain aspect ratio. |
None
|
height
|
int | None
|
Target height in pixels, or None to maintain aspect ratio. |
None
|
round_to_even
|
bool
|
If True (default), snap output width/height to even numbers. |
True
|
Source code in src/videopython/base/transforms.py
apply
Resize video frames to target dimensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
Video
|
Input video. |
required |
Returns:
| Type | Description |
|---|---|
Video
|
Resized video. |
Source code in src/videopython/base/transforms.py
ResampleFPS
ResampleFPS
Bases: Transformation
Resamples video to a different frame rate, upsampling or downsampling as needed.
Source code in src/videopython/base/transforms.py
__init__
Initialize FPS resampler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fps
|
int | float
|
Target frames per second. |
required |
apply
Resample video to target FPS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
Video
|
Input video. |
required |
Returns:
| Type | Description |
|---|---|
Video
|
Video with target frame rate. |
Source code in src/videopython/base/transforms.py
Crop
Supports both pixel values and normalized coordinates (0-1):
from videopython.base import Video, Crop, CropMode
video = Video.from_path("input.mp4")
# Pixel values - crop to exact dimensions
video.crop(640, 480)
# Normalized coordinates - crop to 50% of original size (centered)
Crop(width=0.5, height=0.5).apply(video)
# Custom position - crop right half of video
Crop(width=0.5, height=1.0, x=0.5, y=0.0, mode=CropMode.CUSTOM).apply(video)
Crop
Bases: Transformation
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/base/transforms.py
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 | |
__init__
__init__(
width: int | float,
height: int | float,
x: int | float = 0,
y: int | float = 0,
mode: CropMode = CropMode.CENTER,
)
Initialize cropper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int | float
|
Crop width. Pass an int for pixels, or a float in (0, 1] as a fraction of the video width. |
required |
height
|
int | float
|
Crop height. Pass an int for pixels, or a float in (0, 1] as a fraction of the video height. |
required |
x
|
int | float
|
Left edge X position. Only used when mode is "custom". Pass an int for pixels or a float in [0, 1] for a fraction. |
0
|
y
|
int | float
|
Top edge Y position. Only used when mode is "custom". Pass an int for pixels or a float in [0, 1] for a fraction. |
0
|
mode
|
CropMode
|
"center" crops from the middle of the frame, "custom" uses the x/y coordinates you provide. |
CENTER
|
Source code in src/videopython/base/transforms.py
apply
Crop video to target dimensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
Video
|
Input video. |
required |
Returns:
| Type | Description |
|---|---|
Video
|
Cropped video. |
Source code in src/videopython/base/transforms.py
CropMode
CropMode
SpeedChange
SpeedChange
Bases: Transformation
Speeds up or slows down video playback.
Values above 1.0 speed up (2.0 = twice as fast), values below 1.0 slow down (0.5 = half speed). Can also smoothly ramp between two speeds.
Source code in src/videopython/base/transforms.py
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 | |
__init__
__init__(
speed: float,
end_speed: float | None = None,
interpolate: bool = True,
adjust_audio: bool = True,
)
Initialize speed changer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
speed
|
float
|
Playback speed multiplier. 2.0 = twice as fast, 0.5 = half speed, 1.0 = original speed. |
required |
end_speed
|
float | None
|
If set, smoothly ramp from speed to end_speed over the clip duration. Omit for constant speed. |
None
|
interpolate
|
bool
|
Blend between frames when slowing down for smoother motion. Disable for a choppy/stylistic look. |
True
|
adjust_audio
|
bool
|
Time-stretch audio to match the new speed. If false, audio is sliced or padded instead (no pitch correction). |
True
|
Source code in src/videopython/base/transforms.py
apply
Apply speed change to video.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
Video
|
Input video. |
required |
Returns:
| Type | Description |
|---|---|
Video
|
Video with adjusted speed. |
Source code in src/videopython/base/transforms.py
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 | |
PictureInPicture
PictureInPicture
Bases: Transformation
Places a smaller video on top of the main video (picture-in-picture).
Useful for reaction videos, facecam overlays, tutorials with presenter inset, and side-by-side commentary.
Source code in src/videopython/base/transforms.py
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 | |
__init__
__init__(
overlay: Video,
position: tuple[float, float] = (0.7, 0.7),
scale: float = 0.25,
border_width: int = 0,
border_color: tuple[int, int, int] = (255, 255, 255),
corner_radius: int = 0,
opacity: float = 1.0,
audio_mode: Literal["main", "overlay", "mix"] = "main",
audio_mix: tuple[float, float] = (1.0, 1.0),
)
Initialize picture-in-picture transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
overlay
|
Video
|
The video to show as the small inset. |
required |
position
|
tuple[float, float]
|
Center of the inset as normalized (x, y). (0, 0) = top-left corner, (1, 1) = bottom-right corner. |
(0.7, 0.7)
|
scale
|
float
|
Inset width as a fraction of the main video width. 0.25 = 25% of main width. |
0.25
|
border_width
|
int
|
Border thickness in pixels. 0 = no border. |
0
|
border_color
|
tuple[int, int, int]
|
Border color as [R, G, B], each 0-255. |
(255, 255, 255)
|
corner_radius
|
int
|
Rounded corner radius in pixels. 0 = square corners. |
0
|
opacity
|
float
|
Inset transparency. 0 = invisible, 1 = fully opaque. |
1.0
|
audio_mode
|
Literal['main', 'overlay', 'mix']
|
"main" keeps only the main audio, "overlay" uses only the inset audio, "mix" blends both tracks together. |
'main'
|
audio_mix
|
tuple[float, float]
|
Volume levels as [main, overlay] when audio_mode is "mix". 1.0 = original level. Values above 1.0 amplify (may clip). |
(1.0, 1.0)
|
Source code in src/videopython/base/transforms.py
apply
Apply picture-in-picture overlay to video.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
Video
|
Main video to apply overlay on. |
required |
Returns:
| Type | Description |
|---|---|
Video
|
Video with overlay applied. |
Source code in src/videopython/base/transforms.py
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 | |
Reverse
Reverse
Bases: Transformation
Plays the video backwards, with optional audio reversal.
Source code in src/videopython/base/transforms.py
__init__
Initialize reverse transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reverse_audio
|
bool
|
If true, reverse the audio track along with the video. Set to false to keep original audio over reversed footage. |
True
|
Source code in src/videopython/base/transforms.py
FreezeFrame
FreezeFrame
Bases: Transformation
Pauses video at a specific moment by holding a single frame.
The frozen frame is inserted into the timeline, making the video longer (or replacing existing frames in "replace" mode).
Source code in src/videopython/base/transforms.py
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 | |
__init__
__init__(
timestamp: float,
duration: float = 2.0,
position: Literal[
"before", "after", "replace"
] = "after",
)
Initialize freeze frame transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timestamp
|
float
|
Time in seconds at which to capture the frame. |
required |
duration
|
float
|
How long to hold the frozen frame, in seconds. |
2.0
|
position
|
Literal['before', 'after', 'replace']
|
Where to place the frozen frames. "after" inserts them after the timestamp, "before" inserts them before it, "replace" swaps out existing video at that point. |
'after'
|
Source code in src/videopython/base/transforms.py
SilenceRemoval
Removes or speeds up silent gaps between speech using word-level transcription timing. Requires transcription data passed via VideoEdit.run(context={"transcription": ...}) or directly to apply(video, transcription=...).
SilenceRemoval
Bases: Transformation
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. Requires a transcription to be available.
Source code in src/videopython/base/transforms.py
753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 | |
__init__
__init__(
min_silence_duration: float = 1.0,
padding: float = 0.15,
mode: Literal["cut", "speed_up"] = "cut",
speed_factor: float = 3.0,
)
Initialize silence removal transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_silence_duration
|
float
|
Ignore silences shorter than this many seconds. Keeps natural pauses intact. |
1.0
|
padding
|
float
|
Seconds of breathing room to keep around each speech boundary so cuts don't feel abrupt. |
0.15
|
mode
|
Literal['cut', 'speed_up']
|
"cut" removes silent sections entirely, "speed_up" plays them at a faster speed instead. |
'cut'
|
speed_factor
|
float
|
How fast to play silent sections when mode is "speed_up". 3.0 = three times normal speed. |
3.0
|
Source code in src/videopython/base/transforms.py
apply
Apply silence removal to video.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
Video
|
Input video. |
required |
transcription
|
Transcription | None
|
Word-level transcription (Transcription object). Required -- raises ValueError if not provided. |
None
|
Source code in src/videopython/base/transforms.py
For AI-powered transforms (face tracking, auto-framing), see AI Transforms.