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. |
2nd January 2018, 02:52 | #1 | Link |
Registered User
Join Date: Dec 2011
Posts: 27
|
Stack frames sequentially?
I have been searching around but couldn't find any info on this.
Is it possible to add each next frame, in a video, to the frames already processed? In pseudo-code something like: -read current frame -blend current frame with image stored in buffer -replace image in buffer with this new blend result -repeat Basically building a stack frame by frame using one of the blend modes. Thanks jacob. |
2nd January 2018, 03:12 | #2 | Link | |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
Not sure if this matches your description, but Clipblend:- https://forum.doom9.org/showthread.p...ight=ClipBlend
Can blend all frames with equal weight, producing single frame result. Quote:
(as no frames displayed until final 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; 2nd January 2018 at 18:00. |
|
3rd January 2018, 08:26 | #4 | Link | |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
Quote:
__________________
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 January 2018, 09:41 | #5 | Link | |
Registered User
Join Date: Dec 2011
Posts: 27
|
Quote:
It's useful for creating FX-images such as star-trails or car-trails (Images of streets with long lights of the car's front and rear-lights) An example: I wanted to create some photos like that from video-sequences of fireworks There is star-trail software that can already do it from image-files, but they get really heavy with more than a few hundred images (And the video I have has over 100,000 images) Anyway, thanks again for your input. Happy New Year! |
|
3rd January 2018, 10:19 | #6 | Link | |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
So basically its a channel Max function of all prev frames (incl current).
So, we are talking about every frame processed as you said (not from n frames previous to current) ? What color space ? (I dont do Avs+). Quote:
I guess I could do that. EDITED:
__________________
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; 3rd January 2018 at 12:08. |
|
3rd January 2018, 11:45 | #7 | Link |
Registered User
Join Date: Feb 2002
Location: Germany
Posts: 540
|
Have a look at the overlay() function. Maybe you could use a recursive user defined function to loop through all images, but i have no idea if 100k images are possible. Maybe you have to split them up in groups.
regards hanfrunz |
3rd January 2018, 16:32 | #8 | Link | |
Registered User
Join Date: Sep 2007
Posts: 5,374
|
Quote:
In avisynth there is a way with scriptclip, but it will crash probably so many images (it did for me back then with large dimension image sets, lots of images and avisynth x86). I would definitely try it with avisynth+ x64 Here is an example of star trails, with link to source/script/output https://forum.videohelp.com/threads/...rs#post2279836 |
|
3rd January 2018, 18:23 | #9 | Link |
Registered User
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,587
|
I think this did what OP ask
Code:
ScriptClip(""" o = last c = current_frame try{b=b} catch(error_msg) {b=last} trim(1,0) c == 0 ? o : last c == 0 ? last : merge(last,b) global b = last last """) Code:
ScriptClip(""" o = last c = current_frame try{bb=isclip(b)} catch(error_msg) {bb=false} bb ? last : trim(1,0) c == 0 ? o : last bb ? merge(last,b.trim(1,0)) : last global b = last last """) edit: ok, here is the last code Code:
ScriptClip(""" try{bb=isclip(b)} catch(error_msg) {bb=false} bb ? merge(last,b.Loop(2,0,0)) : last global b = last last """)
__________________
See My Avisynth Stuff Last edited by real.finder; 3rd January 2018 at 19:08. |
3rd January 2018, 18:33 | #10 | Link |
Registered User
Join Date: Sep 2006
Posts: 1,657
|
You can probably do it in vapoursynth with a for loop, the only problem is that I couldn't find an overlay function, I recall someone ported it somewhere on the internet. And I don't know how to load the avisynth.dll itself into vs so I can use the avs overlay function.
Code:
clip = core.avisource.avisource(r"test.avi") clip_range = range(len(clip)) for n in clip_range: if n == 0: accum_clip = clip[n] elif n < len(clip_range): accum_clip = overlay(accum_clip, clip[n]) accum_clip.set_output() |
3rd January 2018, 19:42 | #11 | Link |
Retried Guesser
Join Date: Jun 2012
Posts: 1,373
|
This seems to work okay. Tested on 20000 frames. Takes time but not memory.
Requires AVS+, but can be adapted to classic AviSynth by wrapping the function in a GScript call. When 'blendfactor' = 0, the output is a still frame - a blend of all frames; when 'blendfactor' = (say) 10*framerate, the output is a series of dissolves between still frames at ten-second intervals - each still being a blend of one ten-second segment. Makes a weird effect. Code:
####################################### ### Blend a number of frames together, up to all frames in the clip ## Output framerate and duration are same as the source. ## ## @ blendfactor - blend 'n' frames; if 1, do nothing; if <=0, blend all frames ## @ blend_mode - see Overlay ## @ blend_opacity - see Overlay ## ## Examples ## | ## average of all frames ## | FrameBlendX(0, "blend", 0.5) ## | ## streak effect (with the right source) ## | FrameBlendX(0, "lighten", 1.0) ## function FrameBlendX(clip C, int blendfactor, string blend_mode, float blend_opacity) { C limit = (blendfactor<=0) ? 1 : Max(1, FrameCount/blendfactor) while (FrameCount>limit) { Overlay(SelectEven, SelectOdd, mode=blend_mode, opacity=blend_opacity) } ConvertFPS(C) return (blendfactor==1) ? C : Last } Last edited by raffriff42; 3rd January 2018 at 20:43. |
3rd January 2018, 21:43 | #12 | Link |
Registered User
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,587
|
this is edit to make it work with classic AviSynth without anything
Code:
####################################### ### Blend a number of frames together, up to all frames in the clip ## Output framerate and duration are same as the source. ## ## @ blendfactor - blend 'n' frames; if 1, do nothing; if <=0, blend all frames ## @ blend_mode - see Overlay ## @ blend_opacity - see Overlay ## ## Examples ## | ## average of all frames ## | SFrameBlendX(0, "blend", 0.5) ## | ## streak effect (with the right source) ## | SFrameBlendX(0, "lighten", 1.0) ## function SFrameBlendX(clip C, int "blendfactor", string "blend_mode", float "blend_opacity") { global SFrameBlendX_blend_mode=blend_mode global SFrameBlendX_blend_opacity=blend_opacity C limit = (blendfactor<=0) ? 1 : Max(1, FrameCount/blendfactor) global SFrameBlendX_limit = limit FrameCount!=1 ? ScriptClip(""" try{bb=isclip(b)} catch(error_msg) {bb=false} b = bb ? SFrameBlendX_limit>1 ? Overlay(b.Loop(2,0,0),last,opacity=float(SFrameBlendX_limit)/FrameCount) : b.Loop(2,0,0) : nop() b = bb ? b.Overlay(last, mode=SFrameBlendX_blend_mode, opacity=SFrameBlendX_blend_opacity) : last return b """) : last } it's not 100% same, but did the job
__________________
See My Avisynth Stuff |
4th January 2018, 00:54 | #13 | Link | |
Registered User
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,587
|
Quote:
it start fast then slow then crash with access error but this code don't crash! Code:
ScriptClip(""" o = last c = current_frame try{bb=isclip(b)} catch(error_msg) {bb=false} bb ? last : trim(1,0) c == 0 ? o : last bb ? merge(last,b.trim(1,0)) : last global b = last last """) the other codes slowdown and make less use of cpu before crash, maybe use a lot of ram anyway, why avs don't clean the unneeded old data in runtime to avoid that? is GRunT has some solution for this?
__________________
See My Avisynth Stuff |
|
4th January 2018, 01:35 | #14 | Link |
Retried Guesser
Join Date: Jun 2012
Posts: 1,373
|
To run the script I posted in classic AviSynth:
1) Load GScript http://avisynth.nl/index.php/GScript 2) Wrap "while" loop in GScript: Code:
function FrameBlendX(clip C, int blendfactor, string blend_mode, float blend_opacity) { C limit = (blendfactor<=0) ? 1 : Max(1, FrameCount/blendfactor) GScript(""" while (FrameCount>limit) { Overlay(SelectEven, SelectOdd, mode=blend_mode, opacity=blend_opacity) } """) ConvertFPS(C) return (blendfactor==1) ? C : Last } |
4th January 2018, 03:08 | #15 | Link |
Registered User
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,587
|
yes it work now in classic AviSynth
but it not same effect as the one I post
__________________
See My Avisynth Stuff |
4th January 2018, 04:07 | #16 | Link | |
Registered User
Join Date: Dec 2011
Posts: 27
|
Quote:
It creates a single blended image that lasts as long as the source-video (Takes a while to generate it, but not really very long considering the large amount of frames it has to go through) Avisynth is amazing Thank you very much everybody I wonder why 'normal' video-editors don't have this (Frame accumulation/stacking) as a possible effect, but I haven't seen it in any. Here's the final script I use (In case others want to try this) Code:
####################################### ### Blend a number of frames together, up to all frames in the clip ## Output framerate and duration are same as the source. ## ## @ blendfactor - blend 'n' frames; if 1, do nothing; if <=0, blend all frames ## @ blend_mode - see Overlay ## @ blend_opacity - see Overlay ## ## Examples ## | ## average of all frames ## | FrameBlendX(0, "blend", 0.5) ## | ## streak effect (with the right source) ## | FrameBlendX(0, "lighten", 1.0) ## function FrameBlendX(clip C, int blendfactor, string blend_mode, float blend_opacity) { C limit = (blendfactor<=0) ? 1 : Max(1, FrameCount/blendfactor) GScript(""" while (FrameCount>limit) { Overlay(SelectEven, SelectOdd, mode=blend_mode, opacity=blend_opacity) } """) ConvertFPS(C) return (blendfactor==1) ? C : Last } DirectShowSource("F:\JEL's_OwnOriginalRecordings\Canon\Orig incoming\EOS 80D\20180101\EOS 80D_03571.MP4") FrameBlendX(0, "lighten", 1.0) |
|
4th January 2018, 04:33 | #17 | Link | |
Registered User
Join Date: Dec 2011
Posts: 27
|
Quote:
I could not get it to run for more than 200-300 images before it crashed though (In classic Avisynth) I don't know enough about this to really make a qualified guess on why it crashes, but it seems like a memory-issue or perhaps just memory-mismanagement (Which I assume is related to how Avisynth handles memory when trying to buffer stuff) Technically it shouldn't require much memory though, since you only really need to hold 2 images in memory at any time (The incoming new image, and the buffered one you add the new info to) But as said, my avisynth level of knowledge is limited to basic avs scripting of the built-in filters and a few addon filters |
|
4th January 2018, 14:05 | #18 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
Just curious how this clip might look processed via RgbAmplifier:- https://forum.doom9.org/showthread.php?t=168293
With max radius [EDIT: Max radius is only +- 99 frames] and varying values for Multiplier. Code:
RgbAmplifier (RGB24 and RGB32) ======================================== An Avisynth plugin to amplify color shifts Given a clip, this filter examines every pixel of every frame and independently multiplies the difference of its specific R, G and B values from the average R, G and B values of that same pixel location spanning a defined radius of adjacent frames. If the new values are above or below the allowed RGB values, they are capped at those limits. The revised RGB values replace the original values, and the amplified clip is returned. If the Multiplier is set to a value of zero, the plugin acts as a temporal frame averager. This plugin will: Convert seemingly imperceptible color changes into obvious color changes Highlight seemingly imperceptible movements of high contrast pixels Sharpen the details of moving objects Cause distortion or ghosting/transparency effect to moving objects (an unavoidable side effect) This plugin requires RGB24 or RGB32 color space, and is intended for forensic analysis of videos created from fixed position cameras. Usage on non-stationary cameras may produce unpredictable or content destructive results. The faster the object and/or the greater the radius, the greater the risk of negatively impacting the visual accuracy of the moving object. ===== Usage RgbAmplifier(clip clip,int "Radius"=2,float "Multiplier"=2.0,int "Rmin"=0,int "GMin"=0,int "Bmin"=0, \ int "RMax"=255,int "GMax"=255,int "BMax"=255,bool "Precise"=false)
__________________
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; 4th January 2018 at 14:08. |
4th January 2018, 15:03 | #19 | Link |
Formerly davidh*****
Join Date: Jan 2004
Posts: 2,496
|
If you're trying to average all frames, shouldn't it be moved to an RGB64 or float format to avoid accuracy loss?
Averaging 4096 numbers in pairs, as repeated use of overlay would, might result in being up to ±4 out on the result (and that's only on average, it could be higher). |
5th January 2018, 01:25 | #20 | Link |
Retried Guesser
Join Date: Jun 2012
Posts: 1,373
|
davidhorman, you're right in theory. I haven't noticed a difference, but I wasn't looking too hard.
High bit depth would definitely be a good idea here. One thing, there seems to be a bug in ChangeFPS (corrrection, ConvertFPS) at high bit depth. The bug exists since AVS+ r2440 (at least) through r2580, x86 or x64, YUV or RGB. The output has what looks like posterization or "stripes", but I think it's a possible frame seeking issue. Here's my (quick & dirty) test code Code:
function _x(clip C, float x) { return C.Subtitle("!", align=2, x=x, size=C.Height) } ## make a ! mark scroll left to right over black BlankClip(width=640, height=260, pixel_type="YV12", length=1024) Animate(0, 1000, "_x", \ -0.2*Width, \ 1.2*Width \ ).Trim(0, 1010) ConvertBits(12) ## test high bit depth(s) FrameBlendX(48, "blend", 0.5) ConvertBits(8) ConvertToYV12 TurnRight.Histogram.TurnLeft return Last Last edited by raffriff42; 5th January 2018 at 19:23. Reason: corrrection |
Thread Tools | Search this Thread |
Display Modes | |
|
|