Skip to main content

vs-fgs

A VapourSynth plugin for applying Film Grain Synthesis' table (FGS) using the dav1d decoder.

Since dav1d is widely regarded as the best and fastest AV1 decoder available, its FGS engine is fully spec-compliant with AFGS1 (AOMedia Film Grain Synthesis 1), guaranteeing highly accurate, performant, and standardized grain generation.

vsfgs parses standard FGS text files and applies film grain to the input clip natively in 8-bit, 10-bit, or 12-bit YUV.

Why this plugin

Film Grain Synthesis (FGS) represents a massive step forward in video compression, allowing to model film grain mathematically rather than encoding random noise.

This plugin was built with two primary goals in mind:

  • Visualizing and Fine-Tuning FGS: It serves as a "real-time" visualization tool during your encoding pipeline. By rendering the grain dynamically, you can preview, adjust, and perfectly tune your FGS tables in relation to the actual video content (especially when paired with tools like FGSE).
  • Grain Baking: Not all target codecs (e.g. H.264, VP9, HEVC) support FGS playback, and you don't always want to distribute video files with separate grain metadata. vsfgs gives you the ability to bake the high-quality, standardized AFGS1 grain directly into the video stream before handing it off to your encoder.

Furthermore, this tool is future-proof for processing official AV1 streams (e.g. Netflix) that already have FGS embedded inside them, allowing you to seamlessly extract, visualize, or bake their grain during filtering and re-encoding.

Installation

pip install vsfgs

External Dependencies

To use the load_av1fgs_video function (which automatically extracts FGS data from a video file), you must have grav1synth installed and available in your system's PATH!

Usage

import vapoursynth as vs
import vsfgs

core = vs.core

# 1. Load an AV1 video and automatically apply its embedded Film Grain
# It will extract the FGS tables using grav1synth and map them perfectly to the decoded clip.
# 
# Indexers used:
# - fast=False (Default): Uses BestSource. Slower indexing, but guarantees perfect frame accuracy (recommended).
# - fast=True: Uses FFMS2. Faster indexing.
clip = vsfgs.load_av1fgs_video("source_av1.mkv", fast=False)

# 2. Manual FGS Application (Optional)
# If you already have your video clip and a separate grain table (.bin or .txt), you can apply it manually:
# - ignore_chroma: If True, grain is only applied to Luma (Chroma is copied).
# - static: If True, uses the seed from the FGS table for all frames (if dynamic FGS, per event). If False, rotates the seed for each frame. Note: for `.bin` files, dynamic_seed is disabled automatically.
# - simd: Hardware SIMD architecture ('auto', 'avx512', 'avx2', 'sse41', 'sse3', 'sse2', or 'none'/'c' for plain C). Defaults to 'auto'.
clip = vsfgs.apply_fgs(clip, "grain_table.bin", ignore_chroma=False, static=False, simd="auto")

clip.set_output()

For detailed parameter types, descriptions, and additional indexer arguments (idx_kwargs), check the function docstrings.

Frame Properties

For each processed frame, vsfgs outputs the exact seed integer used during synthesis into the VapourSynth frame properties: FGS_Seed

Input Format & Advanced Customization

vsfgs supports input grain files in both standard .txt (AFGS1 textual format) and directly compiled .bin (Binary format). It allows for extreme and advanced customization of the film grain synthesis pattern.

For complete details on the required text syntax, binary packing parameters, and an advanced visual editor to create and fine-tune these tables, please refer to the FGSEditor wiki: https://github.com/PingWer/FGSEditor

Technical & Implementation Notes

High Bit-Depth & Precision Preservation

The underlying dav1d FGS synthesis engine strictly operates on 8-bit, 10-bit, or 12-bit integer YUV clips. To support higher bit-depths (>12-bit integer or Float formats) without quality loss:

  • The input clip is temporarily converted to 12-bit integer using dither_type="none".
  • Film grain is synthesized at 12-bit depth.
  • The isolated grain pattern (delta) is extracted via MakeDiff, scaled back to match the original clip format, and applied onto the untouched original clip using MergeDiff.

This approach completely eliminates quantization and dithering alterations.

Indexer & Video Loader Flexibility

