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 18th November 2013, 19:22   #1  |  Link
handaimaoh
Guest
 
Posts: n/a
RemoveDirtVS

So I've finally finished porting RemoveDirt to Vapoursynth. I've tested it a little bit but it could definitely use more extensive testing.

To use it in Vapoursynth here is also the ported version of the Avisynth script as a function:

Code:
#removedirtvs.py

import vapoursynth as vs

def RemoveDirt(input, repmode=16):
    core = vs.get_core()
    cleansed = core.rgvs.Clense(input)
    sbegin = core.rgvs.ForwardClense(input)
    send = core.rgvs.BackwardClense(input)
    scenechange = core.rdvs.SCSelect(input, sbegin, send, cleansed)
    alt = core.rgvs.Repair(scenechange, input, mode=[repmode,repmode,1])
    restore = core.rgvs.Repair(cleansed, input, mode=[repmode,repmode,1])
    corrected = core.rdvs.RestoreMotionBlocks(cleansed, restore, neighbour=input, alternative=alt, gmthreshold=70, dist=1, dmode=2, noise=10, noisy=12, grey=0)
    return core.rgvs.RemoveGrain(corrected, mode=[17,17,1])
Copy and paste that into a text file and save as removedirtvs.py and then put it into the Lib/site-packages folder in your Python install. And then you can simply use the function as in this example:

Code:
import vapoursynth as vs
import removedirtvs

core = vs.get_core()
core.std.LoadPlugin(plugins_vs + r'ffms2.dll')
core.std.LoadPlugin(plugins_vs + r'RemoveDirt.dll')
clip = core.ffms2.Source(src)
clip = removedirtvs.RemoveDirt(clip)
clip.set_output()
Windows 32-bit build. Windows 64-bit build.

Source code is here.

Last edited by handaimaoh; 21st November 2013 at 01:03.
  Reply With Quote
Old 18th November 2013, 19:51   #2  |  Link
handaimaoh
Guest
 
Posts: n/a
I forgot to mention, if you are compiling it yourself make sure that "VS_TARGET_CPU_X86" is defined because there is no fallback code in case it isn't right now. I will also eventually create a makefile.

Edited to add:
Just added an #error case in case that is not defined.

Last edited by handaimaoh; 18th November 2013 at 20:00.
  Reply With Quote
Old 18th November 2013, 20:40   #3  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Kinnarps Chair
Posts: 2,596
Quote:
Originally Posted by handaimaoh View Post
I forgot to mention, if you are compiling it yourself make sure that "VS_TARGET_CPU_X86" is defined because there is no fallback code in case it isn't right now. I will also eventually create a makefile.

Edited to add:
Just added an #error case in case that is not defined.
Uh, why is the function in a class you have to instantiate and not a simple function in a python module?
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet
Myrsloik is offline   Reply With Quote
Old 18th November 2013, 20:41   #4  |  Link
handaimaoh
Guest
 
Posts: n/a
Quote:
Originally Posted by Myrsloik View Post
Uh, why is the function in a class you have to instantiate and not a simple function in a python module?
I simply copied how Chikuzen did his ImageReader script here. I don't really know more than a passing amount of Python.
  Reply With Quote
Old 18th November 2013, 20:44   #5  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Kinnarps Chair
Posts: 2,596
Quote:
Originally Posted by handaimaoh View Post
I simply copied how Chikuzen did his ImageReader script here. I don't really know more than a passing amount of Python.
This should work:

Code:
#removedirtvs.py

import vapoursynth as vs

def RemoveDirt(input, repmode=16):
    core = vs.get_core()
    cleansed = core.rgvs.Clense(input)
    sbegin = core.rgvs.ForwardClense(input)
    send = core.rgvs.BackwardClense(input)
    scenechange = core.rdvs.SCSelect(input, sbegin, send, cleansed)
    alt = core.rgvs.Repair(scenechange, input, mode=[repmode,repmode,1])
    restore = core.rgvs.Repair(cleansed, input, mode=[repmode,repmode,1])
    corrected = core.rdvs.RestoreMotionBlocks(cleansed, restore, neighbour=input, alternative=alt, gmthreshold=70, dist=1, dmode=2, noise=10, noisy=12, grey=0)
    return core.rgvs.RemoveGrain(corrected, mode=[17,17,1])
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet
Myrsloik is offline   Reply With Quote
Old 19th November 2013, 17:16   #6  |  Link
handaimaoh
Guest
 
