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 2nd January 2018, 01:52   #1  |  Link
JELSTUDIO
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.
JELSTUDIO is offline   Reply With Quote
Old 2nd January 2018, 02:12   #2  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,626
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:
Or to get a single frame average of all frames in a clip
# ------------------------
Avisource("D:\avs\test.avi")
ClipBlend()
return Trim(FrameCount-1,-1)
# ------------------------
EDIT: It will scan entire clip before returning single frame result, so it may take some time but is as fast as it can be
(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 17:00.
StainlessS is offline   Reply With Quote
Old 3rd January 2018, 00:46   #3  |  Link
JELSTUDIO
Registered User
 
Join Date: Dec 2011
Posts: 27
@StainlessS Thank you

This will 'average' a group of frames.

Is there any way I can use other blend-modes with this? (Such as 'lighten', for example)
JELSTUDIO is offline   Reply With Quote
Old 3rd January 2018, 07:26   #4  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,626
Quote:
Such as 'lighten
Sorry, dont have the faintest idea how to acheive it, nor what that does, perhaps scripts in the other threads linked could be terrorized into doing what you require.
__________________
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 3rd January 2018, 08:41   #5  |  Link
JELSTUDIO
Registered User
 
Join Date: Dec 2011
Posts: 27
Quote:
Originally Posted by StainlessS View Post
Sorry, dont have the faintest idea how to acheive it, nor what that does, perhaps scripts in the other threads linked could be terrorized into doing what you require.
'Lighten' only updates a pixel if it is a brighter value than the current.

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!
JELSTUDIO is offline   Reply With Quote
Old 3rd January 2018, 09:19   #6  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,626
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:
And the video I have has over 100,000 images
So every pixel channel is max of all 100,000 prev same pixel channels and single frame result ?

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 11:08.
StainlessS is offline   Reply With Quote
Old 3rd January 2018, 10:45   #7  |  Link
hanfrunz
Registered User
 
hanfrunz's Avatar
 
Join Date: Feb 2002
Location: Germany
Posts: 536
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
hanfrunz is offline   Reply With Quote
Old 3rd January 2018, 15:32   #8  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 4,106
Quote:
Originally Posted by JELSTUDIO View Post
'Lighten' only updates a pixel if it is a brighter value than the current.

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: <snip>

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!

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
poisondeathray is offline   Reply With Quote
Old 3rd January 2018, 17:23   #9  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 1,360
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
""")
edit: this realy work now but slow
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: Loop(2,0,0) instead of trim(1,0) will make it faster

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
""")
and ofc you can use another function instead of merge()
__________________
My Avisynth Stuff

Last edited by real.finder; 3rd January 2018 at 18:08.
real.finder is offline   Reply With Quote
Old 3rd January 2018, 17:33   #10  |  Link
lansing
Registered User
 
Join Date: Sep 2006
Posts: 1,194
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()
lansing is offline   Reply With Quote
Old 3rd January 2018, 18:42   #11  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,376
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 19:43.
raffriff42 is offline   Reply With Quote
Old 3rd January 2018, 20:43   #12  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 1,360
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
}
SFrameBlendX(5,"lighten")

it's not 100% same, but did the job
__________________
My Avisynth Stuff
real.finder is offline   Reply With Quote
Old 3rd January 2018, 23:54   #13  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 1,360
Quote:
Originally Posted by poisondeathray View Post
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
yes it did crash

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
""")
but it's slow from begin and eat cpu

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?
__________________
My Avisynth Stuff
real.finder is offline   Reply With Quote
Old 4th January 2018, 00:35   #14  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,376
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
}
raffriff42 is offline   Reply With Quote
Old 4th January 2018, 02:08   #15  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 1,360
yes it work now in classic AviSynth

but it not same effect as the one I post
__________________
My Avisynth Stuff
real.finder is offline   Reply With Quote
Old 4th January 2018, 03:07   #16  |  Link
JELSTUDIO
Registered User
 
Join Date: Dec 2011
Posts: 27
Quote:
Originally Posted by raffriff42 View Post
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
}
This works in classic avisynth

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)
JELSTUDIO is offline   Reply With Quote
Old 4th January 2018, 03:33   #17  |  Link
JELSTUDIO
Registered User
 
Join Date: Dec 2011
Posts: 27
Quote:
Originally Posted by real.finder View Post
yes it work now in classic AviSynth

but it not same effect as the one I post
I tried yours as well and loved the ability to watch the effect accumulate over time. To actually see the final image being built, step by step, looks very cool

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
JELSTUDIO is offline   Reply With Quote
Old 4th January 2018, 13:05   #18  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,626
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)
DavidHorman did a variation that will also support YUV, Amp:- http://horman.net/avisynth/
__________________
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 13:08.
StainlessS is offline   Reply With Quote
Old 4th January 2018, 14:03   #19  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 1,911
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).
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is offline   Reply With Quote
Old 5th January 2018, 00:25   #20  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,376
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
8-bit output: showing tail end of crossfade between blended still frames
12-bit output: something is wrong
Substitute ChangeFPS: output is good but crossfade effect is gone (crossfade only matters if blendfactor>1)

Last edited by raffriff42; 5th January 2018 at 18:23. Reason: corrrection
raffriff42 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 12:49.


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