Skip to content

Vapoursynth wrapper for fgrain and helper for overlaying external grain clips.

License

Notifications You must be signed in to change notification settings

pifroggi/vs_grain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Grain Overlay and Generate functions for Vapoursynth

Requirements

Setup

Put the vs_grain.py file into your vapoursynth scripts folder.
Or install via pip: pip install git+https://github.com/pifroggi/vs_grain.git


Generate Realistic Film Grain

Simple helper function for the very realistic grain generator fgrain that animates the grain, adds opacity option, and support for YUV. Requires an Nvidia GPU.

import vs_grain
clip = vs_grain.fgrain(clip, iterations=800, size=0.5, deviation=0.0, blur_strength=0.9, opacity=0.1)

clip
Clip to apply grain to.
Must be in YUV444PS or GRAYS format.

iterations
Higher values look more realistic. Lower values speed up the processing time but result in grain that looks less natural.
Originally called "num_iterations" in fgrain.

size
Average size of the grain particles.
Originally called "grain_radius_mean" in fgrain.

deviation
Standard deviation of size, which dictates how much variation there is in the size of the grain particles.
Originally called "grain_radius_std" in fgrain.

blur_strength
Generates smoother grain. This is not really a blur, but it has a similar effect.
Originally called "sigma" in fgrain.

opacity
Opacity of generated grain.

Overlay Grain Clip

Set your own grain clip and overlay it on top of your base clip. This automatically loops the grain clip, crops it if it is too large and repeats it if it is too small.

import vs_grain
clip = vs_grain.overlay(clip, grain, blend_mode='overlay', size=1.0, blur_strength=0, opacity=1.0)

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

grain
Grain clip to overlay.
Must be in YUV format.

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

blur_strength
Smoothes the grain by blurring the grain clip.

opacity
Opacity of grain clip.

blend_mode
Method used to blend the grain clip with the base clip. Blend functions are from havsfunc by HolyWu.
Available blend modes:

  • overlay
  • hardlight
  • linearlight
  • softlight
  • vividlight
  • grainmerge
  • grainextract
  • average
  • normal

Tips & Troubleshooting

If fgrain is too slow for you, try generating a short grain clip on gray background and then use vs_grain.overlay with blend_mode="grainmerge" to apply it to the whole clip.

About

Vapoursynth wrapper for fgrain and helper for overlaying external grain clips.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages