Log in

View Full Version : using sRestore,...


Selur
7th October 2022, 16:41
Over at videohelp there is a thread (https://forum.videohelp.com/threads/407209-Strange-fields-frames-in-analog-capture) where Avisynth can be nicely used to remove some ghosting using:
ClearAutoloadDirs()
SetFilterMTMode("DEFAULT_MT_MODE", MT_MULTI_INSTANCE)
LoadPlugin("I:\Hybrid\64bit\Avisynth\AVISYN~1\LSMASHSource.dll")
LoadPlugin("I:\Hybrid\64bit\Avisynth\AVISYN~1\RgTools.dll")
LoadPlugin("I:\Hybrid\64bit\Avisynth\AVISYN~1\masktools2.dll")
LoadPlugin("I:\Hybrid\64bit\Avisynth\AVISYN~1\mvtools2.dll")
LoadPlugin("I:\Hybrid\64bit\Avisynth\AVISYN~1\nnedi3.dll")
LoadPlugin("I:\Hybrid\64bit\Avisynth\AVISYN~1\TIVTC.dll")
LoadPlugin("I:\Hybrid\64bit\Avisynth\AVISYN~1\Average.dll")
LoadPlugin("I:\Hybrid\64bit\Avisynth\AVISYN~1\grunt-x64.dll")
LoadPlugin("I:\Hybrid\64bit\Avisynth\AVISYN~1\MedianBlur2.dll")
Import("I:\Hybrid\64bit\Avisynth\avisynthPlugins\mtmodes.avsi")
Import("I:\Hybrid\64bit\Avisynth\avisynthPlugins\QTGMC.avsi")
Import("I:\Hybrid\64bit\Avisynth\avisynthPlugins\Zs_RF_Shared.avsi")
Import("I:\Hybrid\64bit\Avisynth\avisynthPlugins\Srestore.avsi")
# loading source: C:\Users\Selur\Desktop\spots_beg_ufo_sIII1c_amtv_v2_cut.avi
# color sampling YUY2@8, matrix: bt601, scantyp: top field first, luminance scale: limited
LWLibavVideoSource("C:\Users\Selur\Desktop\SPOTS_~1.AVI",cache=false,dr=true,format="YUV422P8", prefer_hw=0)
# current resolution: 720x576
# deinterlacing
AssumeTFF()
QTGMC(Preset="Fast", ediThreads=2)
# removing ghosting
srestore(omode=6)
Preroll(Int(last.FrameRate())) # for consistent preview
# filtering
# adjust color to YV12 (color matrix: Rec601)
ConvertToYV12()
# setting output fps to 23.976fps
AssumeFPS(24000,1001)
# output: color sampling YV16@8, matrix: bt601, scantyp: progressive, luminance scale: limited
return last
https://i.ibb.co/gPdScwT/Avisynth.png (https://ibb.co/rc3xXM6)
using Vapoursynth:
# Imports
import vapoursynth as vs
import os
import ctypes
# Loading Support Files
Dllref = ctypes.windll.LoadLibrary("i:/Hybrid/64bit/vsfilters/Support/libfftw3f-3.dll")
import sys
# getting Vapoursynth core
core = vs.core
# Import scripts folder
scriptPath = 'i:/Hybrid/64bit/vsscripts'
sys.path.insert(0, os.path.abspath(scriptPath))
# Loading Plugins
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/GrainFilter/RemoveGrain/RemoveGrainVS.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/GrainFilter/AddGrain/AddGrain.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/DenoiseFilter/FFT3DFilter/fft3dfilter.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/DenoiseFilter/DFTTest/DFTTest.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/EEDI3m.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/ResizeFilter/nnedi3/vsznedi3.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/libmvtools.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/scenechange.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/fmtconv.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/MiscFilter/MiscFilters/MiscFilters.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/DeinterlaceFilter/Bwdif/Bwdif.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/SourceFilter/LSmashSource/vslsmashsource.dll")
# Import scripts
import havsfunc
# source: 'C:\Users\Selur\Desktop\spots_beg_ufo_sIII1c_amtv_v2_cut.avi'
# current color space: YUV422P8, bit depth: 8, resolution: 720x576, fps: 25, color matrix: 470bg, yuv luminance scale: limited, scanorder: top field first
# Loading C:\Users\Selur\Desktop\spots_beg_ufo_sIII1c_amtv_v2_cut.avi using LWLibavSource
clip = core.lsmas.LWLibavSource(source="C:/Users/Selur/Desktop/spots_beg_ufo_sIII1c_amtv_v2_cut.avi", format="YUV422P8", stream_index=0, cache=0, fpsnum=25, 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 25
clip = core.std.AssumeFPS(clip=clip, fpsnum=25, fpsden=1)
# setting field order to what QTGMC should assume (top field first)
clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=2)
# Deinterlacing using QTGMC
clip = havsfunc.QTGMC(Input=clip, Preset="Fast", TFF=True) # new fps: 50
# make sure content is preceived as frame based
clip = core.std.SetFieldBased(clip, 0)
# adjusting frame count and rate with sRestore
clip = havsfunc.srestore(source=clip,omode=6)
# adjusting output color from: YUV422P8 to YUV420P8 for x264Model
clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P8, range_s="limited")
# set output frame rate to 23.976fps
clip = core.std.AssumeFPS(clip=clip, fpsnum=24000, fpsden=1001)
# Output
clip.set_output()
I get: https://i.ibb.co/JjwKcjt/Vapoursynth.png (https://ibb.co/1GtL0GQ)

