Log in

View Full Version : corrupted frames with MT & denoising


pcat
2nd September 2008, 19:49
Hello,

I'm trying to run faster the scripts I use for denoising with the MT avisynth version. Unfortunately, although the scripts run much faster, there are corrupted frames when using setmtmode (mode 2,3 or 4) along with various powerful denoisers

I have tried mvtools based denoisers (mvdegrain, temporaldegrain, mc_spuds) and dfttest (alone, as a prefilter for temporaldegrain, and for motion compensated denoising with mvflow). In all cases it results in a few corrupted frames at some random places, which does not occur as soon as I comment out setmtmode.

I'm using avisynth 2.5.7 (and the mt modified version 2.5.7.5), masktools v2.0a35 and mvtools v1.9.5.7.
My system is Q6600 with 2 GB.

Here is an exemple script (here with mc_spuds, but when commented and using temporaldegrain instead there are also corrupted frames)...

################
setmemorymax(512)

# dependencies
load_stdcall_plugin("c:\inst\avisynth\plugins\yadif.dll")
Import("v:\avi_scripts\mc_spuds.avs")
Import("v:\avi_scripts\temporaldegrain.avs")

# source
# setmtmode(2) # note: 4 does not help
AVISource("v:\capture.dv2.avi")
AssumebFF()
ConvertToYV12(interlaced=true)


# separate fields
yadif(mode=1)
crop(14,4,-10,-4)

#### denoising

## mc_spuds
# mc_spuds(frames=2,strength=4,debug=0,colorbleed=true,chro=true,aggressive=false)

## temporaldegrain with dfttest prefilter
# filtered=dfttest(sigma=2.8,tmode=1,tbsize=3)
# TemporalDegrain(denoise=filtered,SAD1=300)

### slight post process
# dfttest(sigma=0.4,tmode=0,tbsize=3)

### re-interlace fields
AddBorders(12,4,12,4)
SeparateFields()
SelectEvery(4,0,3).Weave()

###################

It seems that people are successfully running powerful denoisers in multithread mode (mvtools documentation also give an example with mvdegrain with setmtmode(2)), so I should be doing something wrong, or may be I'm not running the right set of versions ?

Can someone help me ? I want to go fast too :)

thetoof
2nd September 2008, 21:29
I had the same problem a little while ago. 2 things helped:
1 - Higher setmemorymax
2 (and better solution imo) - use the multithreaded version of MVTools and smode=0 in dfttest. With this, MT will be enabled without requiring a SetMTMode() or MT() call.
I also have a Q6600 and it works like a charm... you may have memory issues though with very ressource hungry scripts.

jeffy
2nd September 2008, 21:45
@pcat: If you are overclocking, you have to be sure that it is stable. If not, please disregard this comment.

pcat
2nd September 2008, 22:48
Thanks for the tips thetoof!
CPU is running stock speed Jeffy...

pcat
3rd September 2008, 10:23
I had the same problem a little while ago. 2 things helped:
1 - Higher setmemorymax
2 (and better solution imo) - use the multithreaded version of MVTools and smode=0 in dfttest. With this, MT will be enabled without requiring a SetMTMode() or MT() call.


@Thetoof, I looked at the MVTools page:
http://avisynth.org.ru/mvtools/mvtools.html

and all I see about multithread support refers to the "MT" plugin (enabled by setmtmode or MT(call)). What is the multithreaded MVTools version you are using ?

