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. |
11th June 2013, 11:45 | #1 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,011
|
ClipBlend/ClipBlend16 v1.01 - 27 Nov 2018.
ClipBlend v1.01. For Avs v2.58, v2.60/+, Avs+ x64.
Requires VS2008 CPP Runtimes. Prompted by this thread: http://forum.doom9.org/showthread.php?t=168001 Code:
ClipBlend(clip,"delay"=0) # 8 bit Planar, YUY2, RGB ClipBlend16(clip,"delay"=0) # 16 bit, Stack16 Planar, YUY2, RGB (see Dither Tools) Added Delay arg to plugin. Delay, default = 0, == ALL frames played so far blended. 1 = blend with previous frame ie two frames blended. 10 = blend with 10 previous frames, ie 11 frames blended, etc. Accumulator resets at frame 0. To get average of all frames 0 to frame 300 # ------------------------ FRM =300 # Required frame number Avisource("D:\avs\test.avi") ClipBlend() # Default delay=0 ie all previous frames Trim(FRM,-1) # Get Required frame return Last # ------------------------ Or to get a single frame average of all frames in a clip # ------------------------ Avisource("D:\avs\test.avi") ClipBlend() return Trim(FrameCount-1,-1) # ------------------------ How ClipBlend it works ClipBlend() uses a single 32 bit accumulator (unsigned int) for each channel of each pixel x,y position in the clip frame. With a maximum possible value per pixel/channel being 255 ie 8 bits, this leaves 24 bits available for accumulating the sum of values for that pixel/channel position, ie adding the values for that pixel/channel from every selected frame in the blended range. The additional 24 bits would allow for up to ~16 Million (2^24) frames to be summed, however we also need another bit to maintain maximum precision possible for 8 bit result, so reducing maximum possible frame range to ~8 million frames. Code: Return Avisource("test.avi").ClipBlend(delay=0).Trim(999,-1) # 1000 frames, 1000 values per accumulator, ie max 1000*255 Above would sum (each channel/pixel) with maximum possible sum for an accumulator being 1000*255 (about 18 bits, 2^10=1024,2^8=256) As clipblend scans frames, it adds the channel/pixel values at each x,y position to the accumulators, for all of the required frames. If delay = 0, it just adds next frame values to the accumulators. If eg delay=10, and current scanned range is already 10, it subtracts the channel/pixel values of the oldest frame (lowest number) and then adds the values for the next frame to the accumulators. When delivering the result (delay=whatever), it just divides the accumulated sum by the number of sample frames to get the average, and writes it to the relevant pixel/channel/x/y position, could not be simpler. Implementation is equivalent to this: int((accumulator / Float(FramesDone) + 0.5) The actual implementation and reason for the extra needed bit that was mentioned (ie accumulator*2): ((accumulator*2) + FramesDone) / (FramesDone*2) The *2 pair and addition of FramesDone is the integer equivalent of division, adding 0.5 and taking Int() whist maintaining max possible precision at 8 bits result. StainlessS With a delay of maybe 7, produces effect that I think they used to use on Top Of The Pops. Should play in real time. Might be useful for isolating static opaque logos. See Mediafire in sig.
__________________
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 ??? Last edited by StainlessS; 27th November 2018 at 15:35. |
23rd March 2015, 10:31 | #2 | Link |
Registered User
Join Date: Sep 2005
Location: Moscow, Russia
Posts: 66
|
Hello StainlessS!
Please can you help me with your plugin ClipBlend. I need to blend every 40 frames and after that to skip every 39 of 40. I run the following script: ClipBlend(delay=40) SelectEvery(40, 39) But it doesn't work, frames are not blended. I found that I need to force process all frames in my clip, but from your sample script it's not clear for me how do it. Please can you advise me with that! |
23rd March 2015, 12:48 | #3 | Link | |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,011
|
Quote:
I'll take a look at it and see if I can do anything.
__________________
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 ??? Last edited by StainlessS; 24th March 2015 at 18:27. |
|
24th March 2015, 17:18 | #4 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,011
|
@Kisa_AG,
Are you willing to be a guinea pig ? I've done a mod of ClipBlend (needs a bit more testing), but now does not restart when user jumps about and your script would work quite well. (except that I think you should have used 'delay=39' for 40 frames blended together). In your script, it would re-read 40 new frames for every output frame and average the lot, instead of just resetting and starting with 1 frame. with a delay of eg 99 (100 frames) and you jump from 0 to 999, then would reset and read 900-999 (100 frames). With Delay 0 (infinite ie all previous frames), and if you jump from eg frame 1000 to 2000, will scan all intervening frames before display of frame 2000 (EDIT: ie the average of all frames 0 to 2000). I've also modded ClipBlend16() as same, I've only ever tried about 2 scripts, and that was when trying to figure out if ClipBlend16 was working or not. Do you use Stack16 format ? Anyway, givvus a day or two and I'll post a link. EDIT: It only resets and rescans (when jumping about) when quicker to do so, if quicker to subtract/add frames from/to accumulator, then it will do that instead.
__________________
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 ??? Last edited by StainlessS; 25th March 2015 at 00:30. |
24th March 2015, 19:56 | #5 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,011
|
@Kisa_AG,
Here, if you are impatient:- EDIT: LINK REMOVED Seems to work OK. Not sure about the Stack16 version [ClipBlend16()]. Give it a try and report how it goes please. EDIT: Your script should read Code:
ClipBlend(delay=39) SelectEvery(40, 39) Code:
to get frame 300 only # ------------------------ Requires GScript, RT_Stats Avisource("D:\avs\test.avi") ConvertToYV24() # v2.60 #ConvertToYV12() # v2.58 ClipBlend() # ClipBlend(clip) FRM =300 # Required frame number GSCript(""" for(i=0,FRM) { RT_yankChain(i) # force process frames up to FRM } """) Trim(FRM,-1) # Get Required frame return ConvertToRGB32() # For Viewing YV24 Code:
Avisource("D:\avs\test.avi") ConvertToYV12() # v2.58 ClipBlend() # ClipBlend(clip) FRM =300 # Required frame number Trim(FRM,-1) # Get Required frame return ConvertToRGB32() # For Viewing YV24 Code:
Avisource("D:\avs\test.avi") ClipBlend() return Trim(FrameCount-1,-1)
__________________
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 ??? Last edited by StainlessS; 30th March 2015 at 14:12. |
24th March 2015, 21:41 | #6 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,011
|
Timing script, get single frame average of all frames in clip
Code:
Avisource("D:\DBSC\AP10_Out.avi").KillAudio #Trim(0,-10000) FC=FrameCount START=RT_TimerHP ClipBlend() Trim(FC-1,-1) SCRIPT=""" T=RT_TimerHP-START S=RT_String("%d frames : %.3f secs %.3f FPS",FC,T,FC/T) RT_DebugF("%s",S) SubTitle(S) """ Return ScriptClip(SCRIPT,After_frame=True) Both below timings from warm boot. EDIT: Below are INPUT FPS, there is only 1 output frame VS6 compile (as supplied, in above beta link) 00000001 0.00000000 RT_DebugF: 76905 frames : 405.998 secs 189.422 FPS VS ToolKit2003 compile 00000003 298.41174316 RT_DebugF: 76905 frames : 296.480 secs 259.394 FPS EDIT: Also did compile with VS 2008 Express with Full Optimization switch /Ox, timing almost identical to the VS Toolkit 3 (a few milli FPS difference, I think was faster by about 1.25 seconds). EDIT: How ClipBlend it works ClipBlend() uses a single 32 bit accumulator (unsigned int) for each channel of each pixel x,y position in the clip frame. With a maximum possible value per pixel/channel being 255 ie 8 bits, this leaves 24 bits available for accumulating the sum of values for that pixel/channel position, ie adding the values for that pixel/channel from every selected frame in the blended range. The additional 24 bits would allow for up to ~16 Million (2^24) frames to be summed, however we also need another bit to maintain maximum precision possible for 8 bit result, so reducing maximum possible frame range to ~8 million frames. Code:
Return Avisource("test.avi").ClipBlend(delay=0).Trim(999,-1) # 1000 frames, 1000 values per accumulator, ie max 1000*255 As clipblend scans frames, it adds the channel/pixel values at each x,y position to the accumulators, for all of the required frames. If delay = 0, it just adds next frame values to the accumulators. If eg delay=10, and current scanned range is already 10, it subtracts the channel/pixel values of the oldest frame (lowest number) and then adds the values for the next frame to the accumulators. When delivering the result (delay=whatever), it just divides the accumulated sum by the number of sample frames to get the average, and writes it to the relevant pixel/channel/x/y position, could not be simpler. Implementation is equivalent to this: Code:
int(accumulator / Float(FramesDone) + 0.5) Code:
((accumulator*2) + FramesDone) / (FramesDone*2) precision at 8 bits result.
__________________
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 ??? Last edited by StainlessS; 26th March 2015 at 13:28. |
25th March 2015, 12:16 | #7 | Link | |||||
Registered User
Join Date: Sep 2005
Location: Moscow, Russia
Posts: 66
|
Quote:
Quote:
Quote:
Quote:
Quote:
I'll try to do extended test with numbered frames to take a look if it's completely Ok. Actually, I'm trying to do a kind of motion blur by blending frames. That's why I need frames in(1-40) to be blended to frame out(1), frames in(41-80) to frame out(2) etc. Until now I'm making it with the following script: ############################################################## # Speed Up 40x, drop 10, leave 20, drop 10. SelectEvery(40,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29) frame0=SelectEvery(20,0) frame1=SelectEvery(20,1) frame2=SelectEvery(20,2) frame3=SelectEvery(20,3) frame4=SelectEvery(20,4) frame5=SelectEvery(20,5) frame6=SelectEvery(20,6) frame7=SelectEvery(20,7) frame8=SelectEvery(20,8) frame9=SelectEvery(20,9) frame10=SelectEvery(20,10) frame11=SelectEvery(20,11) frame12=SelectEvery(20,12) frame13=SelectEvery(20,13) frame14=SelectEvery(20,14) frame15=SelectEvery(20,15) frame16=SelectEvery(20,16) frame17=SelectEvery(20,17) frame18=SelectEvery(20,18) frame19=SelectEvery(20,19) # blend frames by pairs frame0=frame0.overlay(frame1,opacity=0.6) frame1=frame2.overlay(frame3,opacity=0.6) frame2=frame4.overlay(frame5,opacity=0.6) frame3=frame6.overlay(frame7,opacity=0.6) frame4=frame8.overlay(frame9,opacity=0.6) frame5=frame11.overlay(frame10,opacity=0.6) frame6=frame13.overlay(frame12,opacity=0.6) frame7=frame15.overlay(frame14,opacity=0.6) frame8=frame17.overlay(frame16,opacity=0.6) frame9=frame19.overlay(frame18,opacity=0.6) # blend frames by pairs from borders to center, frames 0 and 9 are omited frame18=frame1.overlay(frame8,opacity=0.5) frame27=frame2.overlay(frame7,opacity=0.5) frame36=frame3.overlay(frame6,opacity=0.5) frame45=frame4.overlay(frame5,opacity=0.5) # blend pairs frame1827=frame18.overlay(frame27,opacity=0.6) frame3645=frame36.overlay(frame45,opacity=0.6) # blend pairs in one frame frame1827.overlay(frame3645,opacity=0.69) ########################################################################### In this script I'm blending only 20 frames from every 40 frames with different weights. But actually it's ok if the weight is the same. |
|||||
25th March 2015, 18:18 | #8 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,011
|
Yes I'm sure you script works ok, but will have precision errors.
ClipBlend() can be a maximum of half a bit in error (in total) for each results pixel/channel/x/y (aint no halves in integer pixels). Where you use Overlay, same thing, half a bit max in error, but, when you overlay with the previous overlay results again, same again, max half a bit in error (cumulative), and so on. This is the reason Vit uses Stack16 (thread linked by Reel.Deal in the prompting thread [linked in 1st post]), to try to reduce overall precision loss. ClipBlend has no need of Stack16, but as RD requested it, I did it anyway. The Beta ClipBlend16() was bugged and can cause access violations, I've re-written a lot of it and seems to now be working ok. I'll have a little bit more play with it an post another beta in a few hours. EDIT: ClipBlend16() will similarly be only max half a bit in error for 16 bit result, for 8 bit final result ClipBlend16() is pointless unless there is further processing to be done at 16 bits (I guess 16 to 8 bit dithering would count as further processing to spread what could have been a half a bit error if done in 8 bit precision). Any merge, Layer, Overlay etc type operation done in 8 bits will similarly produce a max half bit error unless dithering is done, most people are quite happy to accept that just as avisynth itself does.
__________________
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 ??? Last edited by StainlessS; 25th March 2015 at 19:23. |
26th March 2015, 02:52 | #9 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,011
|
ClipBlend v1.0Beta2.
LINK REMOVED By the way, the timing from script to get average of entire clip is not typical when playing clip. When getting average into single frame, there is no frame rendering (lots of slow-ish integer divides), it was only adding pixel/channel values to the accumulators without display (at least up until the final frame). Measured with AVSMeter whilst playing with delay=7, I was getting only about 100FPS for ClipBlend and about 31 FPS for ClipBlend16 (with additional dither funcs ie Dither_convert_8_to_16 () ClipBlend16(delay=7) DitherPost). EDIT:Above timings again with core duo duel core 2.4Ghz, most people will get somewhat better speed than my feeble m/c. EDIT: v2.6 and v2.58 dll's, + source (v2.6 dll MUST have Avisynth v2.6Alpha4 or later).
__________________
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 ??? Last edited by StainlessS; 29th March 2015 at 21:37. |
26th March 2015, 11:41 | #10 | Link |
Registered User
Join Date: Sep 2005
Location: Moscow, Russia
Posts: 66
|
I tried it with a special clip with numbered frames and it works like a charm! Thanks!
And it's much quicker than my SelectEvery/overlay old script. Actually, I also have MFlowBlur and MFlowFps functions in it, so inceasing of speed is very important for me. (I'm using it to make a motion blur for high fps clips). Thanks for excellent plugin! PS: I forgot to say - I tested ClipBlend26.dll with Avisynth v2.6RC1. Last edited by Kisa_AG; 26th March 2015 at 11:44. Reason: Small aadition |
26th March 2015, 13:53 | #11 | Link | |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,011
|
Quote:
The mod required pretty much a total re-write, but I'm quite glad I did it. I did some time ago recommend to Jmac698 that he did not do equivalent (with long timeout till display when delay=0 and jumping about) as I thought the user would be lost as to why jumping about took such a long time to do anything. I was completely wrong there (now that I've tried it) and now think that if that is what the user asked for, then that is what he is going to get. I like the way it works
__________________
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 ??? Last edited by StainlessS; 26th March 2015 at 14:03. |
|
27th November 2018, 15:30 | #12 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,011
|
ClipBlend v1.01, new version. See 1st post.
Code:
v1.00, Clipblend, Initial version. v1.01, 27 Nov 2018. Added Version resource. Moved to VS2008, with x64.
__________________
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 ??? |
3rd July 2022, 16:08 | #15 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,011
|
I'll try remember to do it, some day
EDIT: I'll also try remember that text renderer thing you asked for 2.
__________________
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 ??? |
20th January 2023, 11:39 | #17 | Link |
Registered User
Join Date: Dec 2005
Location: Denmark
Posts: 52
|
This is a very handy plugin! Thank you @StainlessS.
+1 for HDB support, with a parameter to specify output PixelType, such as YUV444PS (32-bit float). It would also be marvelous to have a "mode" option to accumulate a running maximum or minimum, as well as average. |
21st January 2023, 15:46 | #18 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,011
|
OK I hear ya, (in the queue).
__________________
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 ??? |
22nd January 2023, 09:18 | #19 | Link |
Registered User
Join Date: Dec 2005
Location: Denmark
Posts: 52
|
Thanks.
Further dreaming ClipBlend feature requests in the queue... clip maximum and minimum saturation. [I doubt that maximum and minimum hue would have any meaning, considering hue is an angular value.] |
5th February 2023, 19:56 | #20 | Link |
Registered User
Join Date: Dec 2005
Location: Denmark
Posts: 52
|
Copy frame properties in ClipBlend
@StainlessS
I am running AviSynth+ 3.7.3 WIP, and beginning to use frame properties to store parameters for scene and frame processing. I am also a thankful user of ClipBlend(). However, ClipBlend() does not handle frame properties - ie. all frame properties of the input clip are lost. The output clip has no frame properties at all. Is there any chance you will implement propCopy(input, output) in your ClipBlend() plugin, to transfer AVS+ frame properties from input clip to the output clip? Obviously frame-specific numeric statistics like from your DBSC filters, or Dogway's ex_tools, ex_makediff, SceneStats, etc, would lose their meaning after ClipBlend's averaging, so such existing frame properties should not be copied to the output. Hmmm. Now that I think about it, it could be difficult to know which frame properties to copy. But at least the color space related frame properties (_ColorRange, _Matrix, etc.) should be copied if present in the input. What is your opinion on updating your existing plugins to support Avs+ 3.7.2+ features like frame properties? I really appreciate all you do for Avisynth and I know you have a long queue of stuff already For others to understand, I have a little example script, to show that frame properties are not passed through ClipBlend (and probably the majority of other existing Avisynth external filters). Code:
# script to demonstrate that ClipBlend() does not pass frame properties LoadPlugin("yourpath\ClipBlend_x64.dll") # StainlessS plugin c = ColorBarsHD(pixel_type = "YUV444P8", staticframes=true).trim(0, 9).KillAudio() # 10 frames of colorbars c = c.propSet("My_test_1", "c start", mode=1) # property added before ClipBlend a = c a = c.ClipBlend() # comment/un-comment to see frame properties with/without ClipBlend a = a.propSet("My_test_2", 3.14159) # property added after ClipBlend return a.propShow(size=32) My workaround to preserve frame properties is to add a call to propCopy() after the call to clip blend. Code:
a = propCopy(a, c) # insert after call to ClipBlend() |
Thread Tools | Search this Thread |
Display Modes | |
|
|