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 28th September 2005, 13:10   #1  |  Link
mg262
Clouded
 
mg262's Avatar
 
Join Date: Jul 2003
Location: Cambridge, UK
Posts: 1,148
Average plug-in : weighted average of any number of clips; fast (500 FPS on 2 clips)

Average, 21 October 2005

Usage is

Average(clip, weight, clip, weight, clip, weight, ... ) #YV12 clips

For example, a simple average of clips alpha and beta is given by

Average(alpha, 0.5, beta, 0.5)

And for three clips

Average(alpha, 1.0/3, beta, 1.0/3, gamma, 1.0/3)

In action:


It uses (unoptimised) iSSE if present and otherwise falls back to C. On 720x576 source, the iSSE implementation runs at 500 FPS (2 clips), 270 FPS (4 clips) and 190 FPS (6 clips) on my Pentium 4/2400. (Measured, of course, by AVSTimer.)

It is probably best to make sure the weights sum to one; the plug-in will work fine if they don't but the average may not make sense. Audio is always taken from the first clip.

This can be used as a temporal average by using arguments like:

Alpha.trim(1, 0) #next
Alpha
Alpha.trim(0, -1) + Alpha #previous


With a little script work, this can be combined with the scene detection built into Cel Background to avoid averaging over scene boundaries; I'll explain how if one of the scripters out there is interested.

This release was brought to you by the Association for the Prevention of Cruelty to TemporalSoften.

Edit: iSSE added -- read next posts.

Last edited by mg262; 21st October 2005 at 17:09.
mg262 is offline   Reply With Quote
Old 28th September 2005, 13:57   #2  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,389
Hah!

Idea and realisation:

No speed rush for non-64bit Athlons:


Quote:
Originally Posted by mg262
This can be used as a temporal average ...

[...]

With a little script work, this can be combined [...] to avoid averaging over scene boundaries
... and probably some other tasks
__________________
- We´re at the beginning of the end of mankind´s childhood -

My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!)

Last edited by Didée; 28th September 2005 at 14:06.
Didée is offline   Reply With Quote
Old 28th September 2005, 14:43   #3  |  Link
mg262
Clouded
 
mg262's Avatar
 
Join Date: Jul 2003
Location: Cambridge, UK
Posts: 1,148
Why, Didée, you know I can't bear to see you unhappy

Since it was unoptimised assembly it was pretty straightforward to change to iSSE -- and for reasons I don't follow it is also four times faster. (Not that I'm complaining! I will analyse it when I have more time.) I assume Athlons can cope with this? In any case, please let me know if it doesn't seem to be working. Also, change for MMX would be pretty straightforward if needed.

Now a request for you, Didée: please consider making a filter wish list, for anything you want but especially for simple operations like this one...


Edit: the reason it was four times faster was as follows:

DVDepisode("1")#.crop(8, 2, -12, -2)average(last,1.0/6,Trim(1,0),1.0/6,Trim(2,0),1.0/6,Trim(3,0),1.0/6,Trim(4,0),1.0/6,Trim(5,0),1.0/6)
reduceby2()
o= last

a=o.Trim(3650, 3650+100)
b= o.Trim(4392, 4527) #Bridge
c=o.Trim(700, 800) #
s4(a.Subtitle("A"),b.Subtitle("B"),c.Subtitle("C"),Average(a, 0.2,b,0.4,c,0.4).Subtitle("Average(A,0.2, B,0.4, C,0.4)"))
#reduceby2()

#Average(a, 0.2,b,0.4,c,0.4)
#
o
AvsTimer(frames=1000, name="mpeg2dec", quiet=true)
#average(last,1.0/6,Trim(1,0),1.0/6,Trim(2,0),1.0/6,Trim(3,0),1.0/6,Trim(4,0),1.0/6,Trim(5,0),1.0/6)
#average(last,0.5,Trim(1,0), 0.5)
average(last,1.0/4,Trim(1,0),1.0/4,Trim(2,0),1.0/4,Trim(3,0),1.0/4)
AvsTimer(frames=1000, name="average", difference=1)



Last edited by mg262; 28th September 2005 at 14:46.
mg262 is offline   Reply With Quote
Old 28th September 2005, 16:26   #4  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,389
Thank you. Oh, and a nice method to squeeze 400% speed increase, indeed. Could work for other filters, too.

Okay, I consider. Problem is, when you shall think of something, then usually nothings comes into mind ...

BTW, above link starts with "http://http://..." - that's probably not correct.
__________________
- We´re at the beginning of the end of mankind´s childhood -

My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!)
Didée is offline   Reply With Quote
Old 28th September 2005, 17:08   #5  |  Link
mg262
Clouded
 
mg262's Avatar
 
Join Date: Jul 2003
Location: Cambridge, UK
Posts: 1,148
Oops -- link fixed. Thank you.

Don't worry about compiling something right away! Just as/if things occur to you while you are playing with scripts.

Edit: the " test for relevant instruction set" may still reporting an error as "sse2 not present"... but it's just that I forgot to change the other message; it really is testing for integer sse. Will fix in next version.

Last edited by mg262; 28th September 2005 at 17:10.
mg262 is offline   Reply With Quote
Old 29th September 2005, 05:54   #6  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,555
hey, cool. just 2 days ago i was trying to average 3 clips together to get one uber-clip... i was using ye olde interleave(1,2,3).temporalsoften(1,255,255).selectevery(3,1) to do it.

i like your method better
__________________
sucking the life out of your videos since 2004
Mug Funky is offline   Reply With Quote
Old 29th September 2005, 09:59   #7  |  Link
mg262
Clouded
 
mg262's Avatar
 
Join Date: Jul 2003
Location: Cambridge, UK
Posts: 1,148


