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 31st May 2021, 22:54   #1  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,389
"Feedback" - a filter that lets you use a filter chain's output as its own input

Feedback v0.1
Direct link


I think this one's a contender for my most esoteric filter yet.

Code:
Feedback
========

Feedback is a pair of filters that allow the output of a filter chain to be
passed back as an input, further up the chain, to be used in outputting the next
frame of the chain.

For example, it can be used to fill in the empty areas of a stablised clip by
compositing in the previous output frame (which itself will have been composited
using Feedback).

Usage
=====

FeedbackInput(
  (clip),
  (int) id
)

FeedbackOutput(
  (clip),
  (int) id
)

FeedbackInput will return frame 0 of its input clip as frame 0 of its output,
but after that it returns frame n-1 of the associated FeedbackOutput clip.

FeedbackOutput sets a clip as a source for a FeedbackInput clip.

The id parameter is optional, but must be given unique values whenever there is
more than one FeedbackInput/FeedbackOutput pair in a script environment.

Example
=======

Assume that you have a clip, with an alpha channel, that has been stabilised and
so has a moving black border around the stabilised image. Then you can composite
the stabilised clip on top of its previous frames by doing the following:

    Layer(stab.FeedbackInput(), stab).FeedbackOutput()

Frame 0 of the resulting clip will just be frame 0 of "stab" composited on itself.

Frame 1 will be frame 1 of "stab" composited on the previously composited frame (0)

Frame n will be frame n of "stab" composited on the previously composited frame (n-1)

Caveats
=======

Linear access is fast - FeedbackOutput keeps a copy of the previously-output
frame - but non-linear access will be slow as it will need to traverse all the
way back to the beginning of the FeedbackOutput clip.

Using Trim, or any other filter which changes the relative frame numbers of a
clip (e.g. ChangeFps or SelectEven) is probably not a good idea and could lead
to hangs or other strange behaviour.
__________________
My AviSynth filters / I'm the Doctor

Last edited by wonkey_monkey; 26th June 2021 at 13:55.
wonkey_monkey is offline   Reply With Quote
Old 31st May 2021, 23:26   #2  |  Link
kedautinh12
Registered User
 
Join Date: Jan 2018
Posts: 1,259
Thanks
kedautinh12 is offline   Reply With Quote
Old 31st May 2021, 23:44   #3  |  Link
Dogway
Registered User
 
Join Date: Nov 2009
Posts: 2,004
Nice, I might add it to Stab() as a new filling border option if it isn't too slow.
__________________
i7-4790K@Stock::GTX 1070] AviSynth+ filters and mods on GitHub + Discussion thread
Dogway is offline   Reply With Quote
Old 31st May 2021, 23:49   #4  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,389
It shouldn't cause any additional slowdown as long as frames are requested in order.
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is offline   Reply With Quote
Old 1st June 2021, 06:06   #5  |  Link
chmars
Registered User
 
Join Date: Apr 2021
Posts: 127
Very interesting, I am impressed.
chmars is offline   Reply With Quote
Old 1st June 2021, 13:00   #6  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,541
thanks, and if the previous frame has nothing to composite with?
__________________
See My Avisynth Stuff
real.finder is offline   Reply With Quote
Old 1st June 2021, 14:47   #7  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 2,583
Very interesting. When used with stabilization, as in your example, do you think it would produce better edge correction than what is contained in Depanstabilize, Deshaker, Mercalli, etc.?

Now that I've asked that, having spent 20+ years looking at the artifacts produced by Deshaker's edge correction, I wonder if Guner's (Deshaker author) code is doing somewhat the same thing. In fact, as I visualize what would happen with your function I'll bet this is almost exactly what he does, but of course his code is inside Deshaker, whereas your function is generalized to work with anything else one can dream up in AVISynth.

Nice job!
johnmeyer is offline   Reply With Quote
Old 1st June 2021, 14:49   #8  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,389
Quote:
thanks, and if the previous frame has nothing to composite with?
Can you elaborate?

Quote:
Very interesting. When used with stabilization, as in your example, do you think it would produce better edge correction than what is contained in Depanstabilize, Deshaker, Mercalli, etc.?
I've no idea how they work, so I don't know, but probably not. The example I've posted works because all the frames are near-perfectly aligned - if instead you had a smoothed, rather than 100% fixed-in-space clip, then you wouldn't get such a good result, unless you have a way of remapping the previous frame to align with the current one.
__________________
My AviSynth filters / I'm the Doctor

Last edited by wonkey_monkey; 1st June 2021 at 15:07.
wonkey_monkey is offline   Reply With Quote
Old 1st June 2021, 16:20   #9  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,541
Quote:
Originally Posted by wonkey_monkey View Post
Can you elaborate?
like in Scene changed
__________________
See My Avisynth Stuff
real.finder is offline   Reply With Quote
Old 1st June 2021, 16:59   #10  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,266
Quote:
I think this one's a contender for my most esoteric filter yet.
Yep, you watch way too much Dr Who
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 1st June 2021, 17:51   #11  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,389
Quote:
Originally Posted by real.finder View Post
like in Scene changed
It just serves the previous output frame as an input frame, regardless of what they contain or what is done with them, so scene changes aren't within its remit.

Quote:
Originally Posted by StainlessS View Post
Yep, you watch way too much Dr Who
Actually this filter came about because of a Star Wars project.
__________________
My AviSynth filters / I'm the Doctor

Last edited by wonkey_monkey; 1st June 2021 at 19:40.
wonkey_monkey is offline   Reply With Quote
Old 1st June 2021, 18:26   #12  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,541
I did update stab3 to use it (try with stab3(use_Feedback=true)), https://github.com/realfinder/AVS-St...ToolsPack.avsi