LaTo
3rd September 2008, 10:31
Look at the MVTools thread (http://forum.doom9.org/showthread.php?p=1177021#post1177021)

thetoof
3rd September 2008, 10:59
And you'll need another version of TemporalDegrain to run with the new syntax. Here's my mod which you can call with TemporalDegrainMT(source,prefiltered). There is also a new "tr" parameter that sets the temporal radius of the filtering. You can go from 1 to 32 (equivalent to MVDegrain1 to MVDegrain32).
#############################################################################
# Temporal Degrain V1.18b (April 5th, 2008) #
# Function by Sagekilla, original script created by Didée, mod by thetoof #
# #
# Works as a simple temporal degraining function that'll remove MOST grain #
# from video sources, including dancing grain, like the grain found on 300. #
# Is currently capable of utilizing MVDegrain 1, 2, or 3 for degraining #
# Also note, the parameters don't need to be tweaked much. #
# #
# Required plugins: FFT3DFilter.dll / mt_masktools / MVtools.dll #
# HQdn3D.dll / RemoveGrain.dll / Repair.dll #
# #
# FFT3DFilter: http://bag.hotmail.ru/fft3dfilter/fft3dfilter.dhtml #
# mt_masktools: http://manao4.free.fr/mt_masktools.html #
# MVtools: http://avisynth.org.ru/mvtools/mvtools.html #
# RemoveGrain: http://www.removegrain.de.tf/ #
# Repair: See above #
# HQdn3D: http://akuvian.org/src/avisynth/hqdn3d/ #
#############################################################################

########################################################
# Description of functions #
# denoise = Denoised clip for detecting motion vectors #
# pel = MVAnalyse Subpixel accuracy #
# blksize = MVAnalyse block size #
# ov = MVAnalyse block overlap #
# search = MVAnalyse search effort #
# dct = use of DCT for motion vector calculation #
# SAD1 = MVDegrain thSAD #
# SAD2 = MVDegrain thSAD #
# degrain = MVDegrain with 1, 2, or 3 vectors #
# HQ = Additional filtering after MVDegrain #
########################################################

function TemporalDegrainmt ( clip input, clip "denoise", int "pel", int "blksize", int "ov", int "degrain", int "limit", int "SAD1", int "SAD2", int "HQ", int "search", int "dct", bool "truemotion", int "tr")

{
o = input
pel = default( pel, 4) # Higher values increase motion vector quality at the cost of speed
blksize = default( blksize, 8 ) # Higher values are faster, less accurate, and degrain less
ov = default( ov, 4 ) # Increase for better motion vectors but slower speed
degrain = default( degrain, 3 ) # 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, 0 ) # Additional filtering after MVDegrain
search = default( search, 2 ) # MVAnalyse search effort
dct = default( dct, 0 ) # Use of DCT for motion vector calculation
truemotion=default(truemotion,true)
tr=default(tr,3)

# "srch" is a prefiltered clip on which the motion search is done.
srch = denoise


# "spat" is a prefiltered clip which is used to limit the effect of the 1st MV-denoise stage.
spat = denoise
spatD = mt_makediff(o,spat)


# Motion vector search (With very basic parameters. Add your own parameters as needed.)
mvectors = srch.MVAnalyseMulti(refframes=tr, pel=pel, overlap=ov, idx=1, blksize=blksize, dct=dct, search=search,truemotion=truemotion)

# First MV-denoising stage. Usually here's some temporal-medianfiltering going on.
# For simplicity, we just use MVDegrain.
NR1 = o.MVDegrainMulti(mVectors,thSAD=SAD1,idx=2,limit=limit)

NR1D = mt_makediff(o,NR1)


# Limit NR1 to not do more than what "spat" would do.
DD = mt_lutxy(spatD,NR1D,"x 128 - abs y 128 - abs < x y ?")
NR1x = o.mt_makediff(DD,U=2,V=2)


# Second MV-denoising stage. We use MVDegrain2.
NR2 = NR1x.MVDegrainMulti(mVectors,thSAD=SAD2,idx=3,limit=limit)

NR2 = (HQ==1) ? NR2.HQDn3D(1,1,4,1) : NR2 # Temporal filter to remove last bits of dancing pixels
NR2 = (HQ>=1) ? NR2.HQDn3D(2,1,6,1) : NR2 # A stronger version if the default isn't strong enough.

# Contra-sharpening: sharpen the denoised clip, but don't add more than what was removed previously.
# Here: A simple area-based version with relaxed restriction. The full version is more complicated.
s = NR2.minblur(1,1) # Damp down remaining spots of the denoised clip.
allD = mt_makediff(o,NR2) # The difference achieved by the denoising.
ssD = mt_makediff(s,s.removegrain(11,-1)) # The difference of a simple kernel blur.
ssDD = ssD.repair(allD,1) # Limit the difference to the max of what the denoising removed locally.
ssDD = SSDD.mt_lutxy(ssD,"x 128 - abs y 128 - abs < x y ?") # abs(diff) after limiting may not be bigger than before.

#s = NR2.minblur(1,1)
#allD = mt_makediff(o,NR2)
#SsD = mt_makediff(s,s.removegrain(11,-1)).removegrain(20,-1) # Larger radius for VHS
#ssDD = ssD.repair(ssD.repair(allD,1),1) # Larger radius for VHS
#ssDD = ssDD.mt_lutxy(ssD,"x 128 - abs y 128 - abs < x y ?")

NR2.mt_adddiff(ssDD,U=2,V=2) # Apply the limited difference. (Sharpening is just inverse blurring.)

output = last
return(output)
}

Fizick
4th September 2008, 05:42
pcat,
It is interesting (to find a problem), have you (or somebody else) any corrupted frames with simple MVTools example script from the doc?
May be several idx is a problem.

pcat
4th September 2008, 10:07
pcat,
It is interesting (to find a problem), have you (or somebody else) any corrupted frames with simple MVTools example script from the doc?
May be several idx is a problem.

No problems with the basic MVdegrain example, they only happen with MVtools used by the more complex scripts such as TemporalDegrain.

Good news:
Two TemporalDegrain jobs (previously with the issues) completed successfully this night without any corrupted frames. Only changes were "setmemorymax(768)" instead of 512 as suggested by Thetooth, and MVtools v1.10.2.1 instead of v1.9.5.7. I hope the issue is solved :-)
If it happen again I will try the TemporalDegrainMT...

Thanks to all of you for the help !

thetoof
4th September 2008, 18:01
Good to hear!
The thing is, scripts like TemporalDegrain need to access a lot of frames to filter the current frame, so it needs a lot of information in the cache, meaning that a lot of memory is required for the filter to work properly.