Quote:
average 3 clips together to get one uber-clip... i was using ye olde interleave(1,2,3).temporalsoften(1,255,255).selectevery(3,1) to do it.
Doesn't the scene detection mess that up?

@Mug Funky + @Didée (plus anyone else who feels like chipping in),
Do you have preferred methods of scene detection?
mg262 is offline   Reply With Quote
Old 29th September 2005, 10:25   #8  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,555
not really... i set that to 255 as well. so long as you're selectevery-ing the correct frame, there's no bleeding between frames.

as far as preferred scene detection methods go... haven't really needed it, as filters that require it (MVtools stuff) tend to be too slow to use practically anyway.
__________________
sucking the life out of your videos since 2004
Mug Funky is offline   Reply With Quote
Old 29th September 2005, 13:13   #9  |  Link
mg262
Clouded
 
mg262's Avatar
 
Join Date: Jul 2003
Location: Cambridge, UK
Posts: 1,148
Right. Suppose you're taking a temporal average, radius two, like this:

A|B C D E

with a scene break between A and B.

Is it all right to take the five-point average

B B C D E

Or do you think it's necessary to take the four-point average

B C D E

? (The former is straightforward with the scene detection I have, I guess it's straightforward with ConditionalFilter as well, whereas the latter is possible but more fiddly and harder to generalised higher numbers.)
mg262 is offline   Reply With Quote
Old 21st October 2005, 16:24   #10  |  Link
MOmonster
Registered User
 
Join Date: May 2005
Location: Germany
Posts: 495
I used your Average filter that way:
Code:
Average(source.duplicateframe(0), -0.5, source, 1.0, source.trim(1,0), 1.0, source.trim(2,0), -0.5)
Now, with the avisynth 2.56 final it runs stable on my Pc, but I get a green stripe on the right side, see attachment. Do I something wrong?

I made some more test and I have still stability problems with the new avisynth version. I have a athlon XP 2000+ and a simple 256mp DDR.
I get this message when I use it in the function (have also problems with stand alone):
Evaluate: System exception - Access Violation
Attached Images
 

Last edited by MOmonster; 21st October 2005 at 16:45.
MOmonster is offline   Reply With Quote
Old 21st October 2005, 17:08   #11  |  Link
mg262
Clouded
 
mg262's Avatar
 
Join Date: Jul 2003
Location: Cambridge, UK
Posts: 1,148
Quote:
Do I something wrong?
No, I did! When I switched from sse2 to isse, the code changed to process four pixels at a time rather than eight... but there was a stray 8 sitting in the code that I didn't catch. (As it happens, that would have caused an access violation under some circumstances too...) As usual, problem caused by copy/paste... thank you for spotting it. Fixed version above... please let me know what the results of using it are.
mg262 is offline   Reply With Quote
Old 21st October 2005, 17:58   #12  |  Link
MOmonster
Registered User
 
Join Date: May 2005
Location: Germany
Posts: 495
@mg262
Thanks, now everything is running fine.
Really nice fast filter.
MOmonster is offline   Reply With Quote
Old 22nd October 2005, 03:23   #13  |  Link
foxyshadis
ангел смерти
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Lost
Posts: 9,558
Hey, I was wondering where all those Access Violations/crashes were coming from, I thought they were something I was doing wrong. I'll pick up this new version right away and start testing!
foxyshadis is offline   Reply With Quote
Old 22nd October 2005, 03:58   #14  |  Link
mg262
Clouded
 
mg262's Avatar
 
Join Date: Jul 2003
Location: Cambridge, UK
Posts: 1,148
Sorry about that!
mg262 is offline   Reply With Quote
Old 23rd October 2005, 23:16   #15  |  Link
AVIL
Registered User
 
Join Date: Nov 2004
Location: Spain
Posts: 408
humbly request

Hi,

I've used this filter (flawessly, by the way) and i love the possibilty of merge any number of clips i need. Moreover, i think it could be extended, to another colourspaces, and another modes of merge (calculation of median, instead of avegerage). Maybe will be necessary to use another name for the hipotetic new filters, but the central idea will be the same.
AVIL is offline   Reply With Quote
Old 24th October 2005, 06:32   #16  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,555
median is a great idea! that'd sort out stuff like overlaying multiple captures. would also be good for mocomped interleaving and stuff.
__________________
sucking the life out of your videos since 2004
Mug Funky is offline   Reply With Quote
Old 24th October 2005, 07:10   #17  |  Link
mg262
Clouded
 
mg262's Avatar
 
Join Date: Jul 2003
Location: Cambridge, UK
Posts: 1,148
More colour spaces should be quick. Median is possible but will be slow compared to the (assembly optimised) average -- unless you only want it for three clips?
mg262 is offline   Reply With Quote
Old 24th October 2005, 07:16   #18  |  Link
mg262
Clouded
 
mg262's Avatar
 
Join Date: Jul 2003
Location: Cambridge, UK
Posts: 1,148
Average, 24 October 2005

Should cope with any colourspace.
mg262 is offline   Reply With Quote
Old 24th October 2005, 07:41   #19  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,555
hmm. good point about the assembly and median stuff. i guess for median filtering weights would behave counter-intuitively, and it would be better handled with interleave(1,2,3).clense().selectevery(3,1)

[edit]

btw, thanks for the quick update
__________________
sucking the life out of your videos since 2004
Mug Funky is offline   Reply With Quote
Old 24th October 2005, 10:12   #20  |  Link
mg262
Clouded
 
mg262's Avatar
 
Join Date: Jul 2003
Location: Cambridge, UK
Posts: 1,148
If it's for a small, fixed, number, I think I might have a way of doing it reasonably fast in assembly. But I don't understand how you would even put weights in for median filtering? Unless you wanted to take the weighted average of minimum, median, and maximum (for 3 clips).
mg262 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 20:24.


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