Skip to main content

A vapoursynth plugin to do potentially useful things with motion vectors that have already been generated.

Project description

Manipulate Motion Vectors

A vapoursynth plugin to do potentially useful things with motion vectors that have already been generated.

Installation

The plugin is available on PyPI and can be installed with:

python -m pip install vapoursynth-manipmv

Overview

Motion vectors are useful for a variety of video processing tasks, and there is a long history of tooling related generating and using them. This historical tooling has generally coupled creating the motion vectors and consuming them into one plugin, MVTools. But it is the author's opinion that decoupled tooling with a standard interface is reasonable and desirable. There is not quite a standard interface among the various versions and ports of MVTools so for now this plugin specifically targets the conventions used by dubhater/vapoursynth-mvtools (see the assumed conventions section for details).

Functions

ExpandAnalysisData

Expands the binary MVTools_MVAnalysisData frame prop into separate frame props for convenience.

int       Analysis_MagicKey
int       Analysis_Version
int[x, y] Analysis_BlockSize
int       Analysis_Pel
int       Analysis_LevelCount
int       Analysis_DeltaFrame
int       Analysis_Backwards
int       Analysis_CpuFlags
int       Analysis_MotionFlags
int[x, y] Analysis_FrameSize
int[x, y] Analysis_Overlap
int[x, y] Analysis_BlockCount
int       Analysis_BitsPerSample
int[x, y] Analysis_ChromaRatio
int[x, y] Analysis_Padding

Usage

mvmanip.ExpandAnalysisData(vnode clip)

Parameters

  • clip:
    A clip generated by mv.Analyse() or which otherwise follows its conventions.

Examples

# Programmatically reference block size used
clip = vs.core.std.BlankClip()
msuper = clip.mv.Super()
forward = msuper.mv.Analyse()

annotated = forward.manipmv.ExpandAnalysisData()
block_size_x, block_size_y = annotated.get_frame(0).props["Analysis_BlockSize"]
print(f"Blocks used for analysis are {block_size_x}x{block_size_y}")

ScaleVect

[!WARNING] Arbitrary scaling of motion vectors is possible and conceptually reasonable and is thus allowed by this plugin. However subsequent operations which use the motion vectors may not support all of the scaled properties. For example scaling 8x8 blocks by 5x results in 40x40 blocks which aren't something Analyse supports generating.

Scales image_size, block_size, overlap, padding, and the individual motion_vectors contained in Analyse output by arbitrary and independent x and y factors. This is mostly useful to use motion vectors generated on a downscaled clip to perform operations on the full size clip (e.g. calculating motion vectors at 1080p and applying them at 4K).

Usage

manipmv.ScaleVect(vnode clip[, int scaleX=1, int scaleY=scaleX])

Parameters

  • clip:
    A clip generated by mv.Analyse() or which otherwise follows its conventions.
  • scaleX:
    The scale factor to use horizontally.
    This is limited to an 8 bit value, but practical scale factors are likely single digit.
    Default value is 1 (no scaling).
  • scaleY:
    The scale factor to use vertically.
    This is limited to an 8 bit value, but practical scale factors are likely single digit.
    Default value is the same as scaleX.

Examples