Posts: n/a
Quote:
Originally Posted by Myrsloik View Post
This should work:

Code:
#removedirtvs.py

import vapoursynth as vs

def RemoveDirt(input, repmode=16):
    core = vs.get_core()
    cleansed = core.rgvs.Clense(input)
    sbegin = core.rgvs.ForwardClense(input)
    send = core.rgvs.BackwardClense(input)
    scenechange = core.rdvs.SCSelect(input, sbegin, send, cleansed)
    alt = core.rgvs.Repair(scenechange, input, mode=[repmode,repmode,1])
    restore = core.rgvs.Repair(cleansed, input, mode=[repmode,repmode,1])
    corrected = core.rdvs.RestoreMotionBlocks(cleansed, restore, neighbour=input, alternative=alt, gmthreshold=70, dist=1, dmode=2, noise=10, noisy=12, grey=0)
    return core.rgvs.RemoveGrain(corrected, mode=[17,17,1])
Ok, I'll update the first post.
  Reply With Quote
Old 20th November 2013, 00:30   #7  |  Link
handaimaoh
Guest
 
Posts: n/a
RemoveDirtVS

So I guess no one has actually tested this yet but myself since there was a crash bug introduced where I forgot to add back in an EMMS call that was removed at one point from a method that would call into the few functions using MMX intrinsics. Sometimes it would manifest at the very beginning of a video and sometimes after a few hundred to a few thousand frames. So that has now been fixed and a new binary is posted here.

I knew that stupid MMX code would haunt me in some way...

Last edited by handaimaoh; 20th November 2013 at 00:34.
  Reply With Quote
Old 20th November 2013, 00:40   #8  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Kinnarps Chair
Posts: 2,596
Quote:
Originally Posted by handaimaoh View Post
So I guess no one has actually tested this yet but myself since there was a crash bug introduced where I forgot to add back in an EMMS call that was removed at one point from a method that would call into the few functions using MMX intrinsics. Sometimes it would manifest at the very beginning of a video and sometimes after a few hundred to a few thousand frames. So that has now been fixed and a new binary is posted here.

I knew that stupid MMX code would haunt me in some way...
VapourSynth requires sse2 so it's a mystery why you kept the mmx code path as well. Just delete the mmx and have a better life.
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet
Myrsloik is offline   Reply With Quote
Old 20th November 2013, 00:44   #9  |  Link
handaimaoh
Guest
 
Posts: n/a
RemoveDirtVS

I realize that. It's not a seperate code path, though. It's a couple of functions that were only written in MMX. I was already going to rewrite them since the MMX intrinsics prevents compiling for x64. It's just that I hadn't done it yet and I noticed that it was causing the plugin to instantly crash in some cases because of the lack of emms.

Last edited by handaimaoh; 20th November 2013 at 00:55.
  Reply With Quote
Old 20th November 2013, 02:00   #10  |  Link
handaimaoh
Guest
 
Posts: n/a
So converted and purged all the MMX code so I can now make x64 Windows builds. Will build new binaries tomorrow morning.
  Reply With Quote
Old 20th November 2013, 02:16   #11  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,672
Quote:
Originally Posted by handaimaoh View Post
So I guess no one has actually tested this yet but myself since there was a crash bug introduced where I forgot to add back in an EMMS call that was removed at one point from a method that would call into the few functions using MMX intrinsics. Sometimes it would manifest at the very beginning of a video and sometimes after a few hundred to a few thousand frames. So that has now been fixed and a new binary is posted here.
Ok now I have some time to test, but when I try to load your recently uploaded binary I get this error: (does not happen with the previous binary)
Quote:
---------------------------
VirtualDub Error
---------------------------
Avisynth open failure:
Python exception: 'Failed to load C:\\Vapoursynth\\RemoveDirtVS\\RemoveDirtVS.dll'
Traceback (most recent call last):
File "vapoursynth.pyx", line 1082, in vapoursynth.vpy_evaluateScript (src\cython\vapoursynth.c:16736)
File "C:\VapourSynth\RemoveDirtVS\test.vpy", line 4, in <module>
core.std.LoadPlugin(path=r'C:\Vapoursynth\RemoveDirtVS\RemoveDirtVS.dll')
File "vapoursynth.pyx", line 1005, in vapoursynth.Function.__call__ (src\cython\vapoursynth.c:15793)
vapoursynth.Error: 'Failed to load C:\\Vapoursynth\\RemoveDirtVS\\RemoveDirtVS.dll'
Reel.Deel is offline   Reply With Quote
Old 20th November 2013, 02:18   #12  |  Link
handaimaoh
Guest
 
