digitalFAQ.com Forums [Archives]

digitalFAQ.com Forums [Archives] (http://www.digitalfaq.com/archives/)
-   Avisynth Scripting (http://www.digitalfaq.com/archives/avisynth/)
-   -   Avisynth: Motion adaptive filtering now possible? (http://www.digitalfaq.com/archives/avisynth/3594-avisynth-motion-adaptive.html)

kwag 05-15-2003 06:51 PM

Ok, this looks very promising :wink:

-kwag

sbin 05-15-2003 07:31 PM

Quote:

clip = ConvertToYV12( clip )
If you use MarcFD's mpeg2dec3, there is no need for this line because it supports native YV12.

http://ziquash.chez.tiscali.fr/

kwag 05-15-2003 07:40 PM

Quote:

Originally Posted by sbin
Quote:

clip = ConvertToYV12( clip )
If you use MarcFD's mpeg2dec3, there is no need for this line because it supports native YV12.

http://ziquash.chez.tiscali.fr/

Thanks :mrgreen: , I was beginning to wonder if there was a workaround :D

-kwag

sbin 05-15-2003 07:48 PM

Not that it's really relevant to the thread, but MarcFD never ceases to amaze me. He may not be the absolute best AVS filter author, but for a 17-year-old kid he writes some pretty darned amazing stuff. This guy is going to be bringing us a LOT of good stuff in the future.

kwag 05-15-2003 07:54 PM

Quote:

Originally Posted by sbin
but for a 17-year-old kid he writes some pretty darned amazing stuff.

8O 8O Damn, I wish I had a computer when I was 17 :cry:
If I had, then probably KVCD would have been a standard in every home on every DVD player :mrgreen:

-kwag

sbin 05-16-2003 01:45 AM

Ok, there is definitely a problem with the stmedianfilter and temporalsoften settings. Using the straight current script, I get a file size of 12,434k, which is actually smaller than what I get with the best motion adaptive settings in the new script. Here are some file sizes. When I say "motion adaptive" I mean I used the luma blurring values of 1.5/.75/.2. In the case of the current script, that means some colorspace conversions. :?

current script = 12,434k
current script + motion adaptive = 11,867k

new script = 13,404k
new script + motion adaptive = 12,598k

Although there is no doubt that motion adaptive filtering reduces file size, the new script overall is not as good as the current script. Then I started wondering which new filter was the culprit. I replaced temporalsoften with the old temporalsmoother(1,2) (and, of course, the accompanying colorspace conversion) and got a file size of 13,054k - somewhere in the middle. Replacing stmedianfilter with the old 2.0 version and current script values got me down to the same size as the current script.

So while the principle is sound, the script needs a lot of tweaking to be as good as the current script. The following script gave me my best file size to date (11,867k):
Code:

LoadPlugin("C:\Program Files\AviSynth 2.5\plugins20\LoadPluginEx.dll")
Loadplugin("C:\Program Files\AviSynth 2.5\plugins20\STMedianFilter.dll")
Loadplugin("C:\Program Files\AviSynth 2.5\plugins20\unfilter.dll")
Loadplugin("C:\Program Files\AviSynth 2.5\plugins20\legalclip.dll")
Loadplugin("C:\Program Files\AviSynth 2.5\plugins20\mpeg2dec.dll")


threshold_sm = 5
threshold_hm = 15
Width = 544
Height = 480

clip = Mpeg2Source("Z:\SPYLVESE\spy.d2v")
clip = ConverttoYUY2(clip)
clip = BilinearResize(clip, 544,368,5,0,710,480) 
clip = Crop(clip, 0, 44, -0, -44)
clip = STMedianFilter(clip, 10, 30, 0, 0, 10, 30)
clip = unfilter(clip, 50,50)
clip = temporalsmoother(clip, 1,2)
clip = ConverttoYV12(clip)
clip = Filter_Motion( clip, Width, Height, threshold_sm, threshold_hm)
clip = AddBorders(clip, 0,100,0,100)
clip = Limiter(clip)
clip = Sampler(clip, Length=24)

return clip

#####################
##### Functions #####
#####################

### High motion filtering
function Motion_High( clip High, float X, float Y)

High = mergechroma(High,blur(High,1.50))
High = mergeluma(High,blur(High,1.50))
Return High
}

### Medium motion filtering
function Motion_Medium( clip Medium, float X, float Y)
{
Medium  = mergechroma(Medium ,blur(Medium,1.50))
Medium  = mergeluma(Medium ,blur(Medium,.75))
Return Medium
}

### Low motion filtering
function Motion_Low( clip Low, float X, float Y)
{
Low  = mergechroma(Low ,blur(Low,1.50))
Low  = mergeluma(Low ,blur(Low,.20))
Return Low
}

### Detect high, medium, or low motion
function Detect_Motion( clip detect, clip Low, clip Medium, clip High, float threshold_sm, float threshold_hm)
{
global Courant_fr = detect
global Next_fr = detect.trim(1,0)
output1 = Conditionalfilter( Courant_fr, Low, Medium, "YDifferenceFromPrevious() + UDifferenceFromPrevious() + VDifferenceFromPrevious()", "<", "threshold_sm", false)
output2 = Conditionalfilter( Next_fr, output1, Medium, "YDifferenceFromPrevious() + UDifferenceFromPrevious() + VDifferenceFromPrevious()", "<", "threshold_sm", false)
output3 = Conditionalfilter( Courant_fr, High, output2, "YDifferenceFromPrevious() + UDifferenceFromPrevious() + VDifferenceFromPrevious()", ">", "threshold_hm", false)
output4 = Conditionalfilter( Next_fr, output3, output2, "YDifferenceFromPrevious() + UDifferenceFromPrevious() + VDifferenceFromPrevious()", ">", "threshold_hm", false)
return output4
}

### Filter the scene based on motion
function Filter_Motion( clip filter, float X, float Y, float threshold_sm, float threshold_hm)
{
Low = Motion_Low( filter, X, Y)
Medium = Motion_Medium( filter, X, Y)
High = Motion_High( filter, X, Y)
output = Detect_Motion( filter, Low, Medium, High, threshold_sm, threshold_hm)
return output
}


bman 05-16-2003 03:58 AM

Quote:

Originally Posted by sbin
The following script gave me my best file size to date (11,867k):

That's very interesting .
According your test it's worth to switch to AVS v2.51 !!???
This Filter combination is my favorite for almoast every my encodes .
What I'm interesting is If u can compare resulted clip quality to quality without Filter_Motion . To make it easy to understand let's say : with Motion CQ 60 and to get the same visual quality clip without Motion - CQ 65 .
It's easyer to see difference ( if there is any ) when we express it in numbers .
Please report if u have new results about Filter_Motion .
bman

jorel 05-16-2003 04:10 AM

Quote:

Originally Posted by sbin
Not that it's really relevant to the thread, but MarcFD never ceases to amaze me. He may not be the absolute best AVS filter author, but for a 17-year-old kid he writes some pretty darned amazing stuff. This guy is going to be bringing us a LOT of good stuff in the future.

you're right sbin!
:)

MarcFD is fantastic.
:!:

kwag 05-16-2003 07:32 AM

I just noticed that I can't use this script with ToK 8O :?
The current version of ToK sets the file prediction at the end of the script, and it doesn't work :roll:
I also tried to move it to the top, after the "clip = Mpeg2source( Source )" line, and it doesn't work either :cry:
I believe that Sampler.dll has been compiled for avisynth 2.5x :?:
I guess in order to use this method, we must use manual file size prediction :x until we can get a fix for using this with ToK :!:

-kwag

Jellygoose 05-16-2003 03:45 PM

amazing work, all of you! 8O
i hope this thread leads us to another big improvement in quality...
hopefully SansGrip can compile the sampler.dll to AviSynth2.51.

Isn't there some kind of integrated filter in the newest AviSynth version that does the same thing the sampler.dll?

Keep up the good work! I'll try this new stuff out tomorrow!
btw: can you run AviSynth2.0x and AviSynth2.5x at the same time?

Sagittaire 05-16-2003 05:05 PM

I am the author of this intelligent script. The objective of this intelligent script is of detecter the various types of motion and to apply filters specific. Here some French addresses to use this script correctly.

Downlaod
http://jfl1974.free.fr/HTM/Download.htm

FAQ filters avisynth
http://jfl1974.free.fr/HTM/21_Test_Filtres.htm

Comparative of the video codecs
http://jfl1974.free.fr/HTM/22_Test_Codec_Video.htm

FAQ ffdshow
http://jfl1974.free.fr/HTM/24_ffdshow.htm

And here the last version of this script. I added "subtitle" so that you observe how script works. You can modify the threshold to make script more or less senssible to the scene fast and slow ... :wink:

Code:

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

# AviSynth 2.51 #

# Script Motion Detection Filter YV12 #

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


#################################### Faq ...;-) ###################################


# MPEG2Dec3.dll #
# Convolution3DYV12.dll #
# FluxSmooth-2.5.dll #
# Unfilter.dll #

# Source : Path projet .d2v of DVD2AVI 1.76 #
# CPU_type : you will choose 5 for Pentium IV and 2 for the other processors #

# Threshold : adjustment of the threshold of detection of the scenes #

# Top : Crop top of the image #
# Left : Crop left of the image #
# Right : Crop right of the image #
# Bottom : Crop bottom of the image #

# DimX : Width of the image #
# DimY : Height of the image #

# Start : Start Frame #
# End : End Frame #



#################################### Variables ####################################


Source = "C:\Stock\azerty.d2v"
CPU_type = 2

threshold_sm = 5
threshold_hm = 15

Top = 76
Left = 16
Right = 16
Bottom = 74

DimX = 640
DimY = 272

Start = 0
End = 0



################################# Script Principal ################################


clip = Mpeg2Source( Source, idct = CPU_type)
clip = Trim( clip, Start, End)
clip = Crop( clip, Left, Top, -Right, -Bottom)
clip = lumafilter( clip, 0, 0.9)
clip = Unfilter( clip, +4, +4)
clip = Filter_Motion( clip, DimX, DimY, threshold_sm, threshold_hm)
clip = FluxSmooth( clip, 5, 3)
clip = limiter( clip)
Return clip



#################################### Fonctions ####################################


# Motion_Hight : function of filtering of fast scenes #

function Motion_Hight( clip Hight, float X, float Y)

{

Hight = Convolution3D( Hight, 0, 8, 12, 8, 12, 3, 0)
Hight = BicubicResize( Hight, X, Y, 0.33, 0.33)
Return Hight.subtitle("Hight")

}



# Motion_Medium : function of filtering of Mediums scenes #

function Motion_Medium( clip Medium, float X, float Y)

{

Medium = Convolution3D( Medium, 0, 4, 6, 4, 6, 2.75, 0)
Medium = BicubicResize( Medium, X, Y, 0, 0.5)
Return Medium.subtitle("Medium")

}



# Motion_Slow : function of filtering of Slow scenes #

function Motion_Slow( clip Slow, float X, float Y)

{

Slow = Convolution3D( Slow, 0, 2, 3, 2, 3, 2.5, 0)
Slow = BicubicResize( Slow, X, Y, 0, 0.7)
Return Slow.subtitle("Slow")

}



# Detect_Motion : function of detection of scenes slow, medium and rapid #

function Detect_Motion( clip detect, clip Slow, clip Medium, clip Hight, float threshold_sm, float threshold_hm)

{

global Courant_fr = detect
global Next_fr = detect.trim(1,0)

output1 = Conditionalfilter( Courant_fr, Slow, Medium, "YDifferenceFromPrevious() + UDifferenceFromPrevious() + VDifferenceFromPrevious()", "<", "threshold_sm", false)

output2 = Conditionalfilter( Next_fr, output1, Medium, "YDifferenceFromPrevious() + UDifferenceFromPrevious() + VDifferenceFromPrevious()", "<", "threshold_sm", false)

output3 = Conditionalfilter( Courant_fr, Hight, output2, "YDifferenceFromPrevious() + UDifferenceFromPrevious() + VDifferenceFromPrevious()", ">", "threshold_hm", false)

output4 = Conditionalfilter( Next_fr, output3, output2, "YDifferenceFromPrevious() + UDifferenceFromPrevious() + VDifferenceFromPrevious()", ">", "threshold_hm", false)

return output4

}



# Filter_Motion : function of filtage of scenes slow, medium and rapid #

function Filter_Motion( clip filter, float X, float Y, float threshold_sm, float threshold_hm)

{

Slow = Motion_Slow( filter, X, Y)
Medium = Motion_Medium( filter, X, Y)
Hight = Motion_Hight( filter, X, Y)
output = Detect_Motion( filter, Slow, Medium, Hight, threshold_sm, threshold_hm)
return output

}

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


kwag 05-16-2003 06:00 PM

Welcome Sagittaire :)
We've been playing and modifying your script :wink:

