-
Notifications
You must be signed in to change notification settings - Fork 13
3 ‐ Preprocessing
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, # trim start (seconds)
endtime=15, # trim end (seconds)
skip=3, # keep every 4th frame
rotate=90, # degrees
contrast=100, # -100 to 100
brightness=20, # -100 to 100
crop='auto', # 'auto', 'manual', or None
color=False, # False = grayscale
)| Parameter | Description |
|---|---|
starttime, endtime
|
Trim to a time range in seconds |
skip |
Skip n frames between each kept frame |
frames |
Fix total frame count (−1 for keyframes only) |
rotate |
Rotation angle in degrees |
contrast, brightness
|
Percentage adjustment, −100 to 100 |
crop |
'auto' (motion-based) or 'manual' (draw rectangle) |
color |
False for grayscale mode |
keep_all |
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/overwrite work as elsewhere.
By default each method appends a suffix: dance_history.avi. With overwrite=True (default) an existing file is replaced in place; set overwrite=False for the old auto-increment behaviour: dance_history_0.avi, dance_history_1.avi, etc.
A project from the fourMs Lab, RITMO Centre for Interdisciplinary Studies in Rhythm, Time and Motion, Department of Musicology, University of Oslo.