Skip to main content

A faster FFT spectrum VapourSynth plugin.

Project description

vapoursynth-fftspectrum-rs

A faster FFT spectrum VapourSynth plugin.

example

Install

Via vsrepo:

vsrepo install fftspectrum_rs

Manually: download a release from the Releases page and unzip fftspectrum_rs.dll (Windows), libfftspectrum_rs.so (Linux), or libfftspectrum_rs.dylib (macOS) into a plugins directory.

API

fftspectrum_rs.FFTSpectrum(clip: vs.VideoNode) -> vs.VideoNode
  • clip — Input video node. Must have 32-bit float format.

Only the first plane of clip will be processed. The output is a GRAYS video node.

Benchmark

On 1080p clips, this plugin is about 2.2 times faster than fftspectrum.FFTSpectrum(). This is mostly accomplished by minimizing the number of allocations, copies, and transposes done.

import numpy as np
from cv2 import DFT_COMPLEX_OUTPUT, dft
from vssource import BestSource
from vstools import core, depth, get_y, set_output, vs

core.set_affinity(range(0, 32, 2), 22000)

src = BestSource.source("/path/to/1080_clip.mkv", bits=0)
src_8 = depth(src, 8)
src_32 = depth(src, 32)

# fftspectrum
set_output(src_8.fftspectrum.FFTSpectrum(), "fftspectrum")

# numpy + ModifyFrame
def _to_polar(f: vs.VideoFrame, n: int) -> vs.VideoFrame:
    src = np.asarray(f[0])
    dft_shift = np.fft.fftshift(dft(src, flags=DFT_COMPLEX_OUTPUT))
    mag = np.sqrt(np.power(dft_shift[:, :, 1], 2) + np.power(dft_shift[:, :, 0], 2))
    dst = f.copy()
    np.copyto(np.asarray(dst[0]), np.log(mag) / 10)
    return dst

y = get_y(src_32)
set_output(y.std.ModifyFrame(y, _to_polar), "numpy ModifyFrame")

# fftspectrum_rs
set_output(src_32.fftspectrum_rs.FFTSpectrum(), "fftspectrum_rs")
$ hyperfine --warmup 1 'vspipe test.py --end 1999 -o {output_node} .' -P output_node 0 2
Benchmark 1: vspipe test.py --end 1999 -o 0 .
  Time (mean ± σ):     31.878 s ±  0.853 s    [User: 44.497 s, System: 1.592 s]
  Range (min  max):   30.672 s  33.681 s    10 runs

Benchmark 2: vspipe test.py --end 1999 -o 1 .
  Time (mean ± σ):     62.379 s ±  1.839 s    [User: 59.013 s, System: 22.801 s]
  Range (min  max):   59.342 s  64.992 s    10 runs

Benchmark 3: vspipe test.py --end 1999 -o 2 .
  Time (mean ± σ):     13.909 s ±  0.146 s    [User: 178.334 s, System: 18.904 s]
  Range (min  max):   13.669 s  14.166 s    10 runs

Summary
  vspipe test.py --end 1999 -o 2 . ran
    2.29 ± 0.07 times faster than vspipe test.py --end 1999 -o 0 .
    4.48 ± 0.14 times faster than vspipe test.py --end 1999 -o 1 .
Benchmark Mean (fps) Range (fps)
fftspectrum 62.74 ± 1.68 59.38 … 65.21
numpy ModifyFrame 32.06 ± 0.95 30.77 … 33.70
fftspectrum_rs 143.79 ± 1.51 141.18 … 146.32

Build

Rust v1.91.0-nightly and cargo may be used to build the project. Older versions will likely work fine but they aren't explicitly supported.

$ git clone https://github.com/sgt0/vapoursynth-fftspectrum-rs.git
$ cd vapoursynth-fftspectrum-rs

# Debug build.
$ cargo build

# Release (optimized) build.
$ cargo build --release