At first, I thought it might be a preview issue with sRestore, like I get in Avisynth when not using Preroll.
(I Avisynth you won't get proper preview with sRestore unless you start xy frame before the scene you want to look at or add Preroll after sRestore.)
Sadly, unlike with Avisynth, where the encoding is always, proper (even if the preview was wrong), I'm still left with the ghosting when using sRestore in Vapoursynth.

=> Anyone got an idea how to get sRestore to work in Vapoursynth as good as it does in Avisynth?


Cu Selur

Ps.: is there something similar to Preroll in Vapoursynth which might help with the issue?

poisondeathray
7th October 2022, 19:01
Works for me. Similar results to avs version for the preview (when going back a few frames and advancing linearly frame by frame), or when encoded

Selur
8th October 2022, 05:29
Thanks for testing.
Sadly, for me, with Vapoursynth, frame 46 (after QTGMC() and sRestore()) still has the ghosting.
I could live with the preview being 'broken', but the encoding has the same ghosting. :(

So it must be something with my setup.
Since it's also in the reencode for me, it must be something with the scripts I use.

havsfunc script I'm using is:
https://github.com/Selur/VapoursynthScriptsInHybrid/blob/master/havsfunc.py
(no change when using FFMS2 over L-SmashSource)

Also: Does anyone know whether there is an alternative to Preroll in Vapoursynth?

Cu Selur

cretindesalpes
8th October 2022, 08:42
Does the difference come from srestore or from QTGMC, which is a quite complex function?

Selur
8th October 2022, 09:14
Must be sRestore.
Here's the output of QTGMC(Fast) for Vapoursynth (94/95/96):
https://i.ibb.co/1qdqZ16/Vapoursynt-QTGMC-94.png (https://ibb.co/Xs3sX18)https://i.ibb.co/F8jw5ww/Vapoursynt-QTGMC-95.png (https://ibb.co/3SLNpNN)https://i.ibb.co/SvS697S/Vapoursynt-QTGMC-96.png (https://ibb.co/mzpRMFp)
and for Avisynth (94/95/96):
https://i.ibb.co/1ZCCDty/Avisynth-QTGMC-94.png (https://ibb.co/wynn9FG)https://i.ibb.co/CMjwg0v/Avisynth-QTGMC-95.png (https://ibb.co/GtZdyPk)https://i.ibb.co/ChQX9PR/Avisynth-QTGMC-96.png (https://ibb.co/Tmtn0W9)

=> QTGMC output looks identical to me.

Cu Selur

lollo2
8th October 2022, 09:49
In AviSynth I used Srestore(). The omode parameter defaults at 6, the same you used.

Is it possible than in VapourSynth omode parameter is handled differently?

Just a guess...

Selur
8th October 2022, 10:01
I tried all omode values, so if it's handled differently it's not a simple mapping difference. :/

ChaosKing
8th October 2022, 10:32
Probably a some kind of bug. Dehalo_alpha and finedehalo had also different results for years.
https://github.com/HomeOfVapourSynthEvolution/havsfunc/issues/30

Debugging srestore will certainly be more difficult.

Selur
8th October 2022, 11:28
Hmm,... I hate those expressions in polish format,...

Problem is, to me, basically all the expr calls seem different to me in Vapoursynth than in Avisynth. :/
Would be nice if anyone having more experience than me can say if he sees a difference.

Cu Selur

Ps.: Also created an issue entry https://github.com/HomeOfVapourSynthEvolution/havsfunc/issues/78.