-kwag

kwag 05-16-2003 06:07 PM

Quote:

Originally Posted by Jellygoose
btw: can you run AviSynth2.0x and AviSynth2.5x at the same time?

Hi Jellygoose,

The script will work only on AviSynth 2.5x, because the heart of the script is the "Conditionalfilter" function :)
It won't be long before we convert this to a linear strength filter instead of three filter bracket ranges (Low, Medium, High), and integrate the new algorithm into MovieStacker ( Hello muaddib :mrgreen: ) :wink:

-kwag

ovg64 05-16-2003 06:15 PM

OK Sagittaire is this going to work with our KVCDs, cause that looks like a Divx site and is like in frensh language :?: I don't understand frensh :?: :wink:

kwag 05-16-2003 06:22 PM

Hi ovg64,

Check page 2 of this thread. It's been translated to english.

-kwag

muaddib 05-16-2003 07:40 PM

Quote:

Originally Posted by kwag
I just noticed that I can't use this script with ToK 8O :?
The current version of ToK sets the file prediction at the end of the script, and it doesn't work :roll:
I also tried to move it to the top, after the "clip = Mpeg2source( Source )" line, and it doesn't work either :cry:
I believe that Sampler.dll has been compiled for avisynth 2.5x :?:
I guess in order to use this method, we must use manual file size prediction :x until we can get a fix for using this with ToK :!:

