Motionvectors¶
mg_motionvectors ¶
mg_motionvectors(self, target_name=None, overwrite=True)
Renders a video visualising the motion vectors encoded in the input video.
Inter-frame codecs (MPEG-1/2/4, H.264, H.265, …) store motion vectors that describe
how macroblocks move between frames. This method uses FFmpeg's codecview filter
(with -flags2 +export_mvs) to draw those vectors as arrows on top of the video,
giving a quick, decoder-level view of motion without any re-computation.
NB: Only codecs that actually carry motion vectors will show arrows. Intra-only
formats (e.g. MJPEG, common in .avi files) have none — convert to an inter-frame
codec first (e.g. via show(mode='notebook') which makes an mp4, or any mp4/h264
source) to see motion vectors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_name
|
str
|
Target output name for the video. Defaults to None (which uses the input filename with the suffix "_motionvectors"). |
None
|
overwrite
|
bool
|
Whether to allow overwriting existing files or to automatically increment the target filename. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgVideo |
MgVideo
|
An MgVideo pointing to the rendered motion-vector video. |
Source code in musicalgestures/_motionvectors.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |