Skip to main content

Vapoursynth functions to generate realistic film grain (via fgrain) and for overlaying external grain clips.

Project description

Grain Overlay and Generate functions for VapourSynth


Installation

pip install -U vs_grain

For older vapoursynth versions below R74, follow the manual installation steps here.


Generate Realistic Film Grain

Helper function for the very realistic grain generator fgrain that animates the grain, adds opacity options, and support for YUV. Grain is only applied to luma. Requires an Nvidia GPU.

import vs_grain
clip = vs_grain.fgrain(clip, iterations=800, size=0.3, deviation=0.0, blur=0.8, opacity=[0.5, 0.5, 0.5], num_streams=1)

clip
Clip to apply grain to.
Must be in YUV or GRAY format.

iterations
Higher values look more realistic. Lower values are faster but result in grain that looks less natural.

size
Average size of grain particles.

deviation
Deviation of size, or how much variation there is in the size of grain particles. High values can cause bad outputs, use with caution.

blur
Generates smoother grain.

opacity
Opacity of generated grain. Can be a list [0.5, 1.0, 0.5] for shadows/midtones/highlights, or a single value for everything.

num_streams
Number of parallel GPU streams. For high end GPUs higher can be a bit faster, but requires more VRAM.

[!TIP] If fgrain is too slow for you, try generating a short grain clip on neutral mid-gray background and then use the overlay function to apply it to the whole clip.


Overlay Grain Clip

Bring your own grain clip and overlay it on top of your base clip. This automatically loops the grain clip, crops if too large or stacks if too small.

import vs_grain
clip = vs_grain.overlay(clip, grain, blend_mode="overlay", size=1.0, blur=0.0, opacity=[1.0, 1.0, 1.0], planes=[0, 1, 2])

clip
Clip to apply grain to.
Must be in YUV or GRAY format.

grain
Grain clip to overlay. This is expected to be grain on a neutral mid-gray background.
Must be the same format as the base clip.

blend_mode
Method used to blend the grain clip with the base clip. Available blend modes:

  • grainshow Shows the grain without blending.
  • grainmerge Grain is applied everywhere with the same impact.
  • grainextract Inverse of grainmerge. Removes grain added via grainmerge.
  • overlay Grain has strongest impact in midtones and fades toward shadows/highlights.
  • hardlight Opposite of overlay, meaning grain gets stronger toward shadows/highlights.
  • softlight Similar to overlay, but dark grains get weaker in shadows and bright grains get weaker in highlights.
  • vividlight Dark grains get stronger in shadows and bright grains get stronger in highlights.

size
Multiplicator to resize grain clip. Will automatically crop if too large or repeat if too small.

blur
Smoothes the grain by blurring the grain clip.

opacity
Opacity of grain clip. Can be a list [0.5, 1.0, 0.5] for shadows/midtones/highlights, or a single value for everything.

planes
Which planes should be affected by the grain clip. Any unmentioned planes will simply be copied.
If nothing is set, the grain will be applied to all planes.

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

vs_grain-2.1.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

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

vs_grain-2.1.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file vs_grain-2.1.0.tar.gz.

File metadata

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

File hashes

Hashes for vs_grain-2.1.0.tar.gz
Algorithm Hash digest
SHA256 276d5224de4bb39a11595c705a65604b79023d70ba3f5b2da57c5af37e752e3a
MD5 d90c1ba0ab1c184d8a83f2c68a2eaa52
BLAKE2b-256 e7015ba3cafac14cb13c4b405706c9a7c0ce085381479ef82ad61fb5711d0daa

See more details on using hashes here.

Provenance

The following attestation bundles were made for vs_grain-2.1.0.tar.gz:

Publisher: publish.yml on pifroggi/vs_grain

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

File details

Details for the file vs_grain-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: vs_grain-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for vs_grain-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6323bb6acb14a9f2eea495bd305dec931618f3d94b62ffb1555c006df875d43c
MD5 563132b4bd7ffcb338d22420c3b9ad73
BLAKE2b-256 e1248e4f61fe0c7edd0ad9caf2bbd08f50daa9e0e4ec05d261029e35a5c4ff2d

See more details on using hashes here.

Provenance

The following attestation bundles were made for vs_grain-2.1.0-py3-none-any.whl:

Publisher: publish.yml on pifroggi/vs_grain

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