Mainly to generate datasets without the need for intermediates. Maybe useful to compare encoding settings.
- libjpeg-turbo (optional)
- Windows: Download & install
libjpeg-turbo-X.X.X-vc-x64.exe
Linux: Via package manager e.g.apt install libturbojpeg - And install python packages via
pip install PyTurboJPEG numpy
- Windows: Download & install
- ffmpeg (optional)
- Download and add to PATH, or put into your vapoursynth folder.
You have probably already done that. - And install a python package via
pip install numpy
- Download and add to PATH, or put into your vapoursynth folder.
Put the vs_degrade.py file into your vapoursynth scripts folder.
Or install via pip: pip install -U git+https://github.com/pifroggi/vs_degrade.git
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 and is very fast.
import vs_degrade
clip = vs_degrade.jpeg(clip, quality=50, fields=False, 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.
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.
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, 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:
This adds gibbs ringing and skips compression.
args = "-vf unsharp=5:5:{randf(0.0,1.0)} -c:v mpeg2video -q:v 10"
{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"
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.