Skip to main content

Add Degradations in VapourSynth

Mainly to generate datasets without the need for intermediates. Maybe useful to compare encoding settings.


Installation

pip install -U vs_degrade
  • Jpeg Degradation requires libjpeg-turbo (optional):
    Windows: Download & install libjpeg-turbo-X.X.X-vc-x64.exe
    Linux: Via package manager e.g. apt install libturbojpeg
  • FFmpeg Degradation requires ffmpeg (optional):
    Download and add to PATH, or set the path manually via the path parameter.

Jpeg Degradation

Degrades a YUV clip directly as is, without upsampling chroma or doing any format/color conversions, since Jpeg also works in YUV. Adds purely spatial compression artifacts very fast.

import vs_degrade
clip = vs_degrade.jpeg(clip, quality=50, fields=False, seed=0, planes=[0, 1, 2], path=None)

clip
Clip to degrade. Jpeg supports YUV420P8, YUV422P8, and YUV444P8 formats.

quality
Image quality in the range 1-100 with 1 being the worst.
Can be a constant value or randomized each frame by providing a range: quality=[30, 80]

fields (optional)
Will separate the clip into fields, degrade each field seperately, then put them back together.
This creates interlacing artifacts like combing and more mosquito noise.

seed (optional)
Seed used for quality randomization.

planes (optional)
Which planes to degrade. Any unmentioned planes will simply be copied.
If nothing is set, all planes will be degraded.

path (optional)
Path to libjpeg-turbo (turbojpeg.dll on Windows, libturbojpeg.so on Linux), if not auto-detected.


FFmpeg Degradation

Runs randomizable FFmpeg commands in chunks directly on a YUV clip as is, without upsampling chroma or doing any format/color conversions. Adds spatial and temporal compression artifacts.

import vs_degrade
clip = vs_degrade.ffmpeg(clip, temp_window=10, args="-c:v mpeg2video -q:v 10", fields=False, seed=0, planes=[0, 1, 2], path=None)

clip
Clip to degrade. Supports YUV420P8/P10, YUV422P8/P10, YUV444P8/P10 formats.

temp_window
Temporal window length. The amount of frames to encode at once.

args
The video encoding arguments of an FFmpeg command.

  • Simplest example using the MPEG-2 codec with quality 10:
    args = "-c:v mpeg2video -q:v 10"
    
  • Arguments can optionally be randomized per temporal window:
    {rand(5,50)} sets randomizer range for int values
    {randf(-0.5,0.9)} sets randomizer range for float values
    {choice(veryfast,medium,veryslow)} chooses randomly from a list
    Example using the H.264 codec with random crf and preset:
    args = "-c:v libx264 -crf {rand(5,50)} -preset {choice(veryfast,medium,veryslow)}"
    
  • Multiple full commands can be randomized per temporal window by providing a list:
    args = ["-c:v mpeg2video -q:v {rand(5,30)}",
            "-c:v libx264 -crf {rand(5,50)} -x264-params bframes={rand(0,16)}",
            "-c:v libx265 -crf {rand(5,50)} -preset {choice(veryfast,medium,veryslow)}",
            "-c:v libvpx-vp9 -crf {rand(5,60)} -b:v 0"]
    clip = vs_degrade.ffmpeg(clip, temp_window=10, args=args)
    
  • FFmpeg filters can also be applied. This one for example randomly sharpens before compressing:
    args = "-vf unsharp=5:5:{randf(0.0,1.0)} -c:v mpeg2video -q:v 10"
    
    This adds gibbs ringing and skips compression. {w} {h} gets the input dimensions:
    args = "-vf 'scale={w}*0.85:{h}*0.85:sws_flags=sinc,scale={w}:{h}:sws_flags=sinc' -c:v rawvideo"
    
  • You may want to add additional interlacing flags if fields=True, but it is not strictly necessary:
    args = "-c:v mpeg2video -q:v 10 -flags +ildct+ilme -top 1"
    

seed (optional)
Seed used ffmpeg args randomization.

fields (optional)
Will seperate the clip into fields, degrade with FFmpeg, then put them back together.
This creates interlacing artifacts like combing and more mosquito noise.

planes (optional)
Which planes to degrade. Any unmentioned planes will simply be copied.
If nothing is set, all planes will be degraded.

path (optional)
Path to FFmpeg (ffmpeg.exe on Windows, just ffmpeg on Linux), if not auto-detected.

Download files

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

Source Distribution

vs_degrade-1.2.0.tar.gz (293.9 kB view details)

Uploaded Source

Built Distribution

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

vs_degrade-1.2.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file vs_degrade-1.2.0.tar.gz.

File metadata

  • Download URL: vs_degrade-1.2.0.tar.gz
  • Upload date:
  • Size: 293.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for vs_degrade-1.2.0.tar.gz
Algorithm Hash digest
SHA256 e7dcde6b68d076365784f284532cd97bc190040b91dc15f0c510f461c9e0ed88
MD5 6df1ba4254a1c6446a35d798eecadc7e
BLAKE2b-256 b6a470f8e84cfb04a54e54c9a93258c5671fa8ac010bc3040da2da9ba46a6ef9

See more details on using hashes here.

Provenance

The following attestation bundles were made for vs_degrade-1.2.0.tar.gz:

Publisher: publish.yml on pifroggi/vs_degrade

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_degrade-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: vs_degrade-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for vs_degrade-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8d462f7ab15395eaf679d9c029758fa134cccb65ac525db425226d0f9ec31e34
MD5 201bc382fa78993aad6bbb566fe1b6fe
BLAKE2b-256 7c13f25e932cd2f7867f8da778e495dc20a2f8baf596b601b4e2f85404bd4433

See more details on using hashes here.

Provenance

The following attestation bundles were made for vs_degrade-1.2.0-py3-none-any.whl:

Publisher: publish.yml on pifroggi/vs_degrade

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

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 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