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. |
|
|
Thread Tools | Search this Thread | Display Modes |
28th April 2017, 23:35 | #1 | Link |
Registered User
Join Date: May 2010
Location: Germany, Munich
Posts: 49
|
Looking for help with script for weighted averaging of frames for smooth motion blur
Hello,
It's been almost ten years since I last used Avisynth and so far I am still trying to figure out how to run Vapoursynth(VS) on OSX, so please excuse my beginner level questions. I would like to process 360° shutter high frame rate sources into standard frame rate clips by averaging multiple frames to get smooth motion blur. The attached image represents what I would like to do in VS:
-.01, -.03, -.03, -.06, 0, .17, .42, .69, .91, 1.0, .91., .69, .42, .17, 0, -.06, -.03, -.03, -.01 I understand averaging the five frames within the yellow, dotted verticals can be done like this with Avisynth (AS) but that is as far as I've just gotten. Code:
c1=selectevery(last, 4, 0) c2=selectevery(last, 4, 1) c3=selectevery(last, 4, 2) c4=selectevery(last, 4, 3) c5=selectevery(last, 4, 4) Average (c1, .69, c2, .91, c3, 1, c4, .91, c5, .69) Code:
SelectRangeEvery(clip, 5, 19, x) #19 calls of SelectRangeEvery where x=0 to 19 #and Average(c1, -.01,c2, -.03, c3, -.03, c4, -.06, c10, 1.0, ... c18, -.03, c19, -.01) To take this concept one step further - how to describe the frame weighting as a function, so faster speedup factors, different kinds of artificial motion blur (like asymmetrical functions or simulated shutter speeds of >360°) and keyframes are possible? Unfortunately on top of my lack of advanced scripting skills, the math (I guess AV's "Apply()" would be appropriate for this?) needed for functions is not my strong suit. :-( Additionally, since sometimes it is technically not possible to shoot 360° shutter but only around 180°-270°, is there an elegant way to pad this to 360° motion blur with MVtools, then apply the frame averaging (which should eliminate most if not all artefacts introduced by the fake 360° shutter motion blur)? I hope it became apparent what I am trying to achieve, if not - feel free to ask questions and I will do my best to answer them. Looking forward to what you guys can come up with and thanks in advance for looking into this. :-) JB Last edited by Joachim Buambeki; 30th April 2017 at 20:10. |
29th April 2017, 09:33 | #3 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
Some AVS links to threads here.
https://forum.doom9.org/showthread.p...ight=ClipBlend
__________________
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 ??? |
30th April 2017, 16:42 | #4 | Link | |
Registered User
Join Date: May 2010
Location: Germany, Munich
Posts: 49
|
Quote:
All those examples apply equal weight to the blending except this one, don't they? Can I do weighted blending with your plugin? Last edited by Joachim Buambeki; 30th April 2017 at 17:00. |
|
30th April 2017, 17:00 | #5 | Link | |
Retried Guesser
Join Date: Jun 2012
Posts: 1,373
|
Quote:
You might like this tip: I tuned the weighting with ShowFrameNumber(scroll=true) to identify all recent frames and judge the amount they are showing through. |
|
30th April 2017, 17:15 | #6 | Link | ||
Registered User
Join Date: May 2010
Location: Germany, Munich
Posts: 49
|
I just remembered that attachments take forever to get approved and uploaded the image to an imagehoster.
Quote:
Quote:
Also, what about precision? If you call overlay(), merge() or similar again and again, doesn't that hurt precision? If the weighted merging would be done in a separate plugin like StainlessS's Clipblend() with 32bit internal precision, wouldn't that be favourable? Last edited by Joachim Buambeki; 30th April 2017 at 17:20. |
||
30th April 2017, 17:20 | #7 | Link | |
Professional Code Monkey
Join Date: Jun 2003
Location: Kinnarps Chair
Posts: 2,555
|
Quote:
I guess this is what you want. And if it isn't then I'm not sure just how you want to combine those frames.
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet |
|
30th April 2017, 17:45 | #8 | Link | |
Registered User
Join Date: May 2010
Location: Germany, Munich
Posts: 49
|
Quote:
Yes, that is part of what I want, the problem is that with your proposition I merge the current and 9 adjacent frames into one, then merge the next 19 and so on, leaving me with a speedup factor of 19. What I want to do is take merge x frames (the number of frames "x" represents depends on the speedup factor and what kind of function is called - as said above, asymmetrical functions are also possible). Then move on by y frames (y is the speedup factor and always <x) and repeat. I assume the only thing missing to achieve what describe in my first post is a helper script that calculates the weighting based on a given function and the desired speedup factor. I know you can just put variables (that get calculated and served by the helper script) into the "AverageFrames()" call but how to do you implement varying frame amount? Would you just add a very high amount of variables into the AverageFrames()" call, where the first and last variables are zeros (if the function works with less frames) or is there a more elegant way to do this? To put it another way, I want to speed up the footage by a factor of y but use x amount of frames for each blend (where x>y), so the motion blur (trails) overlap from frame to frame. I hope it became clear what I am trying to do, please bear with me and my limited abilities to explain what my goal is. Last edited by Joachim Buambeki; 30th April 2017 at 17:54. |
|
30th April 2017, 18:14 | #9 | Link | |
Professional Code Monkey
Join Date: Jun 2003
Location: Kinnarps Chair
Posts: 2,555
|
Quote:
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet |
|
30th April 2017, 18:43 | #10 | Link | ||
Registered User
Join Date: May 2010
Location: Germany, Munich
Posts: 49
|
Thanks.
Quote:
Code:
Helperscript() #outputs weight (w1, w2, w3,...,w99) for each frame c.misc.AverageFrames(clip, [w1, w2, w4, ...,w99]) c.std.SelectEvery(clip, cycle=y, offsets=0) Quote:
TIA! Last edited by Joachim Buambeki; 30th April 2017 at 20:56. |
||
30th April 2017, 19:16 | #11 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
Sorry, no. and I gave up on trying to do weighted blend as I could not figure out a fast method to do it.
__________________
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 ??? |
30th April 2017, 20:34 | #12 | Link | |
Registered User
Join Date: May 2010
Location: Germany, Munich
Posts: 49
|
Quote:
@myrsloik, does AverageFrames() have any disadvantages to Clipblend() regarding precision? That image I posted is a polynomial of degree 4, right?! What would be an approximate function to describe it and how do I use this function to derive the weight of each frame (depending on the speedup rate)? Last edited by Joachim Buambeki; 30th April 2017 at 21:06. |
|
30th April 2017, 20:46 | #13 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
Clipblend is max 1/2 bit in error for 8 bit result. ClipBlend16, is again max 1/2 bit in error for STACK16 16 bit result.
(no dithering)
__________________
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 ??? |
30th April 2017, 21:36 | #14 | Link | |
Professional Code Monkey
Join Date: Jun 2003
Location: Kinnarps Chair
Posts: 2,555
|
Quote:
Exactly how did you get those numbers anyway? How accurate does it have to be? Chopped off sinc not good enough?
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet |
|
30th April 2017, 22:35 | #15 | Link | ||
Registered User
Join Date: May 2010
Location: Germany, Munich
Posts: 49
|
Quote:
Quote:
Here is a sketch for the script, obviously this is in AVS style and even there I don't really have an idea how to do it but it should give an idea what I have in mind. If you have any ideas what to improve conceptually or how to actually execute it, feel free to post it. :-) Code:
function haventcomeupwithacoolnameyet(parameters) { speedup = default( speedup, 5 ) # speedup rate, float pre_speedup = default( pre_speedup, 0 ) # if this offers no speed gain, use it to determine the threshold where more samples don't make the result any smoother shutter = default(shutter, 1 ) # 1 = symmetrical blend (the one posted) # 2 = asymmetrical blend # 3 = square shutter, can be >360°, rounded to nearest possible value # 4 = experimental idea, after first pass, pixels with higher local contrast are given more weight in second pass cutoff = default(false) # cutoff negative weights pad = default(false) # optional padding to 360° shutter for >360° shutter sources with MVtools before frame averaging, optional denoising warnings = default(true) # show only warnings OSD = default(false) # displays parameters, frame count pre/post and warnings bars = default(false) # visualises how blending works by generating blank clip with white bars on grey background with clip properties (optionally show video as pip in corner) # generate_frame_weights() outputs weight for each frame based on the selected blend type # For square shutters, round to multiple of 360°/speedup generate_frame_weights(speedup, shutter) #outputs weight for each frame based on the selected shutter type {however that might work...} # generates w1, w2, w4, ...,w99 c.misc.AverageFrames(clip, [w1, w2, w4, ...,w99]) } Last edited by Joachim Buambeki; 5th May 2017 at 16:55. |
||
|
|