The load_av1fgs_video function is provided strictly as a convenience wrapper to automate video loading and FGS table extraction via grav1synth:

  • It indexes only the video stream (ignoring audio/subtitles).
  • You are not locked into using load_av1fgs_video. You can freely use any video loader or indexer of your choice (e.g. lsmas, d2vsource, manual BestSource/ffms2, etc.) to load your clip, and then call vsfgs.apply_fgs(clip, fgs_path) directly with any .txt or .bin grain table.

Performance & Compatibility

vsfgs uses dav1d's hand-written Assembly instructions (AVX-512, AVX2, SSE3 ...), resulting in extremely high throughput with almost zero overhead.

Platform Support:

OS Architecture Supported Tested
Windows x86_64, ARM64 ✅ ✅
Linux x86_64, aarch64 ✅ ❌
macOS x86_64, Apple Silicon ✅ ❌

Benchmark Comparison (2,000 frames of real 1080p source via BestSource): Tests compared vsfgs against Grainer.GAUSS (from vsjetpack). It also demonstrates the speedup of dav1d's hardware SIMD Assembly optimizations over unvectorized reference C code (simd='none').

Format Baseline (BestSource + 16bit conversion) vsfgs (SIMD: Auto / AVX-512) vsfgs (SIMD: None / Plain C) Grainer.GAUSS (vsjetpack)
YUV420P16 ~1128 FPS ~557 FPS ~514 FPS ~347 FPS
YUV422P16 ~866 FPS ~434 FPS ~425 FPS ~322 FPS
YUV444P16 ~649 FPS ~305 FPS ~299 FPS ~279 FPS

Building from Source

To compile the plugin manually, you must have a working C++ toolchain and Meson setup. The plugin depends on dav1d, which will be built automatically as a Meson subproject.

Prerequisites

  • Python 3.13+ (or newer)
  • C++ Compiler: GCC/Clang (Linux/macOS) or MSVC (Windows)
  • Meson & Ninja: Build system (pip install meson ninja)
  • nasm: Highly recommended for x86/x64 systems to enable dav1d assembly optimizations (drastically improves grain synthesis performance).
    • Windows: choco install nasm
    • Linux: sudo apt-get install nasm or sudo dnf install nasm
    • macOS: brew install nasm

Build Steps

  1. Clone the repository recursively to fetch the dav1d submodule:

    git clone --recursive https://github.com/PingWer/vs-fgs.git
    cd vs-fgs
    
  2. Build and install the plugin directly into your active Python environment:

    pip install .
    

Standalone Build (Without Python Installation)

If you only want to compile the VapourSynth plugin binary (DLL/SO/DYLIB) without installing it via pip, you can use Meson directly:

meson setup build --buildtype=release --vsenv
meson compile -C build

TODO

Any suggestions are welcome! But, the plugin is basically feature complete.

Community & Support

For questions, feedback, or troubleshooting, feel free to join and reach out on the AV1 Weeb edition Discord server

License

This project is licensed under the MIT License.

Third-Party Licenses

This project includes and statically links code from dav1d (located in subprojects/dav1d), which is licensed under the BSD 2-Clause License:

Copyright © 2018-2025, VideoLAN and dav1d authors. All rights reserved.
Licensed under the BSD 2-Clause License.

Metadata

Release files for vsfgs 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vsfgs 0.7.0
File Size Uploaded
vsfgs-0.7.0.tar.gz 1.7 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for vsfgs 0.7.0
File
vsfgs-0.7.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details
vsfgs-0.7.0-py3-none-musllinux_1_2_x86_64.whl Python 3 none Linux musl 1.2+ x86-64 Details
vsfgs-0.7.0-py3-none-musllinux_1_2_aarch64.whl Python 3 none Linux musl 1.2+ ARM64 Details
vsfgs-0.7.0-py3-none-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details
vsfgs-0.7.0-py3-none-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl Python 3 none Linux glibc 2.24+ ARM64, Linux glibc 2.28+ ARM64 Details
vsfgs-0.7.0-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details
vsfgs-0.7.0-py3-none-macosx_10_13_x86_64.whl Python 3 none macOS 10.13+ x86-64 Details

Total release size: 4.3 MB

Release files / vsfgs-0.7.0.tar.gz

