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 1st November 2004, 15:18   #1  |  Link
Manao
Registered User
 
Join Date: Jan 2002
Location: France
Posts: 2,856
MVTools

Hi everybody

Since there was no dedicated thread for the MVTools on the usage forum, I create one. It's bundled with (yet another) new version of the MVTools.

You can fetch it here : http://manao4.free.fr/MVTools-v0.9.8.zip

A lot of things have changed since the latest version, but most of the changes are internal. However, some filters'parameters were changed ( MVAnalyse, MVCompensate, MVDenoise ). Two filters were added ( Deblock and MVChangeCompensate ), some were temporarily ( MVInterpolate, MVBlur, MVConvertFPS ) or definitively removed ( EncDenoise ).

The main change for this release is that a vector stream now contains a lot of information : for each blocks, it stores the motion vector, the SAD, but also the mean luminance of the source block and of the reference block, and an approximation of the standard deviation of the source block, and the reference block itself.

That means that, by default, a mv stream already contains the result of the motion compensation ( for luminance and chrominance ). Hence, MVCompensate becomes ( in one of its mode ) a mean of extracting the compensation from the stream. And, of course, you may want to filter it and put it back into the stream, and that's the role of MVChangeCompensate. For example, to deblock the compensation, just do the following :
Code:
vectors = source.MVAnalyse(isb = false, lambda = 1000)
compensation = source.MVCompensate(vectors, mode = 0)
compensation = compensation.Deblock()
vectors = vectors.MVChangeCompensate(compensation)
Now, that change has a great influence on MVDenoise. At the beginning, that filter was only compensating the previous and next frames in order to denoise. That wasn't enough, and I added a hack in order to compensate twice the frames n-2 and n+2, in order to work on 5 frames ( which allows a better denoising ). But it was slow, and the hack was creating a lot of blocking.

Now, since the compensation are stored inside the mv stream, and since you can make a mv search between frame n and n-delta easily ( I added a parameter 'delta' to MVAnalyse ), MVDenoise can take an unlimited number of mv streams as input, and will use all of them to denoise the source.

And, to avoid blocking, you can now deblock the compensations before feeding them to MVDenoise.

Finally, the 'pel' parameter is now limited to 1 or 2 only, but works for all filters.

Now, what's left to do ? The temporal interpolations will come back, but they need a lot of work to be more than left-artifacts-all-around filters. There is still room for optimisations ( when 'pel' = 2, I interpolate the source and the reference 2 times ( one when the frame is the source, the second when the frame becomes the reference ), and when MVAnalyse is used several times on the same clip, the interpolations are recomputed each times ).

