Skip to content

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)

Key parameters

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

Resampling (frame rate, speed, frame decimation)

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 (FFmpeg fps filter)
  • speed — playback-speed factor (>1 faster/shorter, <1 slower/longer); retimes video + audio in sync
  • skip — integer frame decimation (also speeds up)

When combined, they are applied in order skipspeed/fps. The output name defaults to the input name + _resampled; target_name and overwrite work as they do everywhere else, described on File Naming.

Clone this wiki locally