Download URL vsfgs-0.7.0.tar.gz
Size 1.7 MB
Tags Source
SHA-256 checksum
How to use checksums
f873fa5f664b6ea969e9cdfc948634d0cdac31636c9bc6f6720de19fc68f117c
BLAKE2b-256 checksum
How to use checksums
b74bfd3d88dd0d2eca38e757ab6c1dd36eefac59c3e4c8e5d618cd3f6c1f3479
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.

Transparency log

Release files / vsfgs-0.7.0-py3-none-win_amd64.whl

Download URL vsfgs-0.7.0-py3-none-win_amd64.whl
Size 82.6 kB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
86c727ee54133bcb598772c290d8cd54096eb38b6bcce241f243fe80b716f057
BLAKE2b-256 checksum
How to use checksums
5fa491fb90d99d60bbb3db425c1de72eb885e06d1ecf03fca4902d9f940079df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.

Transparency log

Release files / vsfgs-0.7.0-py3-none-musllinux_1_2_x86_64.whl

Download URL vsfgs-0.7.0-py3-none-musllinux_1_2_x86_64.whl
Size 1.1 MB
Tags Linux musl 1.2+ x86-64 Python 3
SHA-256 checksum
How to use checksums
b0787f0fff5fed59d7475e0849f6cdb15ee8b55cee46074fd8692eb41816ae86
BLAKE2b-256 checksum
How to use checksums
a024c80aa7f23102a8f76c6c694dcba3b285ed28d3249bdb5a2b8dbdc3c5eb63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.

Transparency log

Release files / vsfgs-0.7.0-py3-none-musllinux_1_2_aarch64.whl

Download URL vsfgs-0.7.0-py3-none-musllinux_1_2_aarch64.whl
Size 1.0 MB
Tags Linux musl 1.2+ ARM64 Python 3
SHA-256 checksum
How to use checksums
123c2ffaa0ba10b65ea19badd09b101be11e19f9ae4befd8bc5c22744ffb3899
BLAKE2b-256 checksum
How to use checksums
e3a0c3227f4b8d2af4649b8c151894355adb2c22486cbd2a6ea0d32e5ef3e607
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.

Transparency log

Release files / vsfgs-0.7.0-py3-none-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL vsfgs-0.7.0-py3-none-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 100.0 kB
Tags Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
8df078ad3d668df02e9fb0bc8533042a02eda486f3e44b3c9e809425b397d9a8
BLAKE2b-256 checksum
How to use checksums
30f35e2955d6efae104cdcebc12217f8ed81829ec034b77c3fc5b1e17f746673
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.

Transparency log

Release files / vsfgs-0.7.0-py3-none-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl

Download URL vsfgs-0.7.0-py3-none-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Size 60.6 kB
Tags Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
319a65380b7b9948d9583cd36243525a244dcefae1a61042c9a7448c06d38f46
BLAKE2b-256 checksum
How to use checksums
31df88aee794276455fc4d7b84de38b76e6df1cba2d0515a9d973aabadf68c94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.

Transparency log

Release files / vsfgs-0.7.0-py3-none-macosx_11_0_arm64.whl

Download URL vsfgs-0.7.0-py3-none-macosx_11_0_arm64.whl
Size 57.5 kB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
772920c7971298d7236ff8661a2c357bb0116237cbcfdd7936ef4864974fbf6d
BLAKE2b-256 checksum
How to use checksums
ba98cba0d08afcb7ddc030b33edadfe28c1ec898a08348276bc6b19b700230fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.

Transparency log

Release files / vsfgs-0.7.0-py3-none-macosx_10_13_x86_64.whl

Download URL vsfgs-0.7.0-py3-none-macosx_10_13_x86_64.whl
Size 84.9 kB
Tags Python 3 macOS 10.13+ x86-64
SHA-256 checksum
How to use checksums
6288263151858477b7a89a55150f3c5a5d20b34cc992fca3dc56fb95ab9a3555
BLAKE2b-256 checksum
How to use checksums
584f411043efd9ae2e8ad060d1192071e7e331c3d92c2ea61ef650edac2b4ec0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.

Transparency log

Release history Release notifications | RSS feed

1.1.0

8 release files

This release

0.7.0 This release

8 release files

0.6.0

15 release files

0.5.1

15 release files

0.5.0

15 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page