Also, MVDenoise need a better algorithm in order to denoise ( Didee, I'm still waiting for your ideas ). Right now, it's only merging together collocated pixels which respects the thresholds. Something better can be done, and it can be changed very easily, so any ideas are welcomed ( BTW, i take into account the mean luma of the source and reference block when doing the merging, it avoids some artifacts when luminance was changing from a frame to another, but it still leaves a slight blocking ).

I'm sure I forgot a lot of things, and that there are still slight bugs left into the code, so I'm waiting for your impressions.

Last edited by Manao; 20th January 2005 at 22:06.
Manao is offline   Reply With Quote
Old 1st November 2004, 16:27   #2  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,547
thankyou very much! a new toy
__________________
sucking the life out of your videos since 2004
Mug Funky is offline   Reply With Quote
Old 3rd November 2004, 08:32   #3  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,547
little bump here...

would it be possible to have some kind of adaptive block-replacement going for the looping MVcompensate? sort of like the I-block/P-block decisions that encoders use.

this would be good for using the mode=2 mvcompensate in a denoiser. right now i'm using a very low value of thSCD1 (about 15-ish) to prevent the picture going too wibbly, and i can certainly use masks for the rest of the artefact prevention, but it would be good to have a kind of block change detection to mimimize redunancy on long near-static scenes.

no hurry - simple scenechange detection works well. i'm seeing just how much compression gain/denoising i can get out of MVtools. my aim is around 50-60% the size of a non-denoised encode. i'm getting close
__________________
sucking the life out of your videos since 2004
Mug Funky is offline   Reply With Quote
Old 3rd November 2004, 09:10   #4  |  Link
Manao
Registered User
 
Join Date: Jan 2002
Location: France
Posts: 2,856
That can easily be added. I'll do it. Meanwhile, you should be able to test that idea ( on luma only ) using MVdenoise :
Quote:
vectors = source.MVAnalyse(isb = false)
blended = source.MVDenoise(vectors, thSAD = XXX, thMV = YYY, thT = 256)

return yv12LUTxy(blended, source, yexpr = "x 2 * y -", u=2, v=2)
I didn't test it, but it should amount to the same.
Manao is offline   Reply With Quote
Old 3rd November 2004, 10:27   #5  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,547
right now i'm doing something similar to "forced block skipping". ie, if the difference between a looped compensate and the source is small enough, the looped compensate is used. it doesn't really remove much grain, but after encoding with xvid, the grain is somehow gone. plus it's quite fast .

i'm just doing a test encode with it now.

also, an advantage of looped compensation to me is that i can encode difficult-to-IVTC sources at double framerate, and i don't lose denoise effectiveness from all the duplicated frames.
__________________
sucking the life out of your videos since 2004
Mug Funky is offline   Reply With Quote
Old 3rd November 2004, 10:47   #6  |  Link
Manao
Registered User
 
Join Date: Jan 2002
Location: France
Posts: 2,856
I should have read your post entirely. You can't achieve denoising with MVcompensate mode 2 and intra block. The all thing behind MVDenoise is to make the strongest possible temporal denoising. MVCompensate only takes the noise from one frame to another.

If you want strong denoising, use MVdenoise, with 4 or 6 mvstreams, all deblocked through Deblock(quant = 30), and with high sad / mv / temporal threshold for MVDenoise.
Manao is offline   Reply With Quote
Old 3rd November 2004, 14:33   #7  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,547
i'm looking more for a compression gain, actually. the encoder seems to handle the noise pretty well. i'm thinking of I-blocks just as a way of stopping error accumulating (though masking seems to be working pretty well), while still letting through the parts that are still good (rather than forcing a scenechange).

on another note, i can't seem to get mvtools to finish a full encode - i get an access violation at about the 30000 frame mark (it varies). haven't been able to track it down, because 30000 frames is a long time to be without my computer.

plugins i'm using on my last encode to do this are:

dgdecode
tdeint
removegrain
masktools
mvtools

i don't think it's tdeint or dgdecode, as i've done a full length encode with them. it's either mvtools, or masktools (i'm not certain about removegrain, but i think i've had this crash without it).

i'm on win2k sp2, p3-733, 384 sdram.

[edit]
i'm also using VirtualDubMod as well (it's a little unstable of late), but i've had this crash in other apps as well (mencoder via AVIS, and QuEnc)
__________________
sucking the life out of your videos since 2004
Mug Funky is offline   Reply With Quote
Old 3rd November 2004, 14:36   #8  |  Link
Manao
Registered User
 
Join Date: Jan 2002
Location: France
Posts: 2,856
Thank for the report, I'll check that ( this week-end ). I never tried it on long sequence, so it's more than possible than MVTools are guilty.
Manao is offline   Reply With Quote
Old 3rd November 2004, 15:10   #9  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,547
ah, okay. i have no idea what it could be. maybe a memory problem? i haven't explicitly looked for a corellation between how early it crashes and how big the frames are. but i seem to remember a larger framesize encode crashing much earlier (this could be imagination).
__________________
sucking the life out of your videos since 2004
Mug Funky is offline   Reply With Quote
Old 8th November 2004, 07:35   #10  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 1,778
mvtools slow motion - can it still be done?

I have used mvtools version 0.9.2.2 to create smooth slow motion, using this script:
Code:
loadplugin("c:\Program Files\AviSynth 2.5\plugins\kerneldeint140.dll")
loadplugin("C:\Program Files\AviSynth 2.5\plugins\MVTools\mvtools.dll") 

AVISource("E:\Volleyball\Volleyball (Soldedad)\Volleyball (soledad)0022.avi")
assumebff()
changespeed(4, 2, 8) #1/4 speed, using motion compensated frame interpolation (motion will stay smooth)

