Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > VapourSynth

Reply
 
Thread Tools Search this Thread Display Modes
Old 1st October 2022, 21:25   #1  |  Link
gugglu
Registered User
 
Join Date: Jul 2012
Location: Nottingham
Posts: 44
Need help to translate Avisynth script into Vapoursynth.

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
Code:
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
Code:
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 .
Code:
#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.
gugglu is offline   Reply With Quote
Old 2nd October 2022, 08:39   #2  |  Link
cretindesalpes
͡҉҉ ̵̡̢̛̗̘̙̜̝̞̟̠͇̊̋̌̍̎̏̿̿
 
cretindesalpes's Avatar
 
Join Date: Feb 2009
Location: No support in PM
Posts: 712
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:
Code:
blur  = havsfunc.MinBlur(deband,r=1)
dlm16 = deband.std.MergeDiff(core.std.MakeDiff(blur,blur.rgvs.RemoveGrain(4)))
__________________
dither 1.28.1 for AviSynth | avstp 1.0.4 for AviSynth development | fmtconv r30 for Vapoursynth & Avs+ | trimx264opt segmented encoding
cretindesalpes is offline   Reply With Quote
Old 2nd October 2022, 10:51   #3  |  Link
gugglu
Registered User
 
Join Date: Jul 2012
Location: Nottingham
Posts: 44
Quote:
Originally Posted by cretindesalpes View Post
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:
Code:
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.
gugglu is offline   Reply With Quote
Old 16th October 2022, 17:16   #4  |  Link
gugglu
Registered User
 
Join Date: Jul 2012
Location: Nottingham
Posts: 44
Code:
# 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.
gugglu is offline   Reply With Quote
Old 18th October 2022, 03:35   #5  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 6,833
@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.
__________________
Hybrid here in the forum, homepage
Notice: Since email notifications do not work here any more, it might take me quite some time to notice a reply to a thread,..
Selur is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 20:13.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, vBulletin Solutions Inc.