Effects
Effects are Operation subclasses that preserve video shape and frame
count. Each carries an optional window: TimeRange | None field that
limits the effect to a sub-range of the video. See
Operations for the base contract.
Usage
Effects are not applied to a Video directly. They run only through the
streaming engine: add the operation(s) to a VideoEdit and render with
run_to_file. Each effect carries an optional window that limits it to
a sub-range of the segment.
from videopython.base import BoundingBox
from videopython.editing import (
VideoEdit, SegmentConfig,
Blur, Zoom, ColorGrading, Vignette, KenBurns,
Fade, VolumeAdjust, TextOverlay, TimeRange,
)
edit = VideoEdit(segments=[SegmentConfig(source="input.mp4", start=0, end=5, operations=[
# Effect across the full segment:
Blur(mode="constant", iterations=50),
# Effect on a sub-range via the `window` field:
Blur(mode="constant", iterations=50, window=TimeRange(start=0.0, stop=2.0)),
])])
edit.run_to_file("output.mp4")
The constructors below produce the operation objects to drop into a
segment's operations list (as above) and render with run_to_file:
video_op = Blur(mode="constant", iterations=50)
video_op = Blur(mode="constant", iterations=50, window=TimeRange(start=0.0, stop=2.0))
video_op = Zoom(zoom_factor=1.5, mode="in")
video_op = ColorGrading(brightness=0.1, contrast=1.2, saturation=1.1)
video_op = Vignette(strength=0.5, radius=0.8)
start_region = BoundingBox(x=0.0, y=0.0, width=0.5, height=0.5)
end_region = BoundingBox(x=0.5, y=0.5, width=0.5, height=0.5)
video_op = KenBurns(start_region=start_region, end_region=end_region,
easing="ease_in_out")
video_op = Fade(mode="in", duration=1.0)
video_op = Fade(mode="out", duration=0.5)
video_op = VolumeAdjust(volume=0.0, window=TimeRange(stop=2.0)) # mute first 2s
video_op = TextOverlay(text="Hello World", position=(0.5, 0.9), font_size=48)
# YouTube / experimental effects:
from videopython.editing import (
Shake, PunchIn, Flash, ChromaticAberration, Glitch,
FilmGrain, Sharpen, Pixelate, MirrorFlip, Kaleidoscope,
)
video_op = Shake(intensity_px=6, mode="rhythmic", frequency_hz=4)
video_op = PunchIn(zoom_factor=1.5, attack_frames=3, release_frames=0)
video_op = Flash(color=(255, 255, 255), peak_alpha=1.0,
attack_frames=2, decay_frames=4,
window=TimeRange(start=1.0, stop=1.3))
video_op = ChromaticAberration(shift_px=4, mode="radial")
video_op = Glitch(intensity=0.4, slice_count=12, seed=42)
video_op = FilmGrain(intensity=0.08, monochrome=True)
video_op = Sharpen(amount=1.0, kernel_size=5)
video_op = Pixelate(block_size=24,
region=BoundingBox(x=0.4, y=0.2, width=0.2, height=0.2))
video_op = MirrorFlip(mode="mirror_left")
video_op = Kaleidoscope(segments=6)
A SegmentConfig's operations list also accepts the inline dict form;
the window field travels as a nested object:
The subtitles effect (add_subtitles) requires a transcription
context, passed to the runner: run_to_file(..., context={"transcription": ...}).
Available Effects
Every effect is streamable (compatible with VideoEdit.run_to_file() for
constant-memory processing). The two text-rendering effects compile to a native
ffmpeg filter at plan-compile time (no per-frame Python): add_subtitles (libass
subtitles=) and text_overlay (drawtext). Every other effect runs per-frame
Python via process_frame — vectorised numpy/cv2. Benchmarks showed compiling
pixel effects to ffmpeg filters bought at best ~1.1–1.4x (the gain was avoiding
the rawvideo round-trip, not faster compute) and in some cases lost (gblur),
so the engine keeps ffmpeg only for what numpy can't do well: geometry/timing
transforms and text rendering. Context-requiring ops (add_subtitles) stream
too: pass context= to run_to_file and the runner re-bases it onto each
segment's local timeline.
| op | Class | Description |
|---|---|---|
blur_effect |
Blur |
Gaussian blur, constant or ramping |
zoom_effect |
Zoom |
Time-varying zoom in/out |
color_adjust |
ColorGrading |
Brightness / contrast / saturation / temperature |
vignette |
Vignette |
Radial darkening from the edges |
ken_burns |
KenBurns |
Pan-and-zoom between two bounding boxes |
full_image_overlay |
FullImageOverlay |
Composite a full-frame image |
image_overlay |
ImageOverlay |
Scaled, positioned raster/SVG image (logo / watermark) |
fade |
Fade |
Audio + video fade in/out/in_out |
volume_adjust |
VolumeAdjust |
Audio-only effect |
text_overlay |
TextOverlay |
Rendered text on top of frames |
add_subtitles |
TranscriptionOverlay |
Word-level subtitles via libass; requires transcription context |
shake |
Shake |
Per-frame jitter (random / rhythmic / decay) |
punch_in |
PunchIn |
Snap-zoom emphasis with optional release |
flash |
Flash |
Solid-color frame flash with attack/decay |
chromatic_aberration |
ChromaticAberration |
R/B channel split (horizontal / vertical / radial) |
glitch |
Glitch |
Random horizontal slice displacement + channel offsets |
film_grain |
FilmGrain |
Additive seeded noise (mono or RGB) |
sharpen |
Sharpen |
Unsharp-mask sharpening |
pixelate |
Pixelate |
Mosaic blocks, full frame or region |
mirror_flip |
MirrorFlip |
Flip or reflect one half onto the other |
kaleidoscope |
Kaleidoscope |
N-way radial mirror around the center |
API Reference
Effect
Effect
Bases: Operation
Operation that preserves shape and frame count, driven by per-frame streaming.
Subclasses implement the streaming contract -- :meth:process_frame (and
:meth:streaming_init for any precomputed per-stream state) -- which is the
single source of truth for the effect's pixel logic. The streaming engine
in editing/streaming.py drives that contract for bounded-memory
execution, resolving :attr:window against the segment timeline so frames
outside the window pass through untouched.
Effects that compile to a native ffmpeg filter instead set
:attr:compiles_to_filter and implement :meth:to_ffmpeg_filter (and, for
audio-coupled effects like Fade/VolumeAdjust,
:meth:to_ffmpeg_audio_filter) so the window stays coherent across the
decode/encode graph.
Source code in src/videopython/editing/operation.py
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 | |
audio_coupled
class-attribute
Whether the effect mutates audio alongside pixels (afade/volume).
compiles_to_filter
property
Whether this effect joins the decode filter chain instead of scheduling per-frame Python.
When True, the streaming plan builder calls :meth:to_ffmpeg_filter
(with the segment's resolved context on the :class:FilterCtx) and, if
it compiles, appends the result to the vf chain at this op's plan
position -- the Filter class of the streaming contract. Instance-level
rather than a ClassVar because it may depend on field values (e.g.
add_subtitles's renderer). False by default: effects normally
stream via streaming_init/process_frame.
predict_metadata
Effects preserve shape and frame count, so the prediction is identity.
Accepts **_context so requires-aware effects (TranscriptionOverlay)
validate without subclasses needing to override just to widen the
signature. Mirrors :meth:Effect.streaming_init's **_context accept-all.
Source code in src/videopython/editing/operation.py
streaming_init
Hook for per-stream precomputation (per-frame alphas, sigma curves...).
_context carries resolved requires values for context-aware
effects (e.g. transcription=... for TranscriptionOverlay),
already re-based onto the local timeline by the runner. Effects that
declare no requires are always called without context kwargs.
Default: no-op. Override in subclasses that need it.
Source code in src/videopython/editing/operation.py
process_frame
Process one (H, W, 3) uint8 frame in streaming mode.
frame_index is 0-based within this effect's active window.
Source code in src/videopython/editing/operation.py
streams
An effect streams via per-frame Python (process_frame) or a filter.
Frame effects override :meth:process_frame; filter effects
(add_subtitles, vignette, ...) instead set
:attr:compiles_to_filter and implement :meth:to_ffmpeg_filter.
add_subtitles streams only via the filter path (it does not override
process_frame), so compiles_to_filter is consulted per-instance.
Source code in src/videopython/editing/operation.py
Blur
Blur
Bases: Effect
Applies Gaussian blur that can stay constant or ramp up/down over the clip.
Source code in src/videopython/editing/effects.py
Zoom
Zoom
Bases: Effect
Progressively zooms into or out of the frame center over the clip duration.
Source code in src/videopython/editing/effects.py
FullImageOverlay
FullImageOverlay
Bases: Effect
Composites a full-frame image on top of every video frame.
Useful for watermarks, logos, or static graphic overlays. Supports
transparency via RGBA images and an overall opacity control. The overlay
is loaded just-in-time from source so the op stays JSON-serialisable.
Source code in src/videopython/editing/effects.py
predict_metadata
Reject an overlay that cannot composite onto this video at run time.
Two failures run_to_file() cannot survive are caught at validate()
time instead of mid-stream: (a) the overlay's pixel dimensions must match
the video frame exactly (this op is full-frame, unlike
:class:ImageOverlay), and (b) the combined fade-in + fade-out cannot
exceed the clip length. Both checks come from the deleted eager path; the
overlay header is read once here (no per-frame work).
Source code in src/videopython/editing/effects.py
ImageOverlay
ImageOverlay
Bases: _AnchoredOverlay
Composites a scaled image at an anchored position on every frame in the window.
A resolution-independent watermark / logo / brand mark. Unlike
:class:FullImageOverlay (full-frame only, raises on size mismatch), the
image is scaled to a fraction of the frame width and placed at an
anchored normalized position, so one config works across 1080p / 4k /
vertical / square. Loaded just-in-time from source so the op stays
JSON-serialisable. Off-frame or oversized placement clips to a partial
paste or a no-op -- the same contract as :class:TextOverlay, never an
error; only an unreadable source is rejected (in predict_metadata).
source may be a raster image (PNG/JPEG/WebP) or an SVG (detected by the
.svg extension). An SVG is rasterised by resvg at the exact target
pixel width -- crisp at any frame size, not a blurry upscale of a
fixed-size bitmap -- with a transparent background and no remote-resource
fetching (the local path only; no SSRF). SVGs containing text depend on the
fonts available at render time.
Source code in src/videopython/editing/effects.py
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 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 | |
predict_metadata
Reject only a missing/unreadable source (see :meth:Operation.predict_metadata).
An unreadable source is the one failure run_to_file() cannot survive -- it
would raise mid-stream after expensive frame decode -- so it is caught
at validate() time, symmetric with TranscriptionOverlay.
Geometry (oversized / off-frame) is deliberately not checked here: it
clips to a valid no-op like :class:TextOverlay, so rejecting it would
break that contract and the parity with the op this is modeled on. Both
checks are cheap (a header verify() / a 1px SVG parse, no full
decode), so validate() stays frame-free.
Source code in src/videopython/editing/effects.py
ColorGrading
ColorGrading
Bases: Effect
Adjusts color properties: brightness, contrast, saturation, and temperature.
Source code in src/videopython/editing/effects.py
Vignette
Vignette
Bases: Effect
Darkens the edges of the frame, drawing attention to the center.
Source code in src/videopython/editing/effects.py
KenBurns
KenBurns
Bases: Effect
Cinematic pan-and-zoom that smoothly animates between two crop regions.
Creates movement by transitioning from a start region to an end region over the clip. Use it to add motion to still images or to guide the viewer's eye across a scene.
Source code in src/videopython/editing/effects.py
Fade
Fade
Bases: Effect
Fades video and audio to or from black.
Source code in src/videopython/editing/effects.py
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 | |
to_ffmpeg_audio_filter
Express the fade's gain envelope as a windowed volume expression.
The audio twin of the video fade (which scales pixels by the same alpha
envelope in :meth:process_frame). It must mirror
:func:_fade_envelope: the ramp applies only WITHIN [start, stop]
and the gain is 1.0
everywhere else -- so a windowed fade-out returns to full volume after
the window (matching the video, which resumes full brightness), instead
of staying muted. Native afade cannot express this (it holds 0
outside the ramp), so the gain is a piecewise volume=...:eval=frame
expression, like :class:VolumeAdjust. None when the window is
degenerate.
Source code in src/videopython/editing/effects.py
VolumeAdjust
VolumeAdjust
Bases: Effect
Changes audio volume within a time range without affecting video frames.
Source code in src/videopython/editing/effects.py
to_ffmpeg_audio_filter
Apply the volume change over the window via the volume filter.
The audio twin of the (pixel-passthrough) volume effect. A flat
multiplier compiles to volume=<v>:enable='between(t,start,stop)'.
When ramp_duration>0 the gain is a time-piecewise expression
(volume=eval=frame) that ramps 1 -> volume over the first
ramp_duration of the window and back over the last, following the
1 + (volume-1)*sqrt(t) edge-ramp shape. The window resolves
against the segment duration (ctx.frame_count / ctx.fps); None
for a degenerate window or a no-op (volume == 1 with no ramp).
Source code in src/videopython/editing/effects.py
TextOverlay
TextOverlay
Bases: _AnchoredOverlay
Draws text on video frames, with auto word-wrap and optional background box.
Source code in src/videopython/editing/effects.py
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 751 752 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 | |
compiles_to_filter
property
Compile to drawtext when a real TrueType file resolves, else frame-only.
to_ffmpeg_filter
Compile the anchored, word-wrapped text overlay to one drawtext entry.
The text is pre-wrapped with the SAME PIL metrics (:meth:_wrap_text)
the numpy twin uses and written to a textfile (registered on
ctx.owned_files for the runner to delete), so line breaks match
exactly -- drawtext has no pixel word-wrap. The box is
box=1:boxcolor=...:boxborderw=<padding> placed at the anchored
position :meth:_compute_position computes. Faithful visual twin
(freetype vs PIL metrics diverge a few px), re-baselined to ffmpeg.
Comma-join safe: every comma-bearing value is wrapped via
:func:escape_filter_value. yuv-safe (drawtext needs no rgb24).
Source code in src/videopython/editing/effects.py
Shake
Shake
Bases: Effect
Per-frame camera shake: jitters every frame by a random or rhythmic offset.
The frame is translated by (dx, dy) and cropped back to the original
canvas, so the visible area shrinks slightly at the edges. Useful for
reaction emphasis, impact moments, or music-synced vibration.
Source code in src/videopython/editing/effects.py
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 | |
PunchIn
PunchIn
Bases: Effect
Snap-zoom emphasis: rapidly zooms into the center, holds, optionally releases.
Different from Zoom (which ramps continuously over the whole clip).
PunchIn reaches the target zoom in attack_frames and stays there;
if release_frames > 0 it eases back out at the end.
Source code in src/videopython/editing/effects.py
Flash
Flash
Bases: Effect
Solid-color frame flash that fades in over attack_frames and out over decay_frames.
Commonly used between hard cuts, on impact moments, or as a strobe. The
flash color is blended over the source using an alpha curve that peaks
at peak_alpha in the middle of the window.
Source code in src/videopython/editing/effects.py
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 | |
ChromaticAberration
ChromaticAberration
Bases: Effect
Splits R and B channels by shift_px to mimic lens chromatic aberration.
A defining look of glitch / vaporwave / experimental edits. Use a small shift (1-3 px) for a stylistic edge, larger (8+ px) for impact frames.
Source code in src/videopython/editing/effects.py
1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 | |
Glitch
Glitch
Bases: Effect
Random horizontal slice displacement + channel offsets for a digital-corruption look.
Each frame gets a fresh set of slices shuffled left/right plus a small R/B
channel shift. Deterministic given seed -- the same plan produces the
same glitch every run.
Source code in src/videopython/editing/effects.py
FilmGrain
FilmGrain
Bases: Effect
Additive Gaussian noise simulating film grain.
Seeded per-frame so renders are reproducible. monochrome=True keeps
the noise luma-only (cinematic), False adds independent RGB noise
(digital / 8-bit look).
Source code in src/videopython/editing/effects.py
Sharpen
Sharpen
Bases: Effect
Unsharp-mask sharpening: blur the frame and subtract from itself with weight.
amount=0 returns the original frame; higher values produce a crisper
look at the cost of edge halos.
Source code in src/videopython/editing/effects.py
Pixelate
Pixelate
Bases: Effect
Mosaic blocks: downscale + nearest-neighbour upscale, optionally limited to a region.
Useful for face censoring (combine with BoundingBox from face
detection) or a stylistic 8-bit look.
Source code in src/videopython/editing/effects.py
MirrorFlip
MirrorFlip
Bases: Effect
Flip frames or reflect one half onto the other.
horizontal / vertical are plain mirror flips. The mirror_*
modes reflect one half of the frame onto the opposite half, producing
a symmetric image with the chosen half preserved.
Source code in src/videopython/editing/effects.py
Kaleidoscope
Kaleidoscope
Bases: Effect
N-way radial mirror around the frame center.
Samples one wedge of the frame and reflects it segments times around
the center. The mapping is precomputed once per stream, so per-frame cost
is a single cv2.remap.