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 31st October 2022, 08:32   #4761  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 6,904
Okay,
Avisynth:
Code:
Mt_AddDiff(Blurred, ReconstructedMedian)
<>
Vapoursynth:
Code:
core.std.MergeDiff(Blurred, ReconstructedMedian))
Avisynth:
Code:
MT_Luts(Diff, Diff, mode="med", pixels = " 0 0 1 0 -1 0 " ,  expr = " X Y - X Y - X Y - abs 1 + * X Y - abs 1 + "+THR+" 1 >= "+THR+" 0.5 ^ "+THR+" ? + / - 128 +", u=1,v=1)
<>
Vapoursynth:
Code:
partial_expr = lambda M, N: f" x x[{M},{N}] - x x[{M},{N}] - x x[{M},{N}] - abs 1 + * x x[{M},{N}] - abs 1 + {THR} 1 >= {thr_s} 0.5 pow {THR} ? + / - 128 + "
medianDiff = core.akarin.Expr(diff, [partial_expr(0,0) + partial_expr(1,0) + partial_expr(-1,0) + "sort3 drop swap drop", ""])

=> But how to convert,
Avisynth
Code:
Mt_Convolution(Horizontal=" 1 1 0 0 1 0 0 1 1 ", vertical = " 1 ", u=1, v=1)
to Vapoursynth?

Cu Selur
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote
Old 31st October 2022, 10:30   #4762  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 6,904
got it,
Code:
clip.std.Convolution(matrix=[ 1, 1, 0, 0, 1, 0, 0, 1, 1 ], mode='v', planes=[0])
works. (the mode='v' was the main issue)
Uploaded it to: https://github.com/Selur/Vapoursynth...r/fromDoom9.py

Cu Selur
__________________
Hybrid here in the forum, homepage

Last edited by Selur; 31st October 2022 at 10:51.
Selur is offline   Reply With Quote
Old 20th November 2022, 18:21   #4763  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Kinnarps Chair
Posts: 2,497
R61-RC1 is out. Bug fixes only.
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet
Myrsloik is offline   Reply With Quote
Old 20th November 2022, 19:22   #4764  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 6,904
Thanks
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote
Old 29th November 2022, 19:52   #4765  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Kinnarps Chair
Posts: 2,497
Quote:
Originally Posted by Selur View Post
Thanks
R61 released now. No changes from RC1.
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet
Myrsloik is offline   Reply With Quote
Old 29th November 2022, 20:01   #4766  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 6,904
Thanks again.
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote
Old 7th December 2022, 05:08   #4767  |  Link
lansing
Registered User
 
