Animate

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
m (added category)
(add link to avs+ documentation)
 
(One intermediate revision by one user not shown)
Line 1: Line 1:
{{Template:Func2Def|Animate(clip ''clip'', int ''start_frame'', int ''end_frame'', string ''filtername'', start_args, end_args)|ApplyRange(clip ''clip'', int ''start_frame'', int ''end_frame'', string ''filtername'', args)}}
+
<div {{BlueBox2|40|0|3px solid purple}} >
 +
{{AvsPlusFullname}}<br>
 +
Up-to-date documentation: [https://avisynthplus.readthedocs.io/en/latest/avisynthdoc/corefilters/animate.html https://avisynthplus.readthedocs.io]
 +
</div>
  
'''Animate''' is a meta-filter which evaluates its parameter filter with continuously varying arguments. At frame ''start_frame'' and earlier, the filter is evaluated with the arguments given by ''start_args''. At frame ''end_frame'' and later, the filter is evaluated with the arguments given by ''end_args''. In between, the arguments are linearly interpolated for a smooth transition.
 
  
'''ApplyRange''' is a special case of Animate where start_args = end_args, and present in v2.51. It can be used when you want to apply a certain filter only on a certain range of frames of a clip - unlike Animate, frames outside the range ''start_frame'' to ''end_frame'' are passed through untouched. Another difference with Animate is that args can't contain a clip. Starting from v2.53 it supports audio, and start_frame can be equal to end_frame (such that only one frame is processed).
+
'''Animate''' is a meta-filter which evaluates another filter with continuously varying arguments.
  
In cases where a large number of ranges need similar processing using many ApplyRange calls may cause resource issues. An alternative can be to use [[ConditionalReader]] with [[ConditionalFilter]] to select between the unprocessed and processed version of a source.
+
'''ApplyRange''' is a special case of Animate where ''start_args'' = ''end_args''.  
 +
__TOC__
 +
== Syntax and Parameters ==
 +
<div style="max-width:62em" >
 +
{{FuncDefH4|Animate}}
 +
{{FuncDef
 +
|Animate(clip ''clip'', int ''start_frame'', int ''end_frame'', string ''filtername'', var start_args*, var end_args*)
 +
}}
  
The filter name must be enclosed in quotation marks (it's a string), and the two nested argument lists are not parenthesized. Strings and video clips can't be interpolated, and therefore must be identical in the two argument lists. An important warning though: If you use a clip as first argument, that same clip shouldn't be included in start_args and end_args. Thus for example
+
:{{Par2|clip|clip|}}
 +
::Source clip, sent to filter {{FuncArg|filtername}}.
  
v = Version()
+
:{{Par2|start_frame, end_frame|int|}}
Animate(v, 0, 149, "Crop",  
+
::At frame {{FuncArg|start_frame}} and earlier, the filter is evaluated with the arguments given by {{FuncArg|start_args}}.
\  v,  0, 0, 64, 32,  
+
::At frame {{FuncArg|end_frame}} and later, the filter is evaluated with the arguments given by {{FuncArg|end_args}}.
\  v, 316, 0, 64, 32)
+
::In between, the arguments are linearly interpolated for a smooth transition.
  
results in an error, since the first frame is the same as the invalid syntax Crop(v, v, 0, 0, 64, 32). The correct script would be:
+
:{{Par2|filtername|string|}}
 +
::Name of any filter or function accessible to your script.
  
  v = Version()
+
:{{Par2|start_args, end_args|var list|}}
  Animate(v, 0, 149, "Crop",  
+
::Two lists of arguments to {{FuncArg|filtername}}. Data types must match. The two nested argument lists are not parenthesized.
  \    0, 0, 64, 32,  
+
::Strings and video clips can't be interpolated, and therefore must be identical in the two argument lists.
 +
 
 +
::An important warning: If you use a clip as the first argument to '''Animate''', that clip shouldn't be included here.
 +
::Thus for example
 +
<div {{BoxWidthIndent|36|5}} >
 +
  {{BoldColor|blue|100|v}} = [[Version]]()
 +
  Animate({{BoldColor|blue|100|v}}, 0, 149, "[[Crop]]",
 +
\  {{BoldColor|blue|100|v}},  0, 0, 64, 32,
 +
\  {{BoldColor|blue|100|v}}, 316, 0, 64, 32)
 +
</div>
 +
::results in an error. The correct script would be:
 +
<div {{BoxWidthIndent|36|5}} >
 +
{{BoldColor|blue|100|v}} = [[Version]]
 +
Animate({{BoldColor|blue|100|v}}, 0, 149, "[[Crop]]",  
 +
  \    0, 0, 64, 32,
 
  \  316, 0, 64, 32)
 
  \  316, 0, 64, 32)
 +
</div>
 +
::or alternatively,
 +
<div {{BoxWidthIndent|36|5}} >
 +
{{BoldColor|blue|100|v}} = [[Version]]
 +
Animate(0, 149, "[[Crop]]",
 +
\  {{BoldColor|blue|100|v}},  0, 0, 64, 32,
 +
\  {{BoldColor|blue|100|v}}, 316, 0, 64, 32)
 +
</div>
  
 +
This filter will ''not'' handle a changing sound track or different output frame sizes.
  
This filter will not correctly handle a changing sound track or different output frame sizes.  
+
The {{FuncArg|filtername}} argument can even be '''Animate''' if you want quadratic rather than linear interpolation.
  
The filter argument can even be Animate if you want quadratic rather than linear interpolation.
 
  
===Animate Examples===
+
{{FuncDefH4|ApplyRange}}
 +
{{FuncDef
 +
|ApplyRange(clip ''clip'', int ''start_frame'', int ''end_frame'', string ''filtername'', var args*)
 +
}}
  
 +
:{{Par2|clip|clip|}}
 +
::Source clip, sent to filter {{FuncArg|filtername}}.
 +
 +
:{{Par2|start_frame, end_frame|int|}}
 +
::Frames outside the range {{FuncArg|start_frame}} to {{FuncArg|end_frame}} are passed through untouched.
 +
::Frames inside the range {{FuncArg|start_frame}} to {{FuncArg|end_frame}} (inclusive) are processed by filter {{FuncArg|filtername}} with arguments {{FuncArg|args}}.  If {{FuncArg|start_frame}}=={{FuncArg|end_frame}}, only one frame is processed.
 +
 +
:{{Par2|filtername|string|}}
 +
::Name of any filter or function accessible to your script.
 +
 +
:{{Par2|args|var list|}}
 +
::List of arguments to {{FuncArg|filtername}}. Unlike '''Animate''', {{FuncArg|args}} can't contain a clip.
 +
::As with '''Animate''', if you use a clip as the first argument to '''ApplyRange''', that clip shouldn't be included here.
 +
 +
Like '''Animate''', this filter will not handle a changing sound track or different output frame sizes.
 +
 +
In cases where a large number of ranges need processing, calling '''ApplyRange''' many times may cause resource issues. An alternative is found here: [[ConditionalReader#ApplyRange_replacement|ConditionalReader: ApplyRange replacement]].
 +
</div>
 +
 +
 +
==Examples==
 +
<div style="max-width:62em" >
 +
===Animate Examples===
 
=====Scrolling "Version" video=====
 
=====Scrolling "Version" video=====
ver = Version()
+
<div {{BoxWidthIndent|54|1}} >
Animate(0, 149, "Crop",
+
  ver = [[Version]]
\  ver,  0, 0, 64, 32,
+
  Animate(ver, 0, 149, "[[Crop]]",  
\  ver, 316, 0, 64, 32)
+
+
# or what is the same:
+
  ver = Version()
+
  Animate(ver, 0, 149, "Crop",  
+
 
  \    0, 0, 64, 32,  
 
  \    0, 0, 64, 32,  
 
  \  316, 0, 64, 32)
 
  \  316, 0, 64, 32)
+
</div>
 +
 
 
=====Fade to white=====
 
=====Fade to white=====
  AviSource("E:\pdwork\DO-Heaven.AVI")
+
<div {{BoxWidthIndent|54|1}} >
  Animate(100,200,"Levels",  
+
  [[AviSource]]("e:\test.avi")
 +
  Animate(100,200,"[[Levels]]",  
 
  \  0, 1, 255,  0, 255,  
 
  \  0, 1, 255,  0, 255,  
 
  \  0, 1, 255, 255, 255)
 
  \  0, 1, 255, 255, 255)
 +
</div>
  
 
=====Zoom In=====  
 
=====Zoom In=====  
 +
<div {{BoxWidthIndent|54|1}} >
 
  # Do a gradual zoom into the center of a 320x240 video, starting at
 
  # Do a gradual zoom into the center of a 320x240 video, starting at
 
  # 1:1 magnification in frame 100 and ending with 4:1 magnification
 
  # 1:1 magnification in frame 100 and ending with 4:1 magnification
 
  # in frame 200:
 
  # in frame 200:
  clip = AviSource("E:\pdwork\DO-Heaven.avi")
+
  clip = [[AviSource]]("e:\test.avi")
  Animate(100,200,"BicubicResize",  
+
  Animate(100,200,"[[BicubicResize]]",  
 
  \  clip,320,240,0,0,320,240,  
 
  \  clip,320,240,0,0,320,240,  
 
  \  clip,320,240,120,90,80,60)
 
  \  clip,320,240,120,90,80,60)
  # Animate(clip, 100,200,"BicubicResize",  
+
  # Animate(clip, 100,200,"[[BicubicResize]]",  
 
  #\  320,240,0,0,320,240,  
 
  #\  320,240,0,0,320,240,  
 
  #\  320,240,120,90,80,60) # also works
 
  #\  320,240,120,90,80,60) # also works
 +
</div>
  
 
=====Zoom Out=====  
 
=====Zoom Out=====  
 +
<div {{BoxWidthIndent|54|1}} >
 
  # Make the text "Hello, World!" zoom out from the center of a 320x240 video:
 
  # Make the text "Hello, World!" zoom out from the center of a 320x240 video:
  BlankClip(width=320, height=240)
+
  [[BlankClip]](width=320, height=240)
  Animate(0,48,"Subtitle",  
+
  Animate(0,48,"[[Subtitle]]",  
 
  \  "Hello, World!", 160, 120, 0, 99999, "Arial", 0,
 
  \  "Hello, World!", 160, 120, 0, 99999, "Arial", 0,
 
  \  "Hello, World!",  25, 130, 0, 99999, "Arial", 48)
 
  \  "Hello, World!",  25, 130, 0, 99999, "Arial", 48)
 +
</div>
  
 
=====Zoom overlay 1=====
 
=====Zoom overlay 1=====
 +
<div {{BoxWidthIndent|54|1}} >
 
  # Zooming clip c2 while overlaying it on c1:
 
  # Zooming clip c2 while overlaying it on c1:
 
   
 
   
  Function myfunc(clip c1, clip c2, int x, int y, int w, int h)
+
  function myfunc(clip c1, clip c2, int x, int y, int w, int h)
 
  {
 
  {
   w = w - w%2
+
   w = w - w % 2
   h = h - h%2
+
   h = h - h % 2
   my_c2 = BicubicResize(c2,w,h)
+
   my_c2 = [[BicubicResize]](c2,w,h)
 
   Overlay(c1,my_c2,x,y)
 
   Overlay(c1,my_c2,x,y)
 
  }
 
  }
 
   
 
   
  c1 = AviSource("D:\Captures\jewel.avi") # c1 is larger than c2
+
  c1 = [[AviSource]]("e:\c1.avi") # c1 is larger than c2
  c2 = AviSource("D:\Captures\atomic.avi").BicubicResize(320,240)
+
  c2 = [[AviSource]]("e:\c2.avi").[[BicubicResize]](320,240)
 
  Animate(0,1000,"myfunc",
 
  Animate(0,1000,"myfunc",
 
  \  c1,c2, 10, 10, 10, 10,
 
  \  c1,c2, 10, 10, 10, 10,
Line 86: Line 148:
 
  #\  c2,300,300,360,288)
 
  #\  c2,300,300,360,288)
 
   
 
   
  # but the following doesn't work, since three clips  
+
  # but the following doesn't work, since ''three'' clips  
 
  # are passed to myfunc (c1, c1 and c2), while only two are allowed:
 
  # are passed to myfunc (c1, c1 and c2), while only two are allowed:
 
  # Animate(c1,0,1000,"myfunc",
 
  # Animate(c1,0,1000,"myfunc",
 
  #\  c1,c2, 10, 10, 10, 10,
 
  #\  c1,c2, 10, 10, 10, 10,
 
  #\  c1,c2,300,300,360,288)
 
  #\  c1,c2,300,300,360,288)
 +
</div>
  
 
=====Zoom overlay 2=====
 
=====Zoom overlay 2=====
 +
<div {{BoxWidthIndent|54|1}} >
 
  # A small picture enlarges on a black clip until replace the main clip:
 
  # A small picture enlarges on a black clip until replace the main clip:
 
   
 
   
 
  function res(clip clip, clip "LClip", int "width", int "height",  
 
  function res(clip clip, clip "LClip", int "width", int "height",  
 
  \          int "centerX", int "centerY") {
 
  \          int "centerX", int "centerY") {
     LClip = BicubicResize(LClip, width, height)
+
     LClip = [[BicubicResize]](LClip, width, height)
     Overlay(clip, LClip, centerX-LClip.width/2, centerY-LClip.height/2)
+
     [[Overlay]](clip, LClip, centerX-LClip.Width/2, centerY-LClip.Height/2)
 
  }
 
  }
 
   
 
   
Line 110: Line 174:
 
  }
 
  }
 
   
 
   
  clip = AviSource("D:\captures\jewel.avi")
+
  clip = [[AviSource]]("e:\test.avi")
  clip = clip.BicubicResize(640,480)
+
  clip = clip.[[BicubicResize]](640,480)
  clip = clip.ConvertToRGB()
+
  clip = clip.[[ConvertToRGB]]
  black = BlankClip(clip)
+
  black = [[BlankClip]](clip)
 
   
 
   
 
  resize(black, clip,  
 
  resize(black, clip,  
  \      0, 120, 120*clip.height/clip.width,  
+
  \      0, 120, 120*clip.Height/clip.Width,  
 
  \      500, 640, 480,  
 
  \      500, 640, 480,  
  \      clip.width/2, clip.height/2)
+
  \      clip.Width/2, clip.Height/2)
 
+
</div>
:See also, '''[[Subtitle#Animated_parameter_demonstration|Subtitle: Animated parameter demonstration]]'''
+
  
 +
See also, '''[[Subtitle#Animated_parameter_demonstration|Subtitle: Animated parameter demonstration]]'''
  
 
===ApplyRange Examples===
 
===ApplyRange Examples===
 
+
<div {{BoxWidthIndent|54|1}} >
 
  ver = Version()
 
  ver = Version()
 
  return ver.ApplyRange(0,149,"Crop", 158,0,64,32)
 
  return ver.ApplyRange(0,149,"Crop", 158,0,64,32)
 
  # gives an error since cannot have different frame sizes within a clip
 
  # gives an error since cannot have different frame sizes within a clip
 +
</div>
  
  Version()
+
<div {{BoxWidthIndent|54|1}} >
  ApplyRange(100,149,"Blur", 1.0)
+
  [[Version]]
 +
  ApplyRange(100,149,"[[Blur]]", 1.0)
 +
</div>
  
  AviSource("E:\pdwork\DO-Heaven.avi").BicubicResize(320,240)
+
<div {{BoxWidthIndent|54|1}} >
  ApplyRange(0,48,"Subtitle", "Hello, World!",25,130,0,99999,"Arial",48)
+
  [[AviSource]]("e:\test.avi").[[BicubicResize]](320,240)
 +
  ApplyRange(0,48,"[[Subtitle]]", "Hello, World!",25,130,0,99999,"Arial",48)
 
   
 
   
 
  # or what is the same:
 
  # or what is the same:
  clip = AviSource("E:\pdwork\DO-Heaven.avi").BicubicResize(320,240)
+
  clip = [[AviSource]]("e:\test.avi").[[BicubicResize]](320,240)
  ApplyRange(clip, 0,48,"Subtitle", "Hello, World!",25,130,0,99999,"Arial",48)
+
  ApplyRange(clip, 0,48,"[[Subtitle]]", "Hello, World!",25,130,0,99999,"Arial",48)
 
   
 
   
  # but since the frame range can be provided to Subtitle itself, this is the same as:  
+
  # since the frame range can be provided to Subtitle itself, this is the same as:  
  AviSource("E:\pdwork\DO-Heaven.avi").BicubicResize(320,240)
+
  [[AviSource]]("e:\test.avi").[[BicubicResize]](320,240)
  Subtitle("Hello, World!",25,130,0,48,"Arial",48)
+
  [[Subtitle]]("Hello, World!",25,130,0,48,"Arial",48)
 +
</div>
  
 +
</div>
 
[[Category:Internal filters]]
 
[[Category:Internal filters]]
 
[[Category:Meta_filters]]
 
[[Category:Meta_filters]]

Latest revision as of 19:29, 17 September 2022

AviSynth+
Up-to-date documentation: https://avisynthplus.readthedocs.io


Animate is a meta-filter which evaluates another filter with continuously varying arguments.

ApplyRange is a special case of Animate where start_args = end_args.

Contents

 [hide

[edit] Syntax and Parameters

Animate

Animate(clip clip, int start_frame, int end_frame, string filtername, var start_args*, var end_args*)

clip  clip =
Source clip, sent to filter filtername.
int  start_frame, end_frame =
At frame start_frame and earlier, the filter is evaluated with the arguments given by start_args.
At frame end_frame and later, the filter is evaluated with the arguments given by end_args.
In between, the arguments are linearly interpolated for a smooth transition.
string  filtername =
Name of any filter or function accessible to your script.
var list  start_args, end_args =
Two lists of arguments to filtername. Data types must match. The two nested argument lists are not parenthesized.
Strings and video clips can't be interpolated, and therefore must be identical in the two argument lists.
An important warning: If you use a clip as the first argument to Animate, that clip shouldn't be included here.
Thus for example
v = Version()
Animate(v, 0, 149, "Crop", 
\  v,   0, 0, 64, 32, 
\  v, 316, 0, 64, 32)
results in an error. The correct script would be:
v = Version
Animate(v, 0, 149, "Crop", 
\    0, 0, 64, 32,
\  316, 0, 64, 32)
or alternatively,
v = Version
Animate(0, 149, "Crop", 
\  v,   0, 0, 64, 32,
\  v, 316, 0, 64, 32)

This filter will not handle a changing sound track or different output frame sizes.

The filtername argument can even be Animate if you want quadratic rather than linear interpolation.


ApplyRange

ApplyRange(clip clip, int start_frame, int end_frame, string filtername, var args*)

clip  clip =
Source clip, sent to filter filtername.
int  start_frame, end_frame =
Frames outside the range start_frame to end_frame are passed through untouched.
Frames inside the range start_frame to end_frame (inclusive) are processed by filter filtername with arguments args. If start_frame==end_frame, only one frame is processed.
string  filtername =
Name of any filter or function accessible to your script.
var list  args =
List of arguments to filtername. Unlike Animate, args can't contain a clip.
As with Animate, if you use a clip as the first argument to ApplyRange, that clip shouldn't be included here.

Like Animate, this filter will not handle a changing sound track or different output frame sizes.

In cases where a large number of ranges need processing, calling ApplyRange many times may cause resource issues. An alternative is found here: ConditionalReader: ApplyRange replacement.


[edit] Examples

[edit] Animate Examples

[edit] Scrolling "Version" video
ver = Version
Animate(ver, 0, 149, "Crop", 
\    0, 0, 64, 32, 
\  316, 0, 64, 32)
[edit] Fade to white
AviSource("e:\test.avi")
Animate(100,200,"Levels", 
\  0, 1, 255,   0, 255, 
\  0, 1, 255, 255, 255)
[edit] Zoom In
# Do a gradual zoom into the center of a 320x240 video, starting at
# 1:1 magnification in frame 100 and ending with 4:1 magnification
# in frame 200:
clip = AviSource("e:\test.avi")
Animate(100,200,"BicubicResize", 
\  clip,320,240,0,0,320,240, 
\  clip,320,240,120,90,80,60)
# Animate(clip, 100,200,"BicubicResize", 
#\  320,240,0,0,320,240, 
#\  320,240,120,90,80,60) # also works
[edit] Zoom Out
# Make the text "Hello, World!" zoom out from the center of a 320x240 video:
BlankClip(width=320, height=240)
Animate(0,48,"Subtitle", 
\  "Hello, World!", 160, 120, 0, 99999, "Arial", 0,
\  "Hello, World!",  25, 130, 0, 99999, "Arial", 48)
[edit] Zoom overlay 1
# Zooming clip c2 while overlaying it on c1:

function myfunc(clip c1, clip c2, int x, int y, int w, int h)
{
  w = w - w % 2
  h = h - h % 2
  my_c2 = BicubicResize(c2,w,h)
  Overlay(c1,my_c2,x,y)
}

c1 = AviSource("e:\c1.avi") # c1 is larger than c2
c2 = AviSource("e:\c2.avi").BicubicResize(320,240)
Animate(0,1000,"myfunc",
\  c1,c2, 10, 10, 10, 10,
\  c1,c2,300,300,360,288)
# or
# Animate(c1,0,1000,"myfunc", 
#\  c2, 10, 10, 10, 10, 
#\  c2,300,300,360,288)

# but the following doesn't work, since three clips 
# are passed to myfunc (c1, c1 and c2), while only two are allowed:
# Animate(c1,0,1000,"myfunc",
#\  c1,c2, 10, 10, 10, 10,
#\  c1,c2,300,300,360,288)
[edit] Zoom overlay 2
# A small picture enlarges on a black clip until replace the main clip:

function res(clip clip, clip "LClip", int "width", int "height", 
\           int "centerX", int "centerY") {
    LClip = BicubicResize(LClip, width, height)
    Overlay(clip, LClip, centerX-LClip.Width/2, centerY-LClip.Height/2)
}

function resize(clip clip, clip "LClip", 
\               int "start_frame", int "start_width", int "start_height",
\               int "end_frame", int "end_width", int "end_height", 
\               int "centerX", int "centerY") {
    return Animate(start_frame, end_frame, "res", 
        \       clip, LClip, start_width, start_height, centerX, centerY,
        \       clip, LClip, end_width, end_height, centerX, centerY)
}

clip = AviSource("e:\test.avi")
clip = clip.BicubicResize(640,480)
clip = clip.ConvertToRGB
black = BlankClip(clip)

resize(black, clip, 
\      0, 120, 120*clip.Height/clip.Width, 
\      500, 640, 480, 
\      clip.Width/2, clip.Height/2)

See also, Subtitle: Animated parameter demonstration

[edit] ApplyRange Examples

ver = Version()
return ver.ApplyRange(0,149,"Crop", 158,0,64,32)
# gives an error since cannot have different frame sizes within a clip
Version
ApplyRange(100,149,"Blur", 1.0)
AviSource("e:\test.avi").BicubicResize(320,240)
ApplyRange(0,48,"Subtitle", "Hello, World!",25,130,0,99999,"Arial",48)

# or what is the same:
clip = AviSource("e:\test.avi").BicubicResize(320,240)
ApplyRange(clip, 0,48,"Subtitle", "Hello, World!",25,130,0,99999,"Arial",48)

# since the frame range can be provided to Subtitle itself, this is the same as: 
AviSource("e:\test.avi").BicubicResize(320,240)
Subtitle("Hello, World!",25,130,0,48,"Arial",48)
Personal tools