Log in

View Full Version : Need help to translate Avisynth script into Vapoursynth.


gugglu
1st October 2022, 21:25
Hello folks
I want to translate my avisynth script code into Vapoursynth script code,but i don't know Vapoursynth that much and having problem to convert some part of the script i have been trying from last few days but still not able to complete the script. i will be greatly thankful him if anyone could help.

Here is my Avisynth script

LoadPlugin("C:\Users\Binny\Desktop\MeGUI-2913-32\tools\lsmash\LSMASHSource.dll")
LSMASHVideoSource("C:\Users\Binny\Videos\Jungle.mp4")
crop(0, 140, 0, -140)
Spline36Resize(1920,800)
src = last
src16 = Dither_convert_8_to_16(src)
emask = src.tcanny(sigma=2.00, mode=1, plane=7)
denoise = SMDegrain(src,lsb=true,lsb_out=true)
deband = GradFun3(denoise, Smode=2, radius=14, ampn=0, thr=0.25, mask=0, lsb_in=true, lsb=true)
s16 = deband
s8 = deband.ditherpost(mode=-1)
blur = s8.minblur(1)
sharp = s8.mt_adddiff(mt_makediff(blur,blur.removegrain(4)))
sharp16 = Dither_convert_8_to_16 (sharp)
dlm16 = Dither_limit_dif16 (s16, sharp16, thr=1.0, elast=2.0)
#i did translate the script upto here i will leave a translated code below hopefully its correct if you guys found anything wrong please correct me.tia

# This Avisynth block of mask i am not able to translate into Vapoursynth script code
ymask = emask.ConvertToY8.mt_lut("x 3 <= 0 x 3 - 7 << ?", U=1, V=1)
uvmask = emask.UtoY.ConvertToY8.mt_logic(emask.VtoY.ConvertToY8, "max", Y=3, U=1, V=1)
\ .Spline36Resize(emask.width, emask.height, 0.25)
\ .mt_expand(U=1, V=1).mt_lut("x 4 <= 0 255 ?", U=1, V=1)
mask = ymask.mt_logic(uvmask, "max", Y=3, U=1, V=1)
\ .ConvertToYV12()
#stuck here from almost a week

dm16_8 = Dither_merge16_8(dlm16, src16, mask, luma=true, Y=3, U=3, V=3)
#Dither_quantize (dm16_8,bitdepth=10,reducerange=true,mode=0).Dither_out()#Reduce to 10bit Interleave output to x264
DitherPost(dm16_8,mode=0) #Reduce to 8bit output


Here is Vapoursynth script much i could translate

import vapoursynth as vs
import havsfunc
import muvsfunc
import Dither
import vshelpers
core = vs.core

src = core.lsmas.LWLibavSource(r'C:\Users\Binny\Videos\Jungle.mp4')
src = core.std.Crop(src,0,0,140,140)
src = core.resize.Spline36(src, width=1920, height=800)
emask = core.tcanny.TCanny(src,sigma=2.00,mode=1,planes=[0,1,2])
src16 = core.fmtc.bitdepth(src, bits=16)

denoise = havsfunc.SMDegrain(src16)
deband = muvsfunc.GradFun3(denoise, smode=2, radius=14, ampn=0, thr=0.25, mask=0, lsb=True)
s16 = deband
s8 = deband.fmtc.bitdepth(bits=8,dmode=1)
blur = havsfunc.MinBlur(s8,r=1)
sharp = s8.std.MergeDiff(core.std.MakeDiff(blur,blur.rgvs.RemoveGrain(4)))
sharp16 = core.fmtc.resample(sharp)
dlm16 = Dither.limit_dif16(s16, sharp16, thr=1.0, elast=2.0)
dlm16.set_output()
#only upto here i could translate ,guys i really need help to complete the below part correctly.

problem begins here i'm sure i'm doing it wrong here, this is where i am stuck from days .