it's kinda a test update, let see if there any problem

edit: redownload it, I did another update that make it work even better
__________________
See My Avisynth Stuff

Last edited by real.finder; 1st June 2021 at 19:47.
real.finder is offline   Reply With Quote
Old 1st June 2021, 20:48   #13  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,266
Wow that was quick R.F, I'm still tryin' to figure out what it is and why it is
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 1st June 2021, 22:33   #14  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 2,583
Quote:
Originally Posted by StainlessS View Post
Wow that was quick R.F, I'm still tryin' to figure out what it is and why it is
It seems akin to reentrancy, something we all learned in the classroom, but always seemed to be difficult to get to work in the real world without causing problems (at least that was my experience). Hopefully this won't have memory issues, or lose its place (my problems the few times I tried having a function call itself).
johnmeyer is offline   Reply With Quote
Old 2nd June 2021, 01:16   #15  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,266
Thanx John, tis the Wonderful World of Wonkey Willy's Chocolate Factory,
Only the likes of Vincent Van Gogh would understand.
[That other nutter that chopped his ear off. You still got two ears Wonkey ?]
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 26th June 2021, 18:24   #16  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,389
Cellular automaton (Conway's Life) in Avisynth (play linearly from frame 0, don't try and seek because it will crash):

Code:
blankclip(pixel_type = "y8", width = 360 + 40, height = 360 + 100, length = 30000, fps = 60)

Expr("sx 176 == sy 204 == & sx 175 == sy 205 == & | sx 177 == sy 205 == & | sx 176 == sy 206 == & | sx 183 == sy 214 == & | sx 181 == sy 215 == & | sx 183 == sy 
215 == & | sx 180 == sy 216 == & | sx 181 == sy 216 == & | sx 183 == sy 216 == & | sx 179 == sy 218 == & | sx 180 == sy 218 == & | sx 181 == sy 218 == & | 255 0 ?")

FeedbackInput.Expr("x[-1,-1] x[0,-1] x[1,-1] x[-1,0] x[1,0] x[-1,1] x[0,1] x[1,1] + + + + + + + B^   B 510 == x 255 ? C^    B 765 > 0 C ? D^      B 510 < 0 D ?").FeedbackOutput

crop(20, 20, -20, -80) # required to hide gliders crashing at edges
__________________
My AviSynth filters / I'm the Doctor

Last edited by wonkey_monkey; 26th June 2021 at 18:27.
wonkey_monkey is offline   Reply With Quote
Old 13th July 2021, 21:45   #17  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,389
Something interesting from Blur/Shapen:

Code:
BlankClip(width = 32, height = 32, length = 30000).invert
AddBorders(944, 524, 944, 524)

FeedbackInput.Sharpen(1).Blur(1).FeedbackOutput
Even trippier when combined with my Warp plugin:

Code:
BlankClip(width = 32, height = 32, length = 30000).invert
AddBorders(944, 524, 944, 524)

FeedbackInput.Sharpen(1).Warp("
0,0, 0,-1
1920,0 1921.1,0
1920,1080 1920,1081.2
0,1080 -1.3,1080
").Blur(1).FeedbackOutput
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is offline   Reply With Quote
Old 14th August 2021, 23:39   #18  |  Link
Dogway
Registered User
 
Join Date: Nov 2009
Posts: 2,004
Hi wonkey_monkey! I'm testing your feedback snippets and it's very cool although the first one with Sharpen().Blur() crashed for me.

I'm also trying to implement it into ex_median() for the temporal modes but had some issues. I tested several combinations but all crash for me. To start I had to disable Prefetch(4) otherwise I would get an ID related error.

Code:
#        b  = a.selectevery(1,-1)
        b  = fb ? a.FeedbackInput() : a.selectevery(1,-1)
        f  = a.selectevery(1,+1)

        isy     ? Expr(a, b,     f,     str,                                  optSingleMode = false                     ) : \
        UV == 1 ? Expr(a, b,     f,     str, "",                              optSingleMode = false                     ) : \
                  Expr(a, b,     f,     str, ex_UVexpr(str, UV, bi, rgb, fs), optSingleMode = false, scale_inputs="none")

       fb ? FeedbackOutput() : last
__________________
i7-4790K@Stock::GTX 1070] AviSynth+ filters and mods on GitHub + Discussion thread
Dogway is offline   Reply With Quote
Old 19th August 2021, 22:50   #19  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,389
Difficult to say. Feedback is pretty unlikely to work well with Avisynth multithreading, and frame access should be linear. If you skip too many frames I think it ends up trying to calculate/load all the skipped frames into memory at once so there's a limit to how many frames you can skip. Same goes for reloading a script in VirtualDub when you're not on frame 0 already.
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is offline   Reply With Quote
Old 19th August 2021, 23:18   #20  |  Link
Dogway
Registered User
 
Join Date: Nov 2009
Posts: 2,004
Yes, the sharpen.blur script of yours that failed was because I had trim at the end. Anyways I solved it by calling it twice, halves the performance but if you have a better idea...


Code:
b  =         rc ? a.selectevery(1,-1).ex_median(mode,false,UV,fs,thr) : a.selectevery(1,-1)
f  =                                                                    a.selectevery(1,+1)
b2 = temp5 ? rc ? b.selectevery(1,-1) :                                 a.selectevery(1,-2) : nop()
f2 = temp5 ?                                                            a.selectevery(1,+2) : nop()
__________________
i7-4790K@Stock::GTX 1070] AviSynth+ filters and mods on GitHub + Discussion thread
Dogway 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 01:14.


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