-
Notifications
You must be signed in to change notification settings - Fork 14
3 ‐ Preprocessing
Alexander Refsum Jensenius edited this page Aug 6, 2026
·
23 revisions
For complete documentation see Preprocessing on the docs site.
All preprocessing is applied at load time via MgVideo constructor arguments. Steps execute in this order: trim → skip → fix → rotate → contrast/brightness → crop → grayscale.
import musicalgestures as mg
mv = mg.MgVideo('/path/to/video.avi', starttime=5, endtime=15, skip=3,
rotate=90, contrast=100, brightness=20, crop='auto', color=False)| Parameter | Default | Description |
|---|---|---|
starttime, endtime
|
0, 0
|
Trim to a time range in seconds |
skip |
0 |
Discard n frames before keeping one, so skip=3 keeps every 4th frame |
frames |
0 |
Fix total frame count (−1 for keyframes only) |
rotate |
0 |
Rotation angle in degrees |
contrast, brightness
|
0, 0
|
Percentage adjustment, −100 to 100 |
crop |
'None' |
'auto' (motion-based) or 'manual' (draw rectangle) |
color |
True |
False for grayscale mode |
keep_all |
False |
Keep intermediate files from each step |
resample() is a method on an already-loaded MgVideo. It returns a new MgVideo and leaves the original untouched:
mv = mg.MgVideo('/path/to/video.avi')
mv25 = mv.resample(fps=25) # retime to 25 fps (duration-preserving)
fast = mv.resample(speed=2.0) # 2× faster — video + audio retimed in sync
slow = mv.resample(speed=0.5) # 2× slower / longer
dec = mv.resample(skip=2) # discard 2 frames for every one kept-
fps— duration-preserving frame-rate change (FFmpegfpsfilter) -
speed— playback-speed factor (>1faster/shorter,<1slower/longer); retimes video + audio in sync -
skip— integer frame decimation (also speeds up)
When combined, they are applied in order skip → speed/fps. The output name defaults to the input name + _resampled; target_name and overwrite work as they do everywhere else, described on File Naming.
A project from the fourMs Lab, RITMO Centre for Interdisciplinary Studies in Rhythm, Time and Motion, Department of Musicology, University of Oslo.