Posts: n/a
What's your script? Loaded just fine for me after I made the fix to test.
  Reply With Quote
Old 20th November 2013, 02:19   #13  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,672
Code:
import vapoursynth as vs
core = vs.get_core()
core.avs.LoadPlugin(path=r'C:\Program Files\AviSynth 2.5\plugins\DGDecodeNV.dll')
core.std.LoadPlugin(path=r'C:\Vapoursynth\RemoveDirtVS\RemoveDirtVS.dll')

# Source
src = core.avs.DGSource(dgi=r'C:\Vapoursynth\RemoveDirtVS\00110.dgi')

# Proccesing
src = core.vivtc.VFM(clip=src, order=1, field=1)
src = core.vivtc.VDecimate(clip=src)

# RemoveDirt
clip = src
cleansed = core.rgvs.Clense(clip)
sbegin = core.rgvs.ForwardClense(clip)
send = core.rgvs.BackwardClense(clip)
scenechange = core.rdvs.SCSelect(clip, sbegin, send, cleansed)
alt = core.rgvs.Repair(scenechange, clip, mode=[16,16,1])
restore = core.rgvs.Repair(cleansed, clip, mode=[16,16,1])
corrected = core.rdvs.RestoreMotionBlocks(cleansed, restore, neighbour=clip, alternative=alt, gmthreshold=70, dist=1, dmode=2, noise=10, noisy=12, grey=0)
clip = core.rgvs.RemoveGrain(clip, mode=[17,17,1])
clip.set_output()
Reel.Deel is offline   Reply With Quote
Old 20th November 2013, 02:21   #14  |  Link
handaimaoh
Guest
 
Posts: n/a
Just pulled down the binary on another computer and ran the same script. Loaded just fine in VirtualDub for me. What version of Vapoursynth you running?
  Reply With Quote
Old 20th November 2013, 02:24   #15  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,672
Hmm that's odd. If I replace the binary with the older one, it loads without errors.

Im using VS R21 on 32-bit Windows XP sp3.

Going to update to R22 test version to see if that does anything.

Update:
With R22 test 2, I can't even load a script. It just freezes VDub. I also removed RemoveDirt and tried with a simpler script and still froze.
Will investigate a little more.

Last edited by Reel.Deel; 20th November 2013 at 02:37.
Reel.Deel is offline   Reply With Quote
Old 20th November 2013, 02:38   #16  |  Link
handaimaoh
Guest
 
Posts: n/a
I'm running R22 test 2 on both machines. Loads just fine. *shrug*

Last edited by handaimaoh; 20th November 2013 at 02:44.
  Reply With Quote
Old 20th November 2013, 16:52   #17  |  Link
handaimaoh
Guest
 
Posts: n/a
First post has been updated with both 32-bit and 64-bit builds for Windows.

Last edited by handaimaoh; 20th November 2013 at 20:05.
  Reply With Quote
Old 15th December 2014, 20:52   #18  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,672
The links in the OP are dead so just in case someone is looking for them here they are: RemoveDirtVS.zip
Reel.Deel is offline   Reply With Quote
Old 20th February 2022, 16:47   #19  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,551
I'm using a script called 'killerspots' (https://github.com/Selur/Vapoursynth...killerspots.py) which works find unless I use:it with advanced = True (the default) in which case:
Code:
def RemoveDirtMod(clip: vs.VideoNode, limit: int =10):
  core = vs.core  
  clensed = core.rgvs.Clense(clip)
  alt = core.rgvs.RemoveGrain(clip,mode=1)
  clip = core.rdvs.RestoreMotionBlocks(clensed, clip, alternative=alt, pthreshold=4, cthreshold=6, gmthreshold=40, dist=3, dmode=2, noise=limit, noisy=12)
  return clip