#my attempt to translate the below avisynth code and ended up with this [vapoursynth.Error: Expr: More expressions given than there are planes] error in vshelpers logic function
#ymask = emask.std.ShufflePlanes(planes=0, colorfamily=vs.GRAY).std.Expr(expr=["x 3 <= 0 x 3 - 128 * ?", ""])
#umask = emask.std.ShufflePlanes(planes=1, colorfamily=vs.GRAY)
#vmask = emask.std.ShufflePlanes(planes=2, colorfamily=vs.GRAY)
#uvmask = vshelpers.logic(umask, vmask, mode='max', planes=[0])

# This Avisynth block of mask i am struggling to translate into Vapoursynth avobe
#ymask = emask.ConvertToY8.mt_lut("x 3 <= 0 x 3 - 7 << ?", U=1, V=1)
#uvmask = emask.UtoY.ConvertToY8.mt_logic(emask.VtoY.ConvertToY8, "max", Y=3, U=1, V=1)
#\ .Spline36Resize(emask.width, emask.height, 0.25)
#\ .mt_expand(U=1, V=1).mt_lut("x 4 <= 0 255 ?", U=1, V=1)
#mask = ymask.mt_logic(uvmask, "max", Y=3, U=1, V=1)
#\ .ConvertToYV12()
#stuck here from almost a week


Thanks Selur for correting Tcanny code :thumbup: ,but sorry Selur i could't understood the ShufflePlanes part for UtoY/VtoY and still stuck at the same spot, reffering to post in this thread http://forum.doom9.org/showthread.php?t=184361 (i am new to Vapoursynth and there is a lot to learn)

Thank you for having a look.

cretindesalpes
2nd October 2022, 08:39
The part between s16 and dlm16 is a pattern for mixing 8-bit and stack16 processing in the times when Avisynth couldn’t use native 16 bit data. You most likely don’t need this suboptimal hack with VS. You could replace it with something like:
blur = havsfunc.MinBlur(deband,r=1)
dlm16 = deband.std.MergeDiff(core.std.MakeDiff(blur,blur.rgvs.RemoveGrain(4)))

gugglu
2nd October 2022, 10:51
The part between s16 and dlm16 is a pattern for mixing 8-bit and stack16 processing in the times when Avisynth couldn’t use native 16 bit data. You most likely don’t need this suboptimal hack with VS. You could replace it with something like:
blur = havsfunc.MinBlur(deband,r=1)
dlm16 = deband.std.MergeDiff(core.std.MakeDiff(blur,blur.rgvs.RemoveGrain(4)))

Hi cretindesalpes thanks for the correcting the script and clearing that Vapoursynth can use native 16bit without suboptimal hack, i'm glad i learned something new today and i really appreciate your help. :thanks:

gugglu
16th October 2022, 17:16
# This Avisynth block of mask i am struggling to translate into Vapoursynth avobe
#ymask = emask.ConvertToY8.mt_lut("x 3 <= 0 x 3 - 7 << ?", U=1, V=1)
#uvmask = emask.UtoY.ConvertToY8.mt_logic(emask.VtoY.ConvertToY8, "max", Y=3, U=1, V=1)
#\ .Spline36Resize(emask.width, emask.height, 0.25)
#\ .mt_expand(U=1, V=1).mt_lut("x 4 <= 0 255 ?", U=1, V=1)
#mask = ymask.mt_logic(uvmask, "max", Y=3, U=1, V=1)
#\ .ConvertToYV12()
#stuck here from almost a week
I did figured it out that i could translate the utoy/vtoy with shuffleplanes & can replace the mt_logic with expr=[x y 'max'] and mt_inpand/expand with Minimum/Maximum in Vapoursynth,so mod can close this.
thanks cretindesalpes.

Selur
18th October 2022, 03:35
@gugglu: might be a good idea to also post a complete finished translation in 'translate Avisynth script into Vapoursynth' scripts to help potential other users.
As a bonus, explaining what the script is intended to do also might help other users. ;)