# Use vectors from 1080p clip to denoise 4K clip
SCALE = 2
HPAD = 16
VPAD = 16
clip = vs.core.std.BlankClip(width=3840, height=2160)
small_clip = clip.resize.Bilinear(clip.width // SCALE, clip.height // SCALE)

small_msuper = small_clip.mv.Super(hpad=HPAD, vpad=VPAD)
small_forward = small_msuper.mv.Analyse()
small_backward = small_msuper.mv.Analyse(isb=True)

big_msuper = clip.mv.Super(hpad=HPAD * SCALE, vpad=VPAD * SCALE)
upscaled_forward = small_forward.manipmv.ScaleVect(SCALE)
upscaled_backward = small_backward.manipmv.ScaleVect(SCALE)

denoised = clip.mv.Degrain1(big_msuper, upscaled_backward, upscaled_forward)
denoised.set_output()

ShowVect

Draws generated vectors onto a clip.

Usage

manipmv.ShowVect(vnode clip, vnode vectors[, bool useSceneChangeProps=True])

Parameters

  • clip:
    A YUV clip with 8/10/12/16 bit integer bitdepth and dimensions which match the vectors.
  • vectors:
    A clip generated by mv.Analyse() or which otherwise follows its conventions. The first frame of this clip will be fetched with the filter is instantiated to determine the pel and block_size used by the vectors.
  • useSceneChangeProps:
    Skips drawing vectors if frame props indicate they are from a different scene than the current frame of the clip. Specifically if the vectors are forwards then _SceneChangePrev and Scenechange are examined, and if the vectors are backwards _SceneChangeNext is examined. There are a few different filters which can stamp these frame props, but mv.SCDetection() should be preferred when visualizing vectors generated with delta greater than 1.

Examples

# This is not a terribly exciting example since the BlankClip doesn't move...
clip = vs.core.std.BlankClip(width=1920, height=1080)

msuper = clip.mv.Super()
forward = msuper.mv.Analyse()

clip = clip.mv.SCDetection(forward)
debug = clip.manipmv.ShowVect(forward)
debug.set_output()

Assumed Conventions

[!NOTE] No MVTools version really documents its conventions explicitly since they are considered to be internal. So the descriptions in this section should not be considered official, but they are hopefully correct, and serve to at least document the assumptions this plugin is making.

The dubhater/vapoursynth-mvtools plugin stores all of its working data for motion vectors as binary data in vapoursynth frame props on the clip which results from calling mv.Analyse(). Specifically there are two props of interest MVTools_MVAnalysisData and MVTools_vectors.

All of this data is serialized rather implictly from C++ structs. Most of these structs contain only signed integers (even for fields which do not have logical negative interpretations) and bytes are written with native endianness. For deserialization I have chosen to interpret fields that should not be negative (e.g. width, height, size) as unsigned and always use little endian byte order. These nuances are hopefully not relevant in practice as the positive integer range of a signed 32 bit integer is still much larger than practical video sizes and almost every host running MVTools is likely to be little endian natively. Still it would be nice conceptually if future motion vector work could make these conventions explicit; for this reason the types below will be listed with the signedness I think they should have.

MVTools_MVAnalysisData

This just contains some metadata about the context in which the vectors were generated. The length of this data is expected to always be 84 bytes (21 32-bit integers) in the following order:

[!IMPORTANT] The magic_key and version appear to be uninitialized by the MVTools plugin and so have no usable data in them.

u32 magic_key
u32 version
u32 block_size_x
u32 block_size_y
u32 pel
u32 level_count
i32 delta_frame
u32 backwards
u32 cpu_flags
u32 motion_flags
u32 width
u32 height
u32 overlap_x
u32 overlap_y
u32 block_count_x
u32 block_count_y
u32 bits_per_sample
u32 chroma_ratio_y
u32 chroma_ratio_x
u32 padding_x
u32 padding_y

MVTools_vectors

This contains the actual motion vector data for all levels of motion vector calculation. The structure of a single motion vector is simply:

i32 x
i32 y
u64 sad

These are serialized without any padding (16 bytes per vector). Each level is structured as:

u32 size
[] vectors

Again without any padding. So for example a level with 10 vectors would have a size value of 164 (16 bytes per vector * 10 vectors + 4 bytes for the size).

This is ultimately structured as:

u32 size
u32 valid
[] levels

Again without any padding. The value stored in size is therefore expected to be equivalent to the size which vapoursynth reports for the frame property. The valid value is expected to be 0 for situations where motion vectors are not present (e.g. the first frame of forwards vectors) and 1 for situations where motion vectors are present.

Maintenance notes

[!NOTE] This section is just so the maintainer doesn't forget how the repo is setup. This isn't really relevant for users.

Tests can be run with

zig build test --summary all

In theory everything is setup such that the following steps are sufficient to build the library, create a github release, and publish all the wheels to PyPI.

zig build version -- inc --patch
git commit -am "Bumping patch version"
git push

The release body can then be edited to whatever seems appropriate.

This depends on a number of third party github actions so any one of those could break. Zig could also make it easier or harder to get the version from build.zig.zon and the approach may need to be tweaked. For now it seems usable.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vapoursynth_manipmv-1.3.0.tar.gz (21.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

vapoursynth_manipmv-1.3.0-py3-none-win_amd64.whl (57.3 kB view details)

Uploaded Python 3Windows x86-64

vapoursynth_manipmv-1.3.0-py3-none-musllinux_1_2_x86_64.whl (36.0 kB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

vapoursynth_manipmv-1.3.0-py3-none-musllinux_1_2_aarch64.whl (19.7 kB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

vapoursynth_manipmv-1.3.0-py3-none-manylinux_2_17_x86_64.whl (36.3 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

vapoursynth_manipmv-1.3.0-py3-none-manylinux_2_17_aarch64.whl (19.8 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

vapoursynth_manipmv-1.3.0-py3-none-macosx_11_0_x86_64.whl (20.0 kB view details)

Uploaded Python 3macOS 11.0+ x86-64

vapoursynth_manipmv-1.3.0-py3-none-macosx_11_0_arm64.whl (20.4 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file vapoursynth_manipmv-1.3.0.tar.gz.

File metadata

  • Download URL: vapoursynth_manipmv-1.3.0.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for vapoursynth_manipmv-1.3.0.tar.gz
Algorithm Hash digest
SHA256 31e977197ad846f1af1a66f4bc8824e8b05119aabfc3885446f89fee197851bb
MD5 618dad465054bfc265b2aca8b92c9c44
BLAKE2b-256 8584582f98262a2a073468cf3c8b1d5b587baf56dc91e3552fdb17f39d1c7a6c

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_manipmv-1.3.0.tar.gz:

Publisher: build.yaml on Mikewando/manipulate-motion-vectors

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_manipmv-1.3.0-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for vapoursynth_manipmv-1.3.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 006c5c923ac3bae550b4414a47d73557358d40026ff8e7528c81556b4d8ec5fb
MD5 3aeb1da4115b86804da16ec9fbc44b90
BLAKE2b-256 dc35c9485b416110ea6d26063b297099eeff0925000776c4687b7ce78d726c11

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_manipmv-1.3.0-py3-none-win_amd64.whl:

Publisher: build.yaml on Mikewando/manipulate-motion-vectors

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_manipmv-1.3.0-py3-none-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for vapoursynth_manipmv-1.3.0-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 33ddb1d7aaa5ed3d9e276096a1f4e2eb7a75dce31e1c0760226e60687e150add
MD5 a7add89f1aee6fba50c20b049d7acc25
BLAKE2b-256 e715ad140067d4231fac425864bbd4466ffe310eee6c9f8f847cdec30b645ada

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_manipmv-1.3.0-py3-none-musllinux_1_2_x86_64.whl:

Publisher: build.yaml on Mikewando/manipulate-motion-vectors

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_manipmv-1.3.0-py3-none-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for vapoursynth_manipmv-1.3.0-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 9c92c7dbb1aaf9d427e74bcd997ff8dc0ad868bd3fe1166ba0fbdf0f3b4ec4a7
MD5 2aa7a3bdb20dc3da0a525fa650404c94
BLAKE2b-256 d567fd79126568bad6894146d49d4b84843a2a765da2ad2569681032b251aa16

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_manipmv-1.3.0-py3-none-musllinux_1_2_aarch64.whl:

Publisher: build.yaml on Mikewando/manipulate-motion-vectors

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_manipmv-1.3.0-py3-none-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for vapoursynth_manipmv-1.3.0-py3-none-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 37b5ad285e9a873b905ab14ff2aebb515772318724ae6eff3c1086e42a0dc87f
MD5 eb3e424b029f4734537870fcc97d540b
BLAKE2b-256 93574e5762841e25b9a60de72f643577c3c57e4970f3b4afcd05595e51380ee8

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_manipmv-1.3.0-py3-none-manylinux_2_17_x86_64.whl:

Publisher: build.yaml on Mikewando/manipulate-motion-vectors

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_manipmv-1.3.0-py3-none-manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for vapoursynth_manipmv-1.3.0-py3-none-manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 660ff1f585a4aecbb6a88177a83664937fcaa3a18e09f9b2751e5eabfd293839
MD5 b474f41da3f53a9930a329b9efa21c02
BLAKE2b-256 6917d36738d5a297d46de79fd85a41de41838d123bd0513b2b6030bcd7c67836

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_manipmv-1.3.0-py3-none-manylinux_2_17_aarch64.whl:

Publisher: build.yaml on Mikewando/manipulate-motion-vectors

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_manipmv-1.3.0-py3-none-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for vapoursynth_manipmv-1.3.0-py3-none-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 c556a888996e8f76095477cf9c2e606e759d73c65f0bda40f833efc64b49362e
MD5 fe34d31d42edbbab7be5bf6675affb96
BLAKE2b-256 c4b8fdc7afba35a8857d56f19494b028b488ca8f2c04d0bdc261ee351c710e17

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_manipmv-1.3.0-py3-none-macosx_11_0_x86_64.whl:

Publisher: build.yaml on Mikewando/manipulate-motion-vectors

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vapoursynth_manipmv-1.3.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for vapoursynth_manipmv-1.3.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ed69b05fe871c12187d41148783544f24e80406c548668cfaf6952ee3891609e
MD5 ca202fd98f3919c0915441ef7cbef5d5
BLAKE2b-256 2a87029025fbf84d7fbf772c68c747421eed7a28e5d69c073b7d8772e60fa003

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_manipmv-1.3.0-py3-none-macosx_11_0_arm64.whl:

Publisher: build.yaml on Mikewando/manipulate-motion-vectors

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page