function changespeed(clip a, float factor, int mode, int th)
{
	ord = getparity(a) ? 1 : 0
	f=a.kerneldeint(order=ord, sharp=false, twoway=false, threshold=th) 
	e=a.separatefields.trim(1,0).weave.kerneldeint(order=1-ord, sharp=false, twoway=false, threshold=th)
	interleave(f,e).assumeframebased
#	converttoyuy2() # not needed if mode=2 saves extra conversion by commenting out

        (mode == 0) ? changefps(framerate*factor) : (mode == 1) ? convertfps(framerate*factor) : converttoyv12().mvconvertfps(fps=framerate*factor).converttoyuy2()
	assumefps(a.framerate*2,true)
	separatefields()
	(ord==0) ? selectevery(4,0,3) : selectevery(4,1,2)
	weave()
	
}
This worked well with this version, but I cannot get any later version to even load, much less do the slow motion. Also, in looking at the release notes for the latest version, I see that mvconvertfps() has temporarily been deleted.

Question: Is there a better way to generate slow motion using motion-estimated synthesized frames, using another AVISynth plug-in, like Depan? Also, is there any way to use later mvtools versions? With any version after 0.9.2.2 I get this error message:

AVISynth Open Failure.
Evaluate: Unrecognized exception!
johnmeyer is offline   Reply With Quote
Old 8th November 2004, 13:43   #11  |  Link
Manao
Registered User
 
Join Date: Jan 2002
Location: France
Posts: 2,856
The way of using the MVTools changed after v0.9.2.2. So it's normal that your script doesn't work. Moreover, temporal interpolators are disabled for version > 0.9.5, because they are being rewritten.

So I'd advise you to fetch v0.9.5, look into the documentation to see how to adapt your script to the new syntax. The main change is that you have to use two stages : one (or several) filter which analyses the clip and create a motion vectors streams, and another filter which takes the clip and one or several vectors streams and which does the actual processing.
Manao is offline   Reply With Quote
Old 8th November 2004, 19:10   #12  |  Link
Heini011
Registered User
 
Join Date: Nov 2003
Posts: 148
Hi,

little errors in the docu:

version: 0.9.5

