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 > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 4th June 2009, 11:54   #1  |  Link
onesloth
Registered User
 
Join Date: Jul 2007
Posts: 137
TemporalDegrain_MT

Code:
#################################################################################
#
# TemporalDegrain_MT v1.2 (7/1/2009) by onesloth
#
# Simple Front-end for MT()'ing TemporalDegrain V1.23 (by Didee and Sagekilla)
# but using *single-threaded* prefilter clip.
#
# Required plugins:
# http://avisynth.org/mediawiki/Temporal_Degrain
# http://avisynth.org/mediawiki/MT
#
# Required for use of chroma parameter:
# TemporalDegrain_ChromaMod: http://forum.doom9.org/showthread.php?t=147548
# 
# Syntax is same as TemporalDegrain except for addition of threads,
# overlap, and splitvertical parameters from MT() and the chroma and flatsigma parameters.
# See above links for syntax explanation.
#
##################################################################################

##################################################################################
#
# changelog:
#
# v1.1 (6/4/2009) 	+Added chroma parameter for faster processing
# 			of greyscale sources with TemporalDegrain_ChromaMod.
#
# v1.1.1 (6/4/2009) 	-Changed prefilter block width and height default
#			to 32 when GPU=true. Runs at same speed as 16 on my system.
#
# v1.2 (7/1/2009) 	+Added flatsigma parameter. Makes FFT3D prefilter use only
#			a single sigma parameter equal to flatsigma value if flatsigma > 0.
#			+Added switching of FFT3D plane parameter when chroma processing is disabled
#			-Removed parameters from TemporalDegrain calls that aren't used when fed a prefilter clip
#
##################################################################################


function TemporalDegrain_MT ( clip input, clip "denoise", bool "GPU", int "sigma", int "bw", int "bh", int "pel", 
 \                         int "blksize", int "ov", int "degrain", int "limit", int "SAD1", int "SAD2", int "HQ",
 \			   int "threads", int "overlap", bool "splitvertical", bool "chroma", float "flatsigma" )
{
o       = input
GPU     = default( GPU,   false ) # Use FFT3DGPU -- helpful if you have a fast GPU
sigma   = default( sigma,    16 ) # Default seems to work fine -- Higher values don't help much
bw 	= default( bw, ((GPU==false) ? 16 : 32) ) # FFT3D block width
bh 	= default( bh, ((GPU==false) ? 16 : 32) ) # FFT3D block height
pel     = default( pel,       2 ) # Higher values increase motion vector quality at the cost of speed
blksize = default( blksize,   8 ) # use 16 for more speed, or for HD resolutions like 1080p
ov      = default( ov, blksize/2) # Increase for better motion vectors but slower speed. Max is blksize/2
degrain = default( degrain,   2 ) # MVDegrain 1, 2 or 3
limit   = default( limit,   255 ) # Limits maximum change of a pixel. Default means no limit
SAD1    = default( SAD1,    400 ) # Threshold for degraining. Decrease if you suffer from ghosting
SAD2    = default( SAD2,    300 ) # See above
HQ      = default( HQ,        1 ) # How much to clean up clip for motion vector searching
s2      = floor ( sigma * 0.625 ) # See sigma
s3      = floor ( sigma * 0.375 ) # See sigma
s4      = floor ( sigma * 0.250 ) # See sigma
ow      = bw / 2                  # Don't adjust unless you need speed
oh      = bh / 2                  # See above
ov      = (ov*2>blksize) ? blksize/2 : ov
threads = default( threads,   4 ) # Number of threads to run. Set this to the number of threads
				  # your computer is able to run concurrently.
overlap = default( overlap,   8 ) # Number of pixels to add at the top and bottom border or left and right border.
				  # Increase this if you see artifacts where the frame is split.
splitvertical = default( splitvertical, false ) # if true the frame is cut vertical else it is cut horizontal.
chroma	= default( chroma, true ) # When false uses TemporalDegrain_ChromaMod for faster greyscale source processing
plane	= (chroma) ? 4 : 0	  # Sets FFT3D prefilter to only process luma when chroma==false
flatsigma = default( flatsigma, 0 )


# Same as TemporalDegrain prefilter code except for bt=3 in FFT3DGPU.
# bt=4 appears to be broken. bt=3 gives much stronger denoising.
prefiltered = defined(denoise)
\		? denoise
\		: (flatsigma > 0)
\			? (GPU)
\				? o.FFT3DGPU(sigma=flatsigma, bt=3, bw=bw, bh=bh, ow=ow, oh=oh, plane=plane)
\				: o.FFT3DFilter(sigma=flatsigma, bt=4, bw=bw, bh=bh, ow=ow, oh=oh, plane=plane)
\			: (GPU)
\				? o.FFT3DGPU(sigma=sigma, sigma2=s2 , sigma3=s3, sigma4=s4, bt=3, bw=bw, bh=bh, ow=ow, oh=oh, plane=plane)
\				: o.FFT3DFilter(sigma=sigma, sigma2=s2, sigma3=s3, sigma4=s4, bt=4, bw=bw, bh=bh, ow=ow, oh=oh, plane=plane)

interleave(o, prefiltered)

(chroma==false)
\	? MT("""
		orig_extract = selecteven()
		prefilt_extract = selectodd()
		TemporalDegrain_ChromaMod(orig_extract, denoise=prefilt_extract, pel=pel,
		 \	blksize=blksize, ov=ov, degrain=degrain, limit=limit, SAD1=SAD1, SAD2=SAD2, HQ=HQ, chroma=chroma)
	""", threads=threads, overlap=overlap, splitvertical=splitvertical)
\
\	: MT("""
		orig_extract = selecteven()
		prefilt_extract = selectodd()
		TemporalDegrain(orig_extract, denoise=prefilt_extract, pel=pel,
		 \	blksize=blksize, ov=ov, degrain=degrain, limit=limit, SAD1=SAD1, SAD2=SAD2, HQ=HQ)
	""", threads=threads, overlap=overlap, splitvertical=splitvertical)

return(last)
}
I can't run SetMTMode() with Neuron2's NV source filters so I'm forced to use MT() if I want my script multi-threaded. Simply putting TemporalDegrain inside an MT() call is not ideal, though. The FFT3DGPU prefilter sees no benefit from being multi-threaded, and I have also noticed that MT()'ing a prefilter clip amplifies artifacts at MT()'s split points.