gets used and then the script crashes after some time.
The script I use is:
Code:
# Imports
import os
import sys
import ctypes
# Loading Support Files
Dllref = ctypes.windll.LoadLibrary("I:/Hybrid/64bit/vsfilters/Support/libfftw3f-3.dll")
import vapoursynth as vs
# 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/MiscFilter/MiscFilters/MiscFilters.dll")
core.std.LoadPlugin(path="I:/Hybrid/64bit/vsfilters/DenoiseFilter/TTempSmooth/TTempSmooth.dll")
core.std.LoadPlugin(path="I:/Hybrid/64bit/vsfilters/DenoiseFilter/DFTTest/DFTTest.dll")
core.std.LoadPlugin(path="I:/Hybrid/64bit/vsfilters/DenoiseFilter/NEO_FFT3DFilter/neo-fft3d.dll")
core.std.LoadPlugin(path="I:/Hybrid/64bit/vsfilters/Support/DCTFilter.dll")
core.std.LoadPlugin(path="I:/Hybrid/64bit/vsfilters/DeblockFilter/Deblock/Deblock.dll")
core.std.LoadPlugin(path="I:/Hybrid/64bit/vsfilters/DenoiseFilter/RemoveDirt/RemoveDirtVS.dll")
core.std.LoadPlugin(path="I:/Hybrid/64bit/vsfilters/Support/libmvtools.dll")
core.std.LoadPlugin(path="I:/Hybrid/64bit/vsfilters/GrainFilter/RemoveGrain/RemoveGrainVS.dll")
core.std.LoadPlugin(path="I:/Hybrid/64bit/vsfilters/SourceFilter/LSmashSource/vslsmashsource.dll")
# Import scripts
import havsfunc
import killerspots
# source: 'G:\TestClips&Co\files\noisy cartoons examples\1080p_v2.mp4'
# current color space: YUV420P8, bit depth: 8, resolution: 1440x1080, fps: 25, color matrix: 709, yuv luminance scale: limited, scanorder: progressive
# Loading G:\TestClips&Co\files\noisy cartoons examples\1080p_v2.mp4 using LibavSMASHSource
clip = core.lsmas.LibavSMASHSource(source="G:/TestClips&Co/files/noisy cartoons examples/1080p_v2.mp4")
# Setting color matrix to 709.
clip = core.std.SetFrameProps(clip, _Matrix=1)
clip = clip if not core.text.FrameProps(clip,'_Transfer') else core.std.SetFrameProps(clip, _Transfer=1)
clip = clip if not core.text.FrameProps(clip,'_Primaries') else core.std.SetFrameProps(clip, _Primaries=1)
# 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)
clip = killerspots.KillerSpots(clip=clip)
# denoising using MCTemporalDenoise
clip = havsfunc.MCTemporalDenoise(i=clip, settings="very high", ncpu=1)
# set output frame rate to 25.000fps
clip = core.std.AssumeFPS(clip=clip, fpsnum=25, fpsden=1)
# Output
clip.set_output()
(Tried different source filters and settings Vapoursynth core count to 1, none did help.)

Calling:
Code:
VSPipe.exe --progress E:\Output\encodingTempSynthSkript_2022-02-20@16_37_30_9010.vpy -c y4m NUL]
If get:
Code:
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001fe31031d00] stream 0, timescale not set
Script evaluation done in 1.18 seconds
Frame: 209/1992 (11.73 fps)
In each call it ends at different frame numbers. (another Hybrid user has the same issue so I suspect that it's not related to my system itself)

When not using advanced=True, only 'clip = core.rgvs.Clense(clip)' will be called and the scripts runs fine.
So I suspect the issue is with 'rdvs.RestoreMotionBlocks'. since the RemoveDirt version I use is the 64bit one from above which from 2013 I was wondering whether this could be due to some incompatibility with the current Vapoursynth version or if anyone has an idea how to fix this.

Cu Selur

Ps.: read over at https://forum.doom9.org/showthread.php?t=176199 that the Vapoursynth port seems to be known to be buggy,.. :/
__________________
Hybrid here in the forum, homepage, its own forum

Last edited by Selur; 20th February 2022 at 17:04.
Selur is offline   Reply With Quote
Old 5th June 2022, 15:10   #20  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,551
In case someone has the knowledge and motivation to look into RemoveDirts RestoreMotionBlocks randomly crashing:

When I change
Code:
clip = core.rdvs.RestoreMotionBlocks(clensed, clip, alternative=alt, pthreshold=4, cthreshold=6, gmthreshold=40, dist=3, dmode=2, noise=limit, noisy=12)
to
Code:
clip = core.rdvs.RestoreMotionBlocks(clensed, clip, alternative=alt, pthreshold=4, cthreshold=6, gmthreshold=40, dist=3, dmode=2, noise=limit, noisy=0)
by setting noisy to zero I get no random crash.
So the problem probably lies somehwere in the noise handling during motion detection.


Cu Selur
__________________
Hybrid here in the forum, homepage, its own forum
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 12:24.


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