III) Examples
...
To denoise :
...
return source.MVDenoise(backward_vectors1, backward_vectors1, forward_vectors1 ...

---
does the order of backward_vectors1, backward_vectors2 matter ?

can i use 'backward_vectors1, forward_vectors1' only ?

---
many thanks for your really great work!!

best regards.
Heini011 is offline   Reply With Quote
Old 8th November 2004, 19:12   #13  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 1,778
OK, I revised the script using MVTools v0.9.5. I have it working pretty well, but would REALLY appreciate any hints as to which settings -- either in the deinterlace, or in MVTools -- I should try changing in order to improve the results.

My source is interlaced NTSC DV AVI, and I plan to print back to a NTSC DV tape and view on an NTSC monitor. The test clip is a volleyball game, with the camera panning back and forth, and lots of action (inluding the ball) moving in front of the camera.

I am now getting very smooth, clear slow motion, but still sometimes get single frame "glitches," even in areas that are not moving much. I am VERY close to making this work really well.
Code:
loadplugin("c:\Program Files\AviSynth 2.5\plugins\kerneldeint140.dll")
loadplugin("C:\Program Files\AviSynth 2.5\plugins\MVTools\mvtools.dll") 

AVISource("E:\Volleyball\Volleyball (Soldedad)\Volleyball (soledad)0022.avi")

assumebff()
changespeed(4, 8) #Change to 1/4 speed (slow motion)

function changespeed(clip a, float factor, int th)
{

  ord = getparity(a) ? 1 : 0
  f=a.kerneldeint(order=ord, sharp=false, twoway=false, threshold=th) 
  e=a.separatefields.trim(1,0).weave.kerneldeint(order=1-ord, sharp=false, twoway=false, threshold=th)
  g=interleave(f,e).assumeframebased
  h=converttoyv12(g)

  vec_back = h.MVAnalyse(sx=8, sy=8, fth=20, isb=true)
  vec_forw = h.MVAnalyse(sx=8, sy=8, fth=20, isb=false)
  MVConvertFPS(h, vec_back, vec_forw, fps=h.framerate*factor, fbw=2, thSCD2=255, thSCD1=200)

  converttoyuy2()
  assumefps(a.framerate*2,true)
  separatefields()
  (ord==0) ? selectevery(4,0,3) : selectevery(4,1,2)
  weave()
}

Last edited by johnmeyer; 8th November 2004 at 19:42.
johnmeyer is offline   Reply With Quote
Old 8th November 2004, 19:14   #14  |  Link
Manao
Registered User
 
Join Date: Jan 2002
Location: France
Posts: 2,856
The documentation on my webpage is for 0.9.7 only. However, a documentation is bundled with 0.9.5 : it is made of several html documents and you ought to refer to this one when using v0.9.5. Sorry for not having made that clear in the online documentation.
Manao is offline   Reply With Quote
Old 8th November 2004, 19:21   #15  |  Link
Manao
Registered User
 
Join Date: Jan 2002
Location: France
Posts: 2,856
johnmeyer : these filters have always been more experimental than stable. The glitches you're experiencing are due to the crudeness of the code, and I don't think you'll find settings good for the whole movie. This is why I'm rewritting these filters.
Manao is offline   Reply With Quote
Old 8th November 2004, 19:31   #16  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 1,778
Hey, I am not complaining!

If these are experimental, I'd love to see something you consider finished. It must be amazingly good.
johnmeyer is offline   Reply With Quote
Old 9th November 2004, 22:53   #17  |  Link
Heini011
Registered User
 
Join Date: Nov 2003
Posts: 148
Hi Manao,

work the following 2 functions identical and if not, which does it right ??

function mvdenoise1(clip) {
backv2 = clip.MVAnalyse(isb=true, blksize=4, pel=2, lambda=1000, delta=2)
backv1 = clip.MVAnalyse(isb=true, blksize=4, pel=2, lambda=1000, delta=1)
forwv1 = clip.MVAnalyse(isb=false, blksize=4, pel=2, lambda=1000, delta=1)
forwv2 = clip.MVAnalyse(isb=false, blksize=4, pel=2, lambda=1000, delta=2)
return clip.MVDenoise(backv1, backv2, forwv1, forwv2, thT=10, thSAD=64, thMV=100, thSCD1=80)
}


function mvdenoise2(clip) {
{...}
return clip.MVDenoise(backv2, backv1, forwv1, forwv2, thT=10, thSAD=64, thMV=100, thSCD1=80)
}

thanks!
Heini011 is offline   Reply With Quote
Old 10th November 2004, 06:37   #18  |  Link
Manao
Registered User
 
Join Date: Jan 2002
Location: France
Posts: 2,856
Both should work correctly. Order of the vectors streams does'nt matter anymore in MVDenoise.
Manao is offline   Reply With Quote
Old 10th November 2004, 13:04   #19  |  Link
Heini011
Registered User
 
Join Date: Nov 2003
Posts: 148
mvdenoise from MVTools 0.97 seems to be buggy: it produces much ghosting where MVTools 0.96.2 works great.

Use this code for testing purpose:

---------------------------------
MVTools 0.96.2:

function mvdenoise2(clip) {
backv = clip.MVAnalyse(isb=true, sx=4, sy=4, pel=1, lambda=1000)
forwv = clip.MVAnalyse(isb=false, sx=4, sy=4, pel=1, lambda=1000)
return clip.MVDenoise(backv, forwv, thT=100, sadT=1000, thMV=1000, thSCD1=1000)
}

---------------------------------
MVTools 0.97:

function mvdenoise2(clip) {
backv2 = clip.MVAnalyse(isb=true, blksize=4, pel=1, lambda=1000, delta=2)
backv1 = clip.MVAnalyse(isb=true, blksize=4, pel=1, lambda=1000, delta=1)
forwv1 = clip.MVAnalyse(isb=false, blksize=4, pel=1, lambda=1000, delta=1)
forwv2 = clip.MVAnalyse(isb=false, blksize=4, pel=1, lambda=1000, delta=2)
return clip.MVDenoise(backv1, backv2, forwv1, forwv2, thT=100, thSAD=1000, thMV=1000, thSCD1=1000)
}
---------------------------------
Heini011 is offline   Reply With Quote
Old 10th November 2004, 13:44   #20  |  Link
Manao
Registered User
 
Join Date: Jan 2002
Location: France
Posts: 2,856
I found the bug, a new version will be online late tonight, or tomorrow. Thanks for the report.

I wonder what you're filtering, because thT = 100 is very high.
Manao 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 05:57.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.