Hence, TemporalDegrain_MT. It makes a prefiltered clip in the single-threaded environment, then feeds the original clip along with the prefiltered clip into the MT() block where vanilla TemporalDegrain is called.

NOTE: This is not an ideal way to multi-thread TemporalDegrain (or any other motion compensated filter, for that matter). If SetMTMode() works with your script (and actually makes it faster) then you should just use SetMTMode() and call vanilla TemporalDegrain() for best multi-threaded results. EDIT: You can also use TemporalDegrain_ChromaMod in a script with SetMTMode enabled and it should give about the same performance at TemporalDegrain_MT with the same number of threads.

Using MT() with MDegrain (and therefore TemporalDegrain) with some sources can result in artifacts at the lines where MT() splits the frame. Raising the overlap can sometimes alleviate or eliminate this. These artifacts will be most pronounced during a vertical pan (when splitvertical=false) with a flat background. Look for a clip like that and test different overlaps. Sometimes you need really big overlaps (like 32 or 48).

Last edited by onesloth; 1st July 2009 at 10:22. Reason: New version 1.2
onesloth is offline   Reply With Quote
Old 20th June 2009, 13:31   #2  |  Link
Kaotech
Registered User
 
Kaotech's Avatar
 
Join Date: Dec 2008
Location: France
Posts: 54
I put your script into plugin dir, but i've got message : there is no function named 'temporaldegrain'.
Kaotech is offline   Reply With Quote
Old 20th June 2009, 15:34   #3  |  Link
onesloth
Registered User
 
Join Date: Jul 2007
Posts: 137
You need to put TemporalDegrain.avsi in your Avisynth Plugins folder. Read the 'Required Plugins' section at the top of the code.
onesloth is offline   Reply With Quote
Old 1st July 2009, 10:23   #4  |  Link
onesloth
Registered User
 
Join Date: Jul 2007
Posts: 137
New version 1.2
onesloth is offline   Reply With Quote
Old 5th July 2009, 22:15   #5  |  Link
lansing
Registered User
 
Join Date: Sep 2006
Posts: 1,657
a request for star protection to add into it?
lansing is offline   Reply With Quote
Old 6th July 2009, 11:20   #6  |  Link
LaTo
LaTo INV.
 
LaTo's Avatar
 
Join Date: Jun 2007
Location: France
Posts: 701
Quote:
Originally Posted by lansing View Post
a request for star protection to add into it?
MCTemporalDenoise have star protection and it isn't much slower (tested on a 720p sample of 300):

TemporalDegrain_MT() = 3.20 fps
MT("""MCTemporalDenoise(settings="high")""",threads=4,overlap=16) = 3.10fps

The result is close, but MCTD do a better degraining with less detail loss.
LaTo is offline   Reply With Quote
Reply

Tags
degrain, denoise, temporaldegrain, temporaldegrain_mt

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 16:57.


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