Log in

View Full Version : How to apply different filters to different parts of a video using AviSynth?


seggitek
27th October 2018, 11:48
I have a video file and want to post process it using AviSynth. Different parts of the movie require different filters to be used (noise reduction etc.). How can one use different filters for different parts of the input video?

What I once did is to trim the video into segments, apply different filters on them and then concatenate the segments back together. Something like this:

a = clip.Trim(0, 100).RemoveNoise("high")
b = clip.Trim(101, 200).RemoveNoise("low")
clip = a + b

Is there any other way to do this? I am asking, because the more segments you create the more cumbersome the script becomes.

I've read that AviSynth+ supports arrays. So one might create an array with the frame indices and then build the final clip using a loop. Something like this:

original = last
segments = [ \
[ 0, 100, "high"], \
[101, 200", "low"] \
]
clip = BlankClip()
for (i = 0; i < segments.Size; ++i)
{
clip += original.Trim(segments[i][0], segments[i][1]).RemoveNosie(segments[i][2])
}

This way one could create an array, holding the segments. But, it seems to me that despite this post here (https://forum.doom9.org/showthread.php?p=1785253#post1785253), AviSynth+ does not support arrays at the moment.

StainlessS
27th October 2018, 12:03
From ClipClop docs:- https://forum.doom9.org/showthread.php?t=162266&highlight=ClipClop

Example usage script using NickNames:
###
Avisource("D:\avs\test.avi")
ORG=Last

V1 = FFT3DFilter(Plane=0,Sigma=1.6) # Light Luma
V2 = FFT3DFilter(Plane=0,Sigma=2.0) # Med Luma
V3 = FFT3DFilter(Plane=0,Sigma=4.0) # High Luma
V4 = FFT3DFilter(Plane=3,Sigma=1.6) # Light Chroma
V5 = FFT3DFilter(Plane=3,Sigma=2.0) # Med Chroma
V6 = FFT3DFilter(Plane=3,Sigma=4.0) # High Chroma
V7 = FFT3DFilter(Plane=4,Sigma=1.6) # Light Luma+Chroma
V8 = FFT3DFilter(Plane=4,Sigma=2.0) # Med Luma+Chroma
V9 = FFT3DFilter(Plane=4,Sigma=4.0) # High Luma+Chroma
V10= FlipHorizontal() # Flip-H
V11= FlipVertical() # Flip-V
V12= Invert() # Invert

NickNames =""" # Psuedonyms for clips (clip index number)
L0 = 1 # Light Luma
L1 = 2 # Med Luma
L2 = 3 # High Luma
C0 = 4 # Light Chroma
C1 = 5 # Med Chroma
C2 = 6 # High Chroma
LC0 = 7 # Light Luma + Chroma
LC1 = 8 # Med Luma + Chroma
LC2 = 9 # High Luma + Chroma
FH = 10 # Flip-H
FV = 11 # Flip-V
INV = 12 # Invert
"""

SCMD=""" # Clip editing commands in string, can also use commands in file
C0 0,99 # Light Chroma frames @ 0 -> 99
L0 100,-200 # Light Luma frames @ 100, 200 frames ie frames 100->299
INV 300,399 # Invert 300->399
L0 400,499 # Light Luma frames 400->499
FH 500,599 # Flip-H 500->599
LC2 600,699 # High Luma + Chroma
C1 800 # Med Chroma, Single frame
1 900,999 # Light Luma, We used the clip number instead of a NickName
FV 1000,1099 # Flip-V
LC1 2000,0 # Med Luma + Chroma, 2000 -> lastframe
"""

SHOW=True

ClipClop(ORG,V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,scmd=SCMD,nickname=NickNames,show=SHOW)

Clipclop supports up to 255 replacement clips, and unlimited number of replacement ranges using those clips.

Maybe also take a look at ReplaceFramesSimple().

EDIT: Pinterf implemented arrays of mixed variable type, but until support for avs v2.5 plugins is dropped, arrays cannot be
supported and so have been disabled (until the world is a nicer and better place).

qyot27
27th October 2018, 12:28
This way one could create an array, holding the segments. But, it seems to me that despite this post here (https://forum.doom9.org/showthread.php?p=1785253#post1785253), AviSynth+ does not support arrays at the moment.
https://forum.doom9.org/showthread.php?p=1789325#post1789325

StainlessS
27th October 2018, 13:10
Arrays:- http://avisynth.nl/index.php/Arrays
AvsLib:- http://avslib.sourceforge.net/
AviSynthLib:- https://forum.doom9.org/showthread.php?t=164305

EDIT: Maxxon's AviSynthLib should at least get some kind of mention as alternative array in wiki/docs,
also has other very powerful functionality. (Its no wonder that he aint any longer around).

EDIT:
Also, RT_Stats has file based Arrays (1, 2 & 3 dimension) & DBase, but no support for clip (a pointer to a clip in file, has no meaning at all)

Here, an auto generated list of Array/DBase functions in RT_Stats latest beta

RT_Stats_ORDERED_Function_List v2.00Beta12

There follows a list of all function names together with CPP style argument specifiers that inform
Avisynth the argument types and optional names. Optional arguments have square brackets surrounding
their name as in [name] and are followed by a type specifier character that gives the type.
Unnamed arguments are not optional. eg "cc[arg1]b[arg2]i" would be two compulsory unnamed clip args,
followed by optional 'arg1' of type bool and optional 'arg2' of type int.

# Argument type specifier strings.
c - Video Clip
i - Integer number
f - Float number
s - String
b - boolean
. - Any type (dot)
# Array Specifiers
i* - Integer Array, zero or more
i+ - Integer Array, one or more
.* - Any type Array, zero or more
.+ - Any type Array, one or more
# Etc
###################################


RT_ArrayAlloc "s[Type]i[Dim1]i[Dim2]i[Dim3]i[StringLenMax]i"
RT_ArrayAppend "s."
RT_ArrayCheckID "si.+"
RT_ArrayExtend "s[Add]i"
RT_ArrayGet "si[ix2]i[ix3]i"
RT_ArrayGetAttrib "si"
RT_ArrayGetDim "s[Dim]i"
RT_ArrayGetDim1Max "s[Current]b"
RT_ArrayGetElSize "s"
RT_ArrayGetID "si"
RT_ArrayGetStrAttrib "si"
RT_ArrayGetType "s"
RT_ArraySet "s.i[ix2]i[ix3]i"
RT_ArraySetAttrib "si.+"
RT_ArraySetID "si.+"
RT_ArraySetStrAttrib "sis+"
RT_ArrayTypeName "i"

RT_DBaseAlloc "sis[StringLenMax]i"
RT_DBaseAppend "s.+"
RT_DBaseCheckID "si.+"
RT_DBaseExtend "s[Add]i"
RT_DBaseFields "s"
RT_DBaseFieldSize "si"
RT_DBaseFieldType "si"
RT_DBaseFindSeq "siii[low]i[high]i"
RT_DBaseGetAttrib "si"
RT_DBaseGetField "sii"
RT_DBaseGetID "si"
RT_DBaseGetStrAttrib "si"
RT_DBaseGetTypeString "s"
RT_DBaseRecords "s"
RT_DBaseRecordSize "s"
RT_DBaseRecordsMax "s[Current]b"
RT_DBaseSet "si.+"
RT_DBaseSetAttrib "si.+"
RT_DBaseSetField "sii.+"
RT_DBaseSetID "si.+"
RT_DBaseSetStrAttrib "sis+"
RT_DBaseTypeName "i"


EDIT:
RT_Array

*****************************************************
********** RT_ARRAY FUNCTIONS ***********
*****************************************************

RT_Stats ARRAY functions allow fast access to a file based Array of up to 3 dimensions of fixed element type,
Bool, Int, Float, String, or BIN. BIN is a BYTE (8 bit) sized Int where only lowest 8 bits of Int are stored in the Array
as an unsigned 8 bit Int, upper 24 bits ignored.
The maximum possible file size is about 1TB, and depends on number and size of dimensions and element type and size, also
depends upon avilable disk space.
Element types Bool and BIN require 1 byte, Int and Float 4 bytes, and String is of fixed maximum length (user chosen) up to
256KB (256 * 1024, no nul terminating character is stored in an Array String).
Maximum possible size of dimension 1 is $7FFFFFFE but depends upon available disk space and also limited to max 1TB.
RT_ArrayAlloc, allows you to create an array file with a fixed number of dimensions and where the 2nd and/or 3rd dimensions
of a multi-dimensional array are fixed in size but the size of the first dimension can 'grow', single dimension arrays can
'grow' too. You can create an array where the first dimension is 0 (any other dimensions fixed), ie no elements pre-allocated
in array file, in this case you can use RT_ArrayExtend to 'grow' the first dimension of the array so that it can be used. In addition,
single dimension arrays can also use RT_ArrayAppend to add elements to the end of the array.
An Array file allows up to 1024 Attributes of types Int or Float, which can be used for whatever a user desires, these
attributes are stored in the Array file header which is 32768 bytes, so the actual data starts at $8000 hex.
In addition to user attributes, an Array has currently 10 user String Attributes that can be be used for whatever you want, the
string attributes are currently a maximum of 1024 characters in length.
In addition to user attributes and user string attributes, there are currently 128 ID's (Int of [EDIT: or] Float) that are intended to be used
by either RT_Stats itself, or script developers, intended function of ID's are to in some way eg link an array to a particular
clip, by storing maybe Width, Height, Framecount and perhaps other values, the stored ID's might be used to Validate an array
against a clip.
You could use the Array functions to return multiple results from a script function to the caller via a caller supplied Array
filename, perhaps with some kind of status variable returned directly.


RT_DBase

*****************************************************
********** DBASE FUNCTIONS ***********
*****************************************************

RT_Stats DBASE functions allow fast access to a file based DataBase where each record can have up to 1024 fields of variable type,
Bool, Int, Float, String, or BIN. BIN is a BYTE (8 bit) sized Int where only lowest 8 bits of Int are stored in the DBase field
as an unsigned 8 bit Int, upper 24 bits ignored. there is also a type double used in DBase, this is only of use to internal RT_Stats
functions, setting or getting type double takes or returns type Float (as Avisynth cannot handle double precision float).
The maximum possible DBase file size is about 1TB, and the number of records is restricted to $7FFFFFFE, about 2 Billion.
Field types Bool and BIN require 1 byte, Int and Float 4 bytes, and String is of fixed maximum length (user chosen) up to
256KB ((256 * 1024), no nul terminating character is stored in a DBase String). The private type Double requires 8 bytes.
A DBase file allows up to 1024 Attributes of types Int or Float, which can be used for whatever a user desires, these
attributes are stored in the DBase file header which is 32768 bytes, so the actual data starts at $8000 hex.
In addition to user attributes, a DBase has currently 10 user String Attributes that can be be used for whatever you want, the
string attributes are currently a maximum of 1024 characters in length.
In addition to user attributes and user string attributes, there are currently 128 ID's (Int of [EDIT: or] Float) that are intended to be used
by either RT_Stats itself, or script developers, intended function of ID's are to in some way eg link a DBase to a particular
clip, by storing maybe Width, Height, Framecount and perhaps other values, the stored ID's might be used to Validate a DBase
against a clip.
You could use the DBase functions to return multiple results from a script function to the caller via a caller supplied DBase
filename. The DBase functions also make it more likely that script functions could be written to eg find where edits between
two clips have been made, or previously impossible/implausible tasks performed.

seggitek
27th October 2018, 13:21
Thank you very much.