-kwag

Hey kwag,

Did you try to move ALL functions to the top of the script?
I did not try the script yet, but it "should" work... :roll:

muaddib 05-16-2003 07:52 PM

Quote:

Originally Posted by kwag
The script will work only on AviSynth 2.5x, because the heart of the script is the "Conditionalfilter" function :)
It won't be long before we convert this to a linear strength filter instead of three filter bracket ranges (Low, Medium, High), and integrate the new algorithm into MovieStacker ( Hello muaddib :mrgreen: ) :wink:

Hi K man! We will sure do that! 8) :mrgreen:
I didn't have time to put my hands in this great script (thanks Sagittaire), but don't stop... It's getting exciting! :wink:

kwag 05-16-2003 08:41 PM

You know, this thread reminds me something I exposed several months ago, read here: http://www.kvcd.net/forum/viewtopic.php?t=2834
And instead of using a long script to do all of this, if one of SansGrip's filters could be modified ( NoMoSmooth :idea: ) to include "attached" avisynth functions like mergechroma, mergeluma, etc, then we could use the temporal motion engine built-in this filter :!:
This way, it would work just like any other avisynth filters. For example, BlockBuster has tresholds to apply noise, depending on the darkness of the picture. NoMo applies filtering, depending on difference between adjacent frames. So this engine can be applied to "call" mergeluma or other filters, depending on selected activity "trigger" points.
SansGrip, where are you :D
The result: "Automatic Linear Motion Adaptive Filtering"
And that is what we need 8)

-kwag

sbin 05-17-2003 12:12 AM

Greetings all. I haven't had much time to play with this today, because I had to do some work at my paying job. :( But hopefully I can spend some quality time with this now that the weekend is here. :drink:

Quote:

btw: can you run AviSynth2.0x and AviSynth2.5x at the same time?
You can, but there's not much need to since loadpluginex.dll will allow you to run 2.0 filters in 2.5x.

But if you want to run both versions, you can make 2 virtualdub folders and put the different avisynth.dll versions in each folder. Then just start whichever Virtualdub version you want to use. Not sure how that works with frameserving directly to TMPGEnc, though.... never tried it.

jorel 05-17-2003 01:14 AM

:)
Sagittaire
welcome! :wink:

great pages and great job.
the result will be amazing

:!:


All times are GMT -5. The time now is 04:40 AM  —  vBulletin © Jelsoft Enterprises Ltd

Site design, images and content © 2002-2024 The Digital FAQ, www.digitalFAQ.com
Forum Software by vBulletin · Copyright © 2024 Jelsoft Enterprises Ltd.