View Full Version : how to filter video in 16bit and dither?
gugglu
8th March 2019, 23:44
hi there folks , i am having a problem with dark scene in video , i tried GradFun3 / Fag3kdb / mf3kdb / f3kdb i don't know much filtering in Vapoursynth so if someone would be kind enough to help me out with improving my script for the correct result would be so much appreciated .
Vapoursynth current script:
import vapoursynth as vs
import muvsfunc as muf
import havsfunc as hvf
core = vs.core
clip = core.d2v.Source(r'C:\Users\Kalik\Videos\vids\VTS_02_1.VOB.d2v')
clip = core.vivtc.VFM(clip,mode=5,order=1).vivtc.VDecimate()
clip = core.std.Trim(clip,29341,31200)
res = core.fmtc.resample (clip, w=720, h=480)
deg = hvf.SMDegrain(res,tr=3,blksize=8,overlap=4,prefilter=4,RefineMotion=True,chroma=True)
dbd = core.f3kdb.Deband(deg,preset='veryhigh', dither_algo=3, output_depth=16)
sse = muf.SeeSaw(res,dbd)
clip = core.fmtc.bitdepth (clip=sse, bits=10)
clip.set_output ()
any help would be helpful ans much appreciated.
ChaosKing
9th March 2019, 00:40
You could put a clip = mvf.Depth(clip, 16) after your trim so everything after this will be filtered in 16bit.
Don't forget a import mvsfunc as mvf
gugglu
9th March 2019, 11:50
You could put a clip = mvf.Depth(clip, 16) after your trim so everything after this will be filtered in 16bit.
Don't forget a import mvsfunc as mvf
Hi C.K thanks for showing up mate. i am going to do some test today and will be back soon after i doing some practice and test. tho i am newbie nob in Vapoursynth but i will try my best to learn. thanks again C.K,good day sarge.
ChaosKing
9th March 2019, 11:57
How about like this?
import vapoursynth as vs
import muvsfunc as muf
import havsfunc as hvf
import mvsfunc as mvf
core = vs.core
clip = core.d2v.Source(r'C:\Users\Kalik\Videos\vids\VTS_02_1.VOB.d2v')
clip = core.vivtc.VFM(clip,mode=5,order=1).vivtc.VDecimate()
clip = core.std.Trim(clip,29341,31200)
clip = mvf.Depth(clip, 16) # we want to filter in 16 bit
deg = hvf.SMDegrain(clip,tr=3,blksize=8,overlap=4,prefilter=4,RefineMotion=True,chroma=True)
sse = muf.SeeSaw(res,deg )
clip = core.fmtc.resample (sse , w=720, h=480)# I would resize after denoising etc.
clip = core.f3kdb.Deband(clip ,preset='veryhigh', dither_algo=3, output_depth=10) # final output in 10bit
clip.set_output()
gugglu
9th March 2019, 13:21
How about like this?
import vapoursynth as vs
import muvsfunc as muf
import havsfunc as hvf
import mvsfunc as mvf
core = vs.core
clip = core.d2v.Source(r'C:\Users\Kalik\Videos\vids\VTS_02_1.VOB.d2v')
clip = core.vivtc.VFM(clip,mode=5,order=1).vivtc.VDecimate()
clip = core.std.Trim(clip,29341,31200)
clip = mvf.Depth(clip, 16) # we want to filter in 16 bit
deg = hvf.SMDegrain(clip,tr=3,blksize=8,overlap=4,prefilter=4,RefineMotion=True,chroma=True)
sse = muf.SeeSaw(res,deg )
clip = core.fmtc.resample (sse , w=720, h=480)# I would resize after denoising etc.
clip = core.f3kdb.Deband(clip ,preset='veryhigh', dither_algo=3, output_depth=10) # final output in 10bit
clip.set_output()
hi C.K thanks for your time man, example script is looking good ,going to test it will be back in a short while. :thanks:
gugglu
10th March 2019, 04:11
Hello C.K, after doing some practicing i found the script is working as i except but had to seesaw to lower it effect. here is a encoded clip, i am leaving a link please have a look pls, thank you for the help , very much appreciated C.K.
used x265-10bit crf 18 for testing some small BD_1080p clip
https://mega.nz/#!zyoFECqL!WfkbhGCVJWY8S82drpAlnVGXW2FS2j83FRyadOABJGw
sorry man can you help me start this function so i can try it and see it effect, i was getting an error
kagefunc.adaptive_grain(clip,strength=0.30)
Traceback (most recent call last):
File "src\cython\vapoursynth.pyx", line 1927, in vapoursynth.vpy_evaluateScript
File "src\cython\vapoursynth.pyx", line 1928, in vapoursynth.vpy_evaluateScript
File "", line 19, in
File "C:\Users\Kalik\Pictures\VapourSynth64Portable\Scripts\kagefunc.py", line 173, in adaptive_grain
for y in np.arange(0, 1, 0.001):
AttributeError: module 'numpy' has no attribute 'arange'
:thanks:
ChaosKing
10th March 2019, 11:26
Is numpy installed? And how did you install it?
gugglu
10th March 2019, 11:52
Is numpy installed? And how did you install it?
Hi C.K,
Sorry mate, numpy is not installed [i just got your Vapoursynth FATPACK]. how to install it any clue? do i have to install python before installing numpy?
gugglu
10th March 2019, 12:52
Is numpy installed? And how did you install it?
just installed numpy scipy matplotlib and copied those numpy folder from "C:\Users\kalki\AppData\Roaming\Python\Python37\site-packages" to your Vapoursynth FATPACK location "C:\Users\Kalik\Desktop\VapourSynth64Portable\VapourSynth64\Lib\site-packages"
and it is working flawlessly now. Btw how was that encoded video good or bad ?
bin.n2f
10th March 2019, 14:49
Is numpy installed? And how did you install it?
where to get numpy scripts? iam getting errors cause of it
:thanks:
ChaosKing
10th March 2019, 15:54
You can install it via pip: python.exe -m pip install numpy
(make sure you are in the correct dir)
Or wait a bit. I will release propably today a new version of the vs portable fatpack with numpy.
@gugglu the encode looks good to me.
gugglu
10th March 2019, 16:35
You can install it via pip: python.exe -m pip install numpy
(make sure you are in the correct dir)
Or wait a bit. I will release propably today a new version of the vs portable fatpack with numpy.
@gugglu the encode looks good to me.
thank you C.K, i think i can encode that video really thank you very much for correcting the script and special thanks for the Vapoursynth FATPACK wonderful work man. Awesome idea that would be great if u add numpy to it so no need to install it when it comes with your [/b]Vapoursynth FATPACK[/b].
actually i installed numpy using pip on my laptop and it worked . here is what i did cmd
C:\Users\Kalik\AppData\Local\Programs\Python\Python37\Scripts>cmd
Microsoft Windows [Version 10.0.17763.316]
(c) 2018 Microsoft Corporation. All rights reserved.
C:\Users\Kalik\AppData\Local\Programs\Python\Python37\Scripts>pip install numpy
Requirement already satisfied: numpy in c:\users\kalik\appdata\roaming\python\python37\site-packages (1.16.2)
You are using pip version 10.0.1, however version 19.0.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
C:\Users\Kalik\AppData\Local\Programs\Python\Python37\Scripts>pip install scipy
Requirement already satisfied: scipy in c:\users\kalik\appdata\roaming\python\python37\site-packages (1.2.1)
Requirement already satisfied: numpy>=1.8.2 in c:\users\kalik\appdata\roaming\python\python37\site-packages (from scipy) (1.16.2)
You are using pip version 10.0.1, however version 19.0.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
C:\Users\Kalik\AppData\Local\Programs\Python\Python37\Scripts>pip install matplotlib
Requirement already satisfied: matplotlib in c:\users\kalik\appdata\roaming\python\python37\site-packages (3.0.3)
Requirement already satisfied: numpy>=1.10.0 in c:\users\kalik\appdata\roaming\python\python37\site-packages (from matplotlib) (1.16.2)
Requirement already satisfied: kiwisolver>=1.0.1 in c:\users\kalik\appdata\roaming\python\python37\site-packages (from matplotlib) (1.0.1)
Requirement already satisfied: cycler>=0.10 in c:\users\kalik\appdata\roaming\python\python37\site-packages (from matplotlib) (0.10.0)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in c:\users\kalik\appdata\roaming\python\python37\site-packages (from matplotlib) (2.3.1)
Requirement already satisfied: python-dateutil>=2.1 in c:\users\kalik\appdata\roaming\python\python37\site-packages (from matplotlib) (2.8.0)
Requirement already satisfied: setuptools in c:\users\kalik\appdata\local\programs\python\python37\lib\site-packages (from kiwisolver>=1.0.1->matplotlib) (39.0.1)
Requirement already satisfied: six in c:\users\kalik\appdata\roaming\python\python37\site-packages (from cycler>=0.10->matplotlib) (1.12.0)
You are using pip version 10.0.1, however version 19.0.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
Blue = installing cmd
Red = folder i copied to VS.FATPACK
green = i didn't copied them VS.FATPACK
but hold on when i tried same way on my desktop pc it didn't worked i have had to copy the vapoursynth FATPACK and the C:\Users\Kalik\AppData\Roaming\Python and paste it to same location on desktop, then it worked, but i am not that good i can caught the pulse which got rid of the error but it was so much confusing man i never used python before, just today after reading your post when you said have you installed numpy :D encouraged me to read about numpy i was thinking u were talking muvsfunc_numpy but when i googled it made me laugh when i found it is not a script it is kind a package need to be install via python then i started digging deep into.
and one last thing if you can i would like to use SMDegrain(clip,mfilter=?) i tried writing one in avisynth but i never had someone to help me with the code now as we got the same option in VapourSynth can you pls type me something which will be suitable for mfilter in SMDegrain
ChaosKing
10th March 2019, 18:27
I never used mfilter but here's an example https://forum.doom9.org/showthread.php?p=1727653#post1727653
(search for mfilter) http://avisynth.nl/index.php/SMDegrain#Ready-to-run_Samples
Motion Filter, an optional user-supplied clip that will be passed through those areas where SMDegrain() couldn't find a matching block, normally high motion areas. One use for it would be to to use spatial filters, like deblockers or blurring filters that mimic motion blur.
gugglu
15th March 2019, 13:32
I never used mfilter but here's an example https://forum.doom9.org/showthread.php?p=1727653#post1727653
(search for mfilter) http://avisynth.nl/index.php/SMDegrain#Ready-to-run_Samples
Hi C.K ,thanks for pointing that out my friend i will look into it.
btw result with your are better than what i was doing earlier, but banding problem still exist i don't know what is happening in Vapoursynth hood. i used your script but banding is not going away and i am not happy with the result i get(maybe this don't sound good to users but i m having a weird problem i want to solve), i like to improve the script for removing noise & color banding.
like this thread >https://forum.doom9.org/showthread.php?p=1386559#post1386559
here is a script from u i used to encode
import vapoursynth as vs
import muvsfunc as muf
import havsfunc as hvf
import mvsfunc as mvf
core = vs.core
clip = core.lsmas.LWLibavSource(r'C:\Users\Kalik\Videos\BluRay_DVD.d2v')
clip = core.std.Crop(clip, 0,0,136,136)
bit = mvf.Depth(clip, 16) # we want to filter in 16 bit
deg = hvf.SMDegrain(bit, tr=3,blksize=16,overlap=8,prefilter=4,RefineMotion=True,chroma=True,Str=1.06,Amp=0.0625)
sse = muf.SeeSaw(bit,deg, Sstr=1.35,ssx=1.25,ssy=1.25 )
res = core.fmtc.resample(sse, w=1920, h=808)# I would resize after denoising etc.
deb = core.f3kdb.Deband(res, keep_tv_range=True, preset='veryhigh', dither_algo=3, output_depth=10) # final output in 10bit
deb.set_output()
here is encoded sample:
https://mega.nz/#!i6wS3AjA!L-NxgJ0XYjH-aUgTmSmMCZNqytVEl4g1NtoUG7NSn1M
https://mega.nz/#!TzogEYBb!HJusUBu1k3H6qFW7EE3pKioRLIWE9uGY4ioTeAfmML8
https://mega.nz/#!3rhU0KAA!hAdx56PSFoWvK1L_6RJAbEXnYGTvz8oJEVcoLXdj7e0
here is scrn.shot of problem below
https://lookimg.com/image/jMlEr
https://lookimg.com/image/jMXxW
https://lookimg.com/image/jMjMh
https://lookimg.com/image/jMCPj
https://lookimg.com/image/jMWho
please if you can help C.K,here are some sample from untouched BluRay
https://mega.nz/#!vmoSUI6L!GKGlD2fEawXiil29dAOSEIRWJMJhWqYYfRgNeCWQsWE
https://mega.nz/#!nroGSSrD!R8dOl0C_5kaAqLPZlar-zHs0kkkOsXHSXnQ_iEmjczw
https://mega.nz/#!77p0hIYI!ic_t32z5TFnplqaG4wAqA1mcvYPTw9oHt7B6NaMyD5U
:thanks: for the new VapourSynth FATPACK, wonderful work C.K
ChaosKing
16th March 2019, 22:08
The banding seems to appear mostly after the encode.
You have a couple of options:
- dither_algo=2 seems to help a bit.
- higher --aq-strength and/or psy-rd values (I tried this --crf 18 --preset medium --tune grain --aq-mode 3 --aq-strength 1.8 --output-depth 10 --no-strong-intra-smoothing --no-sao)
- Higher grain/debanding for specific scenes: example for the Sun opening
import fvsfunc as fvf
deb_strong = core.f3kdb.Deband(res, keep_tv_range=True, range=20, y=110, cb=150, cr=150, grainy=110, preset='veryhigh', dither_algo=3, output_depth=10)
deb = core.f3kdb.Deband(res, keep_tv_range=True, preset='veryhigh', dither_algo=3, output_depth=10) # final output in 10bit
deb = fvf.ReplaceFrames(deb, deb_strong, mappings="[0 380]") # mappings="[startframe1 endframe1][start2 end2][etc...]"
gugglu
17th March 2019, 15:44
The banding seems to appear mostly after the encode.
You have a couple of options:
- dither_algo=2 seems to help a bit.
- higher --aq-strength and/or psy-rd values (I tried this --crf 18 --preset medium --tune grain --aq-mode 3 --aq-strength 1.8 --output-depth 10 --no-strong-intra-smoothing --no-sao)
- Higher grain/debanding for specific scenes: example for the Sun opening
import fvsfunc as fvf
deb_strong = core.f3kdb.Deband(res, keep_tv_range=True, range=20, y=110, cb=150, cr=150, grainy=110, preset='veryhigh', dither_algo=3, output_depth=10)
deb = core.f3kdb.Deband(res, keep_tv_range=True, preset='veryhigh', dither_algo=3, output_depth=10) # final output in 10bit
deb = fvf.ReplaceFrames(deb, deb_strong, mappings="[0 380]") # mappings="[startframe1 endframe1][start2 end2][etc...]"
Hi C.K thanks for the idea will give it a go , but i think the problem is related to BitDepth Conversation in my script thats needs to be correcting as well i think i may have to remove minblur and masktools diff stuff from the script, here is another approach tried lowering the banding i've putt on to the scrn.shot comparison and i have modified the script as well but still not sure am i dithering it correctly or not but it does look slightly better then before take a look here C.K http://screenshotcomparison.com/comparison/132267
import vapoursynth as vs
import Dither as dif
import fvsfunc as fvf
import mvsfunc as mvf
import muvsfunc as muf
import havsfunc as hvf
import kagefunc as kgf
core = vs.core
core.max_cache_size=15360
clip = core.lsmas.LWLibavSource(r'C:\Users\Kalik\Videos\BluRay_DVD.mkv.lwi)
clip = core.std.Crop(clip, 0,0,136,136)
bit = fvf.Depth(clip, 16) # we want to filter in 16 bit
mb = hvf.Minblur(bit)
mt = core.avs.mt_adddiff(bit,core.avs.makediff(mb,core.rgvs.RemoveGrain(4)))
deg = hvf.SMDegrain(mt, blksize=16, overlap=8, prefilter=4, chroma=True)
sse = muf.SeeSaw(bit,deg,ssx=1.25,ssy=1.25 )
deb = GradFun3(sse,mode=3)
dit = mvf.Depth(deb,dither=3)#replaced from top to middle
dif = dif.limit_dif16(bit,dit,thr=1.00,elast=2.00)
ref = dif
deb2 = dif.f3kdb.Deband(preset='veryhigh', keep_tv_range=True, range=18, grainy=0, grainc=0, dither_algo=2, output_depth=16)
mask = kgf.retinex_edgemask(ref).std.Inflate()
merg = core.std.MaskedMerge(out,ref,mask)
adgr = kgf.adaptive_grain(merg,0.20)
final = fvf.Depth(adgr,10)#Down to 10bit and Dither
final.set_output()
C.K pls check the script and see if it needs any sort a correction,i m still kind a learner. :thanks:
ChaosKing
17th March 2019, 16:11
The encoding settings are also important. Psy and aq can also have a big effect on gradients and dark scenes.
Boulder
19th March 2019, 04:48
It would be better to feed the encoder with 16-bit data and let it dither down to the final bitdepth. From what I remember, x265 will internally work in 16 bits anyway.
gugglu
21st March 2019, 15:14
The encoding settings are also important. Psy and aq can also have a big effect on gradients and dark scenes.
Thanks C.K this does improve things, much appreciate that. i don't use much of the cli option except these --level-idc 4.1 --me 3 --subme 3 --rd 3 --b-intra --weightb --aq-motion --no-strong-intra-smoothing --ref 4 --bframes 5 --rc-lookahead 80result looks nice to my eyes . Reason i used Uniformed --aq-mode 1 because there is a F3kdb in the script that does kind a same favor as aq-mode 3 Auto variance with bias to dark area also i used knlmeansCL as a prefilter in SMDegrain which also do the good job in dark area, result are nicer than before.
:thanks:
It would be better to feed the encoder with 16-bit data and let it dither down to the final bitdepth. From what I remember, x265 will internally work in 16 bits anyway.
Hi Boulder,
thanks for the tip this also helped i removed a dither = fvf.Depth(final,10) and added this line to F3kdb output_depth
input.format.bits_per_sample , as you said , i just fed the 16bit -data to x265 does the trick improved the dark areas scene.
:thanks:
i need bit more help i don't know much of the Vapoursynth but i need help on syntax as you can see from my experience above (lol) i m not able to do it.
Can someone please convert this lut formula for noise into Vapoursynth Format, bunch of thanks C.K 'and' Boulder
Code1:
s_str = 1.2
s_reverse = s_str + 0.25
s_divisor = 1.5
s_indexR = 1.281
sstring = "x 128 - abs "+String(s_divisor)+" / 1 "+String(s_indexR)+" / ^ "+String(s_str)+" * x 128 - x 128 - abs 0.001 + / * x 128 - 2 ^ x 128 - 2 ^ "+String(s_reverse)+" + / * 128 +"
mt_lut(sstring, U=1, V=1)
code 2:
mt_lutxy(clip1, clip2, "x 128 - abs y 128 - abs < x y ?", U=1, V=1)
code 3:
mt_lutxy(clip1, clip2, "x y != 255 0 ?", U=1, V=1)
.
gugglu
21st March 2019, 16:28
Can someone please convert this lut formula for noise into Vapoursynth Format, bunch of thanks C.K 'and' Boulder
Code1:
s_str = 1.2
s_reverse = s_str + 0.25
s_divisor = 1.5
s_indexR = 1.281
sstring = "x 128 - abs "+String(s_divisor)+" / 1 "+String(s_indexR)+" / ^ "+String(s_str)+" * x 128 - x 128 - abs 0.001 + / * x 128 - 2 ^ x 128 - 2 ^ "+String(s_reverse)+" + / * 128 +"
mt_lut(sstring, U=1, V=1).
Hi i tried myself a making things works so for i got below code to work in Vapoursynth but not sure tho is it correct or not please check and correct if needs to be.
:thanks:
s_str = 1.2
s_reverse = s_str + 0.25
s_divisor = 1.5
s_indexr = 1.281
sstring = 'x 128 - abs '+'{s_divisor}'+' / 1 '+'{s_indexr}'+' / ^ '+'{s_str}'+' * x 128 - x 128 - abs 0.001 + / * x 128 - 2 ^ x 128 - 2 ^ '+'{s_reverse}'+' + / * 128 +'
mt_lut(sstring, U=1, V=1)
ChaosKing
25th March 2019, 01:47
It would be better to feed the encoder with 16-bit data and let it dither down to the final bitdepth. From what I remember, x265 will internally work in 16 bits anyway.
Thats good to know :thanks:
s_str = 1.2
s_reverse = s_str + 0.25
s_divisor = 1.5
s_indexr = 1.281
sstring = 'x 128 - abs '+'{s_divisor}'+' / 1 '+'{s_indexr}'+' / ^ '+'{s_str}'+' * x 128 - x 128 - abs 0.001 + / * x 128 - 2 ^ x 128 - 2 ^ '+'{s_reverse}'+' + / * 128 +'
mt_lut(sstring, U=1, V=1)
Sorry can't help you with Expr()
But maybe this can help: https://github.com/darealshinji/vapoursynth-plugins/blob/master/scripts/dehalo_alpha.py#L33
https://github.com/darealshinji/vapoursynth-plugins/blob/master/scripts/fastlinedarken.py#L19
WolframRhodium
25th March 2019, 03:15
Can someone please convert this lut formula for noise into Vapoursynth Format, bunch of thanks C.K 'and' Boulder
Code1:
s_str = 1.2
s_reverse = s_str + 0.25
s_divisor = 1.5
s_indexR = 1.281
sstring = "x 128 - abs "+String(s_divisor)+" / 1 "+String(s_indexR)+" / ^ "+String(s_str)+" * x 128 - x 128 - abs 0.001 + / * x 128 - 2 ^ x 128 - 2 ^ "+String(s_reverse)+" + / * 128 +"
mt_lut(sstring, U=1, V=1)
code 2:
mt_lutxy(clip1, clip2, "x 128 - abs y 128 - abs < x y ?", U=1, V=1)
code 3:
mt_lutxy(clip1, clip2, "x y != 255 0 ?", U=1, V=1)
.
Code1:
s_str = 1.2
s_reverse = s_str + 0.25
s_divisor = 1.5
s_indexR = 1.281
sstring = f"x 128 - abs {s_divisor} / {1 / s_indexR} pow {s_str} * x 128 - dup abs 0.001 + / * x 128 - 2 pow dup {s_reverse} + / * 128 +"
last = core.std.Expr(last, sstring if last.format.color_family == vs.GRAY else [sstring, ""])
code 2:
sstring = "x 128 - abs y 128 - abs < x y ?"
last = core.std.Expr([clip1, clip2], sstring if clip1.format.color_family == vs.GRAY else [sstring, ""])
code 3:
sstring = "x y = 0 255 ?"
last = core.std.Expr([clip1, clip2], sstring if clip1.format.color_family == vs.GRAY else [sstring, ""])
gugglu
26th March 2019, 12:42
Sorry can't help you with Expr()
But maybe this can help: https://github.com/darealshinji/vapoursynth-plugins/blob/master/scripts/dehalo_alpha.py#L33
https://github.com/darealshinji/vapoursynth-plugins/blob/master/scripts/fastlinedarken.py#L19
Hi C.K thats alright sarge thanks anyway, tho I really appreciated all your help from the beginning. :respect:
Code1:
s_str = 1.2
s_reverse = s_str + 0.25
s_divisor = 1.5
s_indexR = 1.281
sstring = f"x 128 - abs {s_divisor} / {1 / s_indexR} pow {s_str} * x 128 - dup abs 0.001 + / * x 128 - 2 pow dup {s_reverse} + / * 128 +"
last = core.std.Expr(last, sstring if last.format.color_family == vs.GRAY else [sstring, ""])
code 2:
sstring = "x 128 - abs y 128 - abs < x y ?"
last = core.std.Expr([clip1, clip2], sstring if clip1.format.color_family == vs.GRAY else [sstring, ""])
code 3:
sstring = "x y = 0 255 ?"
last = core.std.Expr([clip1, clip2], sstring if clip1.format.color_family == vs.GRAY else [sstring, ""])
Awesome WolframRhodium, thanks for your visit. that formula looks great will give it go soon as i get some time to get on my computer, really Doom9 is full of great intelligent guys and i am glad to be part of it .
:thanks:
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.