# Release build optimized for the host CPU.
$ RUSTFLAGS="-C target-cpu=native" cargo build --release

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_fftspectrum_rs-1.0.13.tar.gz (3.0 MB view details)

Uploaded Source

Built Distributions

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

vapoursynth_fftspectrum_rs-1.0.13-py3-none-win_amd64.whl (388.3 kB view details)

Uploaded Python 3Windows x86-64

vapoursynth_fftspectrum_rs-1.0.13-py3-none-manylinux_2_28_x86_64.whl (512.3 kB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

vapoursynth_fftspectrum_rs-1.0.13-py3-none-manylinux_2_28_aarch64.whl (350.7 kB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

vapoursynth_fftspectrum_rs-1.0.13-py3-none-macosx_11_0_arm64.whl (331.1 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file vapoursynth_fftspectrum_rs-1.0.13.tar.gz.

File metadata

File hashes

Hashes for vapoursynth_fftspectrum_rs-1.0.13.tar.gz
Algorithm Hash digest
SHA256 bd2347222d833d82ba8f3b4e4cf45aea6276b7c48e5c3eb510198520bf15ebe6
MD5 82be43cc32a91982cfa87c0949082ab8
BLAKE2b-256 13569771adfbc1195017e887142cf03253316efac3d21d2f7f10900bdcf628df

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_fftspectrum_rs-1.0.13.tar.gz:

Publisher: publish.yml on sgt0/vapoursynth-fftspectrum-rs

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_fftspectrum_rs-1.0.13-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for vapoursynth_fftspectrum_rs-1.0.13-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 6413142fe9760f42739e450be67d1317a5762dcd2761f66bb68d710e03879300
MD5 4434a3b21730b51f84a85a6e6764732b
BLAKE2b-256 57927409c611b1e71fe2cba74d1a0bb0c8c31037f55de077b65545f493b81fdf

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_fftspectrum_rs-1.0.13-py3-none-win_amd64.whl:

Publisher: publish.yml on sgt0/vapoursynth-fftspectrum-rs

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_fftspectrum_rs-1.0.13-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for vapoursynth_fftspectrum_rs-1.0.13-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 229738b5be3147cfdca9a1388c05c8f76e856a52a9b468f9e175970c7d83e4fc
MD5 35e7d7d5f983c215774e4a56bc462e34
BLAKE2b-256 c0856551be73450110449ac509b9f36d33458e48875dcfc27e570dcf4cc2502f

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_fftspectrum_rs-1.0.13-py3-none-manylinux_2_28_x86_64.whl:

Publisher: publish.yml on sgt0/vapoursynth-fftspectrum-rs

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_fftspectrum_rs-1.0.13-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for vapoursynth_fftspectrum_rs-1.0.13-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f6623874f4afa4cc24b853685c2c78d4e2e7e0028d54cb265764b1fbf174d978
MD5 fc2b9cdf5a9cc128e45fd3c0da69f2ff
BLAKE2b-256 7eb21a7b2cba6454c422863c2a351e5533e3d5114b5711d70b86f72beddaeef0

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_fftspectrum_rs-1.0.13-py3-none-manylinux_2_28_aarch64.whl:

Publisher: publish.yml on sgt0/vapoursynth-fftspectrum-rs

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_fftspectrum_rs-1.0.13-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for vapoursynth_fftspectrum_rs-1.0.13-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 31772ed484ec60e1c85a4f60adb7c401d4c295a283935086910c6e656f6670d0
MD5 08f618da4b190f8868262578002f2a49
BLAKE2b-256 bc3ff87efae03c8e204ff706ce04928979b53e48a91e4f498da98e6416b50d9e

See more details on using hashes here.

Provenance

The following attestation bundles were made for vapoursynth_fftspectrum_rs-1.0.13-py3-none-macosx_11_0_arm64.whl:

Publisher: publish.yml on sgt0/vapoursynth-fftspectrum-rs

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