Join Date: Sep 2006
Posts: 1,643
I'm testing out the VSGAN filter in vsedit2, how do I free the gpu ram usage after running it? vsapi->freeFrame() doesn't free it.
lansing is offline   Reply With Quote
Old 18th December 2022, 19:31   #4768  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 6,904
I get totally different decimated output when using:
Code:
# Imports
import vapoursynth as vs
# getting Vapoursynth core
core = vs.core
# Loading Plugins
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/DeinterlaceFilter/TIVTC/libtivtc.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/SourceFilter/LSmashSource/vslsmashsource.dll")
# source: 'C:\Users\Selur\Desktop\sample_from_DVD.mkv'
# current color space: YUV420P8, bit depth: 8, resolution: 720x480, fps: 29.97, color matrix: 470bg, yuv luminance scale: limited, scanorder: telecine
# Loading C:\Users\Selur\Desktop\sample_from_DVD.mkv using LWLibavSource
clip = core.lsmas.LWLibavSource(source="C:/Users/Selur/Desktop/sample_from_DVD.mkv", format="YUV420P8", stream_index=0, cache=0, prefer_hw=0)
# Setting color matrix to 470bg.
clip = core.std.SetFrameProps(clip, _Matrix=5)
clip = clip if not core.text.FrameProps(clip,'_Transfer') else core.std.SetFrameProps(clip, _Transfer=5)
clip = clip if not core.text.FrameProps(clip,'_Primaries') else core.std.SetFrameProps(clip, _Primaries=5)
# Setting color range to TV (limited) range.
clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=1)
# making sure frame rate is set to 29.97
clip = core.std.AssumeFPS(clip=clip, fpsnum=30000, fpsden=1001)
clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=0)
# cropping the video to 704x480
clip = core.std.CropRel(clip=clip, left=6, right=10, top=0, bottom=0)
# Deinterlacing using TIVTC
clip = core.tivtc.TFM(clip=clip, mode=4)
clip = core.tivtc.TDecimate(clip=clip)# new fps: 23.976
# make sure content is preceived as frame based
clip = core.std.SetFieldBased(clip, 0)
# adjusting output color from: YUV420P8 to YUV420P10 for x265Model
clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, range_s="limited")
# set output frame rate to 23.976fps
clip = core.std.AssumeFPS(clip=clip, fpsnum=24000, fpsden=1001)
# Output
clip.set_output()
compared to:
Code:
# Imports
import vapoursynth as vs
# getting Vapoursynth core
core = vs.core
# Loading Plugins
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/DeinterlaceFilter/TIVTC/libtivtc.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/SourceFilter/DGDecNV/DGDecodeNV.dll")
# source: 'C:\Users\Selur\Desktop\sample_from_DVD.mkv'
# current color space: YUV420P8, bit depth: 8, resolution: 720x480, fps: 29.97, color matrix: 470bg, yuv luminance scale: limited, scanorder: telecine
# Loading C:\Users\Selur\Desktop\sample_from_DVD.mkv using DGSource
clip = core.dgdecodenv.DGSource("G:/Temp/mkv_6971e61a600461af6ca6ccf15732fb4f_853323747.dgi",fieldop=2)
# Setting color matrix to 470bg.
clip = core.std.SetFrameProps(clip, _Matrix=5)
clip = clip if not core.text.FrameProps(clip,'_Transfer') else core.std.SetFrameProps(clip, _Transfer=5)
clip = clip if not core.text.FrameProps(clip,'_Primaries') else core.std.SetFrameProps(clip, _Primaries=5)
# Setting color range to TV (limited) range.
clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=1)
# making sure frame rate is set to 29.97
clip = core.std.AssumeFPS(clip=clip, fpsnum=30000, fpsden=1001)
clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=0)
# cropping the video to 704x480
clip = core.std.CropRel(clip=clip, left=6, right=10, top=0, bottom=0)
# Deinterlacing using TIVTC
clip = core.tivtc.TFM(clip=clip, mode=4)
clip = core.tivtc.TDecimate(clip=clip)# new fps: 23.976
# make sure content is preceived as frame based
clip = core.std.SetFieldBased(clip, 0)
# adjusting output color from: YUV420P8 to YUV420P10 for x265Model
clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, range_s="limited")
# set output frame rate to 23.976fps
clip = core.std.AssumeFPS(clip=clip, fpsnum=24000, fpsden=1001)
# Output
clip.set_output()
And the only difference between it is the source filter.
With dgdecodenv.DGSource I get wrong decimation hits.
In Avisynth I would use "clip = clip.PreRoll(Int(clip.FrameRate())" to handle this, but what to do in Vapoursynth?
I encountered this with the source from https://forum.videohelp.com/threads/...erlace-dilemma

Okay, scratch that, using PreRoll in Avisynth doesn't help either, only switching away from DGDecNV.
The question whether there is an alternative to PreRoll still remains.

Cu Selur
__________________
Hybrid here in the forum, homepage

Last edited by Selur; 18th December 2022 at 19:36.
Selur is offline   Reply With Quote
Old 19th December 2022, 04:38   #4769  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,076
Quote:
Originally Posted by Selur View Post
And the only difference between it is the source filter.
With dgdecodenv.DGSource I get wrong decimation hits.
I get similar results between avs and vpy versions of simple TIVTC script using DGSource (frames match up, but not bit identical, I think libtivtc might be taking a slightly different field on some matches, but still resulting in the same frame visually)
poisondeathray is offline   Reply With Quote
Old 20th December 2022, 21:35   #4770  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 6,904
Is there another SourceFilter than DGDecNV which has 'soft telecine' (ForceFilm) handling?
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote
Old 20th December 2022, 21:49   #4771  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,076
Quote:
Originally Posted by Selur View Post
Is there another SourceFilter than DGDecNV which has 'soft telecine' (ForceFilm) handling?
d2vsource ? RFF = False ? or DGIndex FF ?
Quote:

Unlike DGDecode, it's up to the user to apply RFF flags as they see fit, by passing rff=True to the source function, or by passing rff=False and using core.d2v.ApplyRFF(clip, d2v=r'C:\path\to\my.d2v') after calling the source function. Unless you know your source is 100% FILM, you probably want to apply these. DGDecode's traditional "Force FILM" mode isn't really present in this plugin, but if your source or part of it is 100% FILM, which is the only time you should be Force FILMing anyway, you can simply set Force FILM in DGIndex, which will set the framerate properly in the D2V file, and then not apply RFF flags. It's also feasible to trim away any non-FILM frames and still Force FILM.
Maybe ffms2 ... but rffmode might not be present in the vapoursynth version of ffms2 (or maybe it's always mode=0 ?)
poisondeathray is offline   Reply With Quote
Old 5th January 2023, 15:53   #4772  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 6,904
Issue was resolved over at: https://www.rationalqm.us/board/view...php?f=8&t=1220
It was my mistake, I misunderstood how fieldop in DGSource source worked.
Instead of fieldop=2, I should have used fieldop=0. :/
(so not a bug in DGDecNV, but in my mind )

Cu Selur
__________________
Hybrid here in the forum, homepage

Last edited by Selur; 5th January 2023 at 15:55.
Selur is offline   Reply With Quote
Old 9th January 2023, 23:13   #4773  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 268
About _ColorRange prop,
I have to specify it this way: RANGE = {0:'limited', 1:'full'}, I checked Zimg and it has it the same way.
But manual has it backwards, http://www.vapoursynth.com/doc/apire...ame-properties
Could it be fixed in that documentation?
_Al_ is offline   Reply With Quote
Old 10th January 2023, 01:18   #4774  |  Link
Julek
Registered User
 
Julek's Avatar
 
Join Date: Dec 2020
Posts: 78
Quote:
Originally Posted by _Al_ View Post
About _ColorRange prop,
I have to specify it this way: RANGE = {0:'limited', 1:'full'}, I checked Zimg and it has it the same way.
But manual has it backwards, http://www.vapoursynth.com/doc/apire...ame-properties
Could it be fixed in that documentation?

Frame prop and zimg arg are different things.
1 is limited in _ColorRange prop and full in zimg arg.
__________________
CPU: AMD 3700X | GPU: RTX 3070Ti | RAM: 32GB 3200MHz
Discord: @Julek#9391 || GitHub
Julek is offline   Reply With Quote
Old 10th January 2023, 19:28   #4775  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 268
I have to define range and matrix using strings, otherwise things are off:
Code:
print(vs.__api_version__)
clip = core.lsmas.LibavSMASHSource('YUV.mp4')
rgb1 = clip.resize.Bicubic(format=vs.RGB24, matrix_in_s='709', range_in_s='full')
rgb2 = clip.resize.Bicubic(format=vs.RGB24, matrix_in_s='709', range_in=0)
>>>VapourSynthAPIVersion(api_major=3, api_minor=6)
and rgb1 and rgb2 are not the same, is it an old bug? I do not have portable tkinter in portable API4 right now to quick check

Oh, I get it now, it is swapped, so if wanting to set 'limited' in props, we have to use:
Code:
API3:
clip = clip.std.SetFrameProp(prop='_ColorRange', intval=1)
API4:
clip = clip.std.SetFrameProps(_ColorRange=1)
but if wanting to specify limited range for YUV before conversion, we have to:
Code:
rgb = clip.resize.Bicubic(format=vs.RGB24, matrix_in_s='709', range_in=0)
Wow, I wonder how many headaches this caused, I certainly was confused for a long while ... :-)

Last edited by _Al_; 11th January 2023 at 03:57.
_Al_ is offline   Reply With Quote
Old 15th January 2023, 08:55   #4776  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 6,904
Trying to port CQTGMC to Vapoursynth, I started with:
Code:
def CQTGMC(clip: vs.VideoNode, Sharpness: float=0.25, thSAD1: int=192, thSAD2: int=320, thSAD3: int=128, thSAD4: int=320) -> vs.VideoNode:
  
  flip = core.std.FlipHorizontal(clip)
  flip = Padding(clip=clip,top=clip.width%64)
  flip = Padding(clip=clip,right=clip.height%64)
  padded = core.std.StackHorizontal([clip,flip])
  # todo: optional use nnedi3CL
  bobbed = core.znedi3.nnedi3(clip=padded, field=2)
  denoised = core.rgvs.RemoveGrain(clip=bobbed,mode=12)
  denoised = core.fmtc.resample(clip=denoised, kernel="gauss", w=denoised.width, h=denoised.height, scaleh=denoised.width+0.0001, interlaced=False, interlacedd=False)
  denoised = core.resize.Bicubic(clip=denoised, format=bobbed.format, dither_type="error_diffusion") # adjust format after fmtc
  denoised = core.std.Merge(clipa=denoised, clipb=bobbed,weight=0.25)
  
  srchClip = denoised
  csuper = core.mv.Super(clip=denoised);
  bvec = core.mv.Analyse(csuper,isb=True,blksize=64,overlap=32)
  fvec = core.mv.Analyse(csuper,isb=False,blksize=64,overlap=32)
  Comp1 = core.mv.Compensate(denoised,csuper,bvec,thsad=thSAD2)
  Comp2 = core.mv.Compensate(denoised,csuper,fvec,thsad=thSAD2)
  denoised = core.std.Interleave([Comp1,denoised,Comp2])
  csuper = core.vs.Super(clip=denoised)
  bvec = core.mv.Analyse(csuper,isb=True,blksize=64,overlap=32)
  fvec = core.Analyse(csuper,isb=False,blksize=64,overlap=32)
  Inter = core.mv.FlowInter(csuper,bvec,fvec,blend=False)
#   global CQTGMC_A = Inter.SelectEvery(3,0)
#   global CQTGMC_B = Inter.SelectEvery(3,1)
#   srchClip
#   ScriptClip("""
#   P = YDifferenceFromPrevious()
#   N = Trim(1,0).YDifferenceFromPrevious()
#   N < P ? CQTGMC_A : CQTGMC_B 
#   """)
#   super = MSuper()
#   bVec1 = MAnalyse(super,isb=true,overlap=4,delta=1)
#   fVec1 = MAnalyse(super,isb=false,overlap=4,delta=1)
#   bobbed 
#   super = MSuper(levels=1)
#   bComp1 = MCompensate(super,bVec1,thSAD=thSAD3)
#   fComp1 = MCompensate(super,fVec1,thSAD=thSAD3)
#   Interleave(\
#   SeparateFields(bobbed).SelectEvery(4,0),\
#   SeparateFields(fComp1).SelectEvery(4,1),\
#   SeparateFields(bComp1).SelectEvery(4,2),\
#   SeparateFields(bobbed).SelectEvery(4,3))
#   Weave()
#   #   super = MSuper(levels=1)
#   bComp1 = MCompensate(super, bVec1,thSAD=thSAD4)
#   fComp1 = MCompensate(super, fVec1,thSAD=thSAD4)
#   tMax = mt_logic(fComp1,"max",U=3,V=3).mt_logic(bComp1,"max",U=3,V=3)
#   tMin = mt_logic(fComp1,"min",U=3,V=3).mt_logic(bComp1,"min",U=3,V=3)
#   MDegrain1(super,bVec1,fVec1,thSAD=thSAD1)
#   sharpen = mt_adddiff(mt_makediff(Removegrain(20),u=3,v=3),u=3,v=3)
#   mt_clamp(sharpen,tMax,tMin,Sharpness,Sharpness,3,3,3)
#   super = MSuper(levels=1)
#   MDegrain1(super,bVec1,fVec1,thSAD=thSAD1)
#   Crop(0,0,-(input.width()%64),-(input.height()%64))
#   return last
  
# from havsfunc
def Padding(clip: vs.VideoNode, left: int = 0, right: int = 0, top: int = 0, bottom: int = 0) -> vs.VideoNode:
    if not isinstance(clip, vs.VideoNode):
        raise vs.Error('Padding: this is not a clip')

    if left < 0 or right < 0 or top < 0 or bottom < 0:
        raise vs.Error('Padding: border size to pad must not be negative')

    width = clip.width + left + right
    height = clip.height + top + bottom

    return clip.resize.Point(width, height, src_left=-left, src_top=-top, src_width=width, src_height=height)
but now I'm stuck.
Can someone tell me how to convert this part:
Code:
global CQTGMC_A = Inter.SelectEvery(3,0)
    global CQTGMC_B = Inter.SelectEvery(3,1)
    srchClip
    ScriptClip("""
    P = YDifferenceFromPrevious()
    N = Trim(1,0).YDifferenceFromPrevious()
    N < P ? CQTGMC_A : CQTGMC_B 
    """)
to Vapoursynth?

Thanks!

Cu
Selur
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote
Old 15th January 2023, 10:12   #4777  |  Link
kedautinh12
Registered User
 
Join Date: Jan 2018
Posts: 1,643
SelectEvery(3,0) -> std.SelectEvery(clip=clip, cycle=2, offsets=0)
SelectEvery(3,1) -> SelectEvery(clip=clip, cycle=2, offsets=1)
YDifferenceFromPrevious() -> core.std.PlaneStats(clip, clip[0] + clip)
kedautinh12 is offline   Reply With Quote
Old 15th January 2023, 10:33   #4778  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 6,904
Okay, but why:
Code:
SelectEvery(3,0) -> std.SelectEvery(clip=clip, cycle=2, offsets=0)
shouldn't cycle stay 3 ?
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote
Old 15th January 2023, 10:45   #4779  |  Link
kedautinh12
Registered User
 
Join Date: Jan 2018
Posts: 1,643
Quote:
Originally Posted by Selur View Post
Okay, but why:
Code:
SelectEvery(3,0) -> std.SelectEvery(clip=clip, cycle=2, offsets=0)
shouldn't cycle stay 3 ?
Lol, i'm forgot change that, sr
kedautinh12 is offline   Reply With Quote
Old 15th January 2023, 12:03   #4780  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 6,904
Okay. Thanks
Opened a separate thread for the porting. https://forum.doom9.org/showthread.php?p=1981140

Cu
Selur
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote
Reply

Tags
speed, vaporware, vapoursynth

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 15:06.


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