hello_hello
27th March 2015, 22:03
Not that it matters but I can't work out why myself (I'm not Avisynth smart enough) and I'm a bit curious. Can anybody explain why the following script works fine with Avisynth 2.6 RC1 but produces the following error when using Avisynth+ (2.6.0.5 portable via MeGUI).
Script error. Expected '('
((null), line 340, column 4)
Thanks.
Edit: I had to split the script between two posts.
################################################################################################
### ###
### Simple MDegrain - SMDegrain() ###
### ###
### By Caroliano ###
### ###
### Special Thanks: Didée, Jawed, onesloth, rkalwaitis, Sagekilla and MVtools people ###
### ###
### v0.4 - 03 Sep 2011 ###
### ###
################################################################################################
###
### General purpose pure temporal denoiser, not targeted to a specific source. It is a
### simple wrapper for MDegrain1/2/3, to facilitate using and experimenting with it, with
### minimal dependencies. But it also offers many optional optimizations, plus an internal
### contra-sharpener to make things easier.
###
### Doom9 topic: http://forum.doom9.org/showthread.php?p=1523412
###
### +-----------+
### | CHANGELOG |
### +-----------+
###
###
### v0.4: - Merged changes by Dogway:
### Added parameters "lsb" and "lsb_out", for MVtools2 mod version from cretindesalpes' Dither
### (http://forum.doom9.org/showthread.php?p=1386559#post1386559)
### - Added parameters "hpad" and "vpad"
### - Misc: Fully updated the documentation, copying part of Dogway's updated documentation.
### - Misc: Cosmetics changes on the source code
###
### v0.3 : - Added external prefilted clip option for motion-search (thanks onesloth)
### - Added contrasharpening option (thanks rkalwaitis) <-- new dependencies
### - Shamelesly copied some parts from Jawed's Killer.avsi:
### Added "Refine Motion" (MRecalculate), for possibly improved speed/quality
### Added experimental fake "MDegrain5" with tr = 5
### - Added chroma option for motion-search
### - Experimental SETMOD() support (copied from onesloth mod on fastdegrain())
### - Fix: Plane parameter now works
### - Attention: Changed the defaults for thSAD and overlap.
### - Misc: Cosmetics changes on the source code
### - Misc: A bit more fool-proof
###
### v0.2 : - Added this introductory section
### - Added more parameters
###
### v0.1 : - Basic working version
### - Not released
###
###
### +--------------+
### | DEPENDENCIES |
### +--------------+
###
### Required:
### ------------
### -> MVtools2 (v2.5.11.2 or higher)
### (http://avisynth.org.ru/mvtools/mvtools2.html)
### *or*
###
### -> Dither (1.9.5 or higher) (MVtools2 v2.5.11.2mod included)
### (http://forum.doom9.org/showthread.php?p=1386559#post1386559)
### Optional:
### ------------
### -> MaskTools (v2a48 or higher for lsb=true and/or contrasharp=true) (http://manao4.free.fr/)
### -> Repair (only for contrasharpening=true)
###
###
###
### +------------------+
### | BASIC PARAMETERS |
### +------------------+
###
###
### tr [int: 1, "2", 3, 5]
### --------------
### Temporal radius. Select between MDegrain 1, 2 or 3. Higher is better, but also much slower.
### tr = 5 is an "fake MDegrain5": experimental and incompatible (?) with "LSB = true" and pel > 1.
###
###
### thSAD [int: "200"]
### --------------
### Strenght of denoising. Low values can result in staggered denoising,
### large values can result in ghosting and artefacts.
###
###
### blksize [int: 4, "8", 16]
### --------------
### Size of a block (horizontal). Larger blocks are less sensitive to noise, are faster, but also
### less accurate, leading to ghosting and artefacts. You may use 16 for more speed, when using
### RefineMotion, or for HD resolutions like 1080p.
###
###
### RefineMotion [bool: true, "false"]
### --------------
### Use MRecalculate to refine motion estimation, improving quality at a given blksize (8 or 16 only).
### Using blksize=16 should give quality very similar to blksize=8 but with performance that's somewhat faster.
### Turn it on for better motion vectors, specially when dealing with ghosting issues and whatnot.
### You can think about it like half-steps in quality/speed between 4 and 8 and 16 block sizes.
###
###
### Contrasharp [bool= true, "false"]
### --------------
### "Sharpens the denoised clip, but doesn't add more to any pixel than what was removed previously"
### In the practice you will get a slightly sharper result than the source, which is welcome, but may reintroduce
### artfacts in the source, decreasing the denoising effectiveness, and haloing. Requires MaskTools2.
###
###
###
###
### +---------------------------------+
### | 16 BIT PROCESSING AND DITHERING |
### +---------------------------------+
###
###
### LSB [bool= true, "false"]
### --------------
### This enables 16 bit depth precision for denoising, avoiding banding thanks to a dither algorithm friendly for optimum encodings.
### For this to be used you will need the Dither package and its version of mvtools2 plus MaskTools2a48 or above.
###
###
### LSB_OUT [bool= true, "false"]
### --------------
### If you set LSB to true, you can also choose to output in 16 bits so you can keep filtering in 16 bits or/and use your own ditherpost.
### For this to be used you will need the Dither package and its version of mvtools2 plus MaskTools2a48 or above.
###
###
###
###
### +---------------------+
### | ADVANCED PARAMETERS |
### +---------------------+
###
###
### limit [int: 1 - "255"]
### --------------
### Maximal change of pixel luma (post-process like DeGrainMedian plugin
### and LimitChange function of SSETools plugin, to prevent some artefacts).
###
###
### limitc [int: 1 - "255"]
### --------------
### Maximal change of pixel chroma.
###
###
### pel [int: 1, "2", 4]
### --------------
### Accuracy of the motion estimation. 1 means a precision to the pixel.
### 2 means a precision to half a pixel. 4 means a precision to quarter a pixel, produced by
### spatial interpolation (more accurate but slower and not always better due to big level scale step).
###
###
### overlap [int: "blksize/2"]
### --------------
### Must be *even* and *less* than block size. Try use overlap value from blksize/4 to blksize/2.
### The greater overlap, the more blocks number, and the lesser the processing speed.
###
###
### sharp [int: 0, 1, "2"]
### --------------
### Subpixel interpolation method for pel=2,4.
### Use 0 for soft interpolation (bilinear), 1 for bicubic interpolation (4 tap Catmull-Rom),
### 2 for sharper Wiener interpolation (6 tap, similar to Lanczos.
###
###
### plane [int: 1, 2, 3, "4"]
### --------------
### Select the planes you wish to denoise:
### 0 - luma only, 1 - chroma U, 2 - chroma V, 3 - both chromas, 4 - all.
### Keep in mind that plane=4 can sometimes create chroma smearing.
###
###
### Chroma [bool= "true", false]
### --------------
### Takes chroma planes into consideration for calculating the motion vectors.
### Turn it off for more speed with little cost in quality.
###
###
### Search [int: 0, 1, 2, 3, "4", 5]
### --------------
### 0= 'OneTimeSearch', 1 = 'NStepSearch', 2= Logarithmic, 3= Exhaustive, 4= Hexagon, 5= Uneven Multi Hexagon
### See details at MVtools documentation: http://avisynth.org.ru/mvtools/mvtools2.html
###
###
### Hpad, Vpad [int= "blksize"]
### --------------
### It is horizontal/vertical padding added to source frame (both left and right). Small padding is added for more correct
### motion estimation near frame borders. Turn it to 0 if you are running out of resources in your system.
###
###
### pre [clip: - ]
### --------------
### Sets a different clip that will be used ONLY to obtain the motion vectors. Useful for very damaged/grainy sources.
### You should define the new clip in a variable and reference it here. For example:
###
### blured = last.Blur(1.58) # or a strong and fast denoiser of your preference
### SMDegrain(pre=blured)
###
###
### Dark [bool: true, "false"]
### --------------
### Tweaks scene change detection, to be more sensitive, but can erroneously trigger scene change during
### bright/complex scenery with lots of motion.
###
###
###
###
###
### +-------------+
### | FINAL NOTES |
### +-------------+
###
### If there is an important parameter not implemented, please ask.
### Or better yet, implement it yourself and post in the Doom9 thread.
###
### Many paremeters will likely never be implemented,
### and you are better off using the original MVtools way.
###
################################################################################################
function SMDegrain ( clip input, clip "pre", int "tr", int "thSAD", int "plane", int "limit", int "limitc", int "pel",
\ int "sharp", int "blksize", int "overlap", int "search", bool "RefineMotion", bool "dark", bool "chroma",
\ int "hpad", int "vpad", bool "lsb", bool "lsb_out", bool "contrasharp", bool "preout")
{
o = input
tr = default( tr, 2 )
thSAD = default( thSAD, 200 )
plane = default( plane, 4 )
limit = default( limit, 255 )
limitc = default( limitc, limit)
pel = default( pel, 2 )
sharp = default( sharp, 2 )
chroma = default( chroma, true )
blksize = default( blksize, 8 )
overlap = default( overlap, blksize/2 )
search = default( search, 4 )
hpad = default( hpad, blksize)
vpad = default( vpad, blksize)
lsb_out = default( lsb_out, false)
lsb = default( lsb , lsb_out)
contrasharp = default( contrasharp, false) # contrasharpening off by default.
preout = default( preout , false )
dark = default( dark , false )
RefineMotion = default( RefineMotion, false) # true means MRecalculate will be used to improve motion vectors
# Invalid input handling and setting adtional internal variables.
lsb_out ? Assert (lsb == true, "lsb_out requires: lsb=true") : NOP
lsb ? Assert (tr <= 3, "tr > 3 isn't supported when lsb=true") : NOP
pel = (tr > 3) ? 1 : pel
o = o.assumeframebased() # MSuper pel=2 is faster with this
RefineMotion ? Assert (blksize >= 8 , "For RefineMotion you need a blksize of 8 or 16") : NOP
halfblksize = blksize/2 # MRecalculate works with half block size
halfoverlap = (overlap == 2) ? overlap : overlap/2 # Halve the overlap to suit the halved block size
halfthSAD = thSAD/2 # MRecalculate uses a more strict thSAD, which defaults to 150 (half of function's default of 300)
# The default values thSCD1=400, thSCD2=130 often do not reckognize some scenechanges,
# especially in dimmed/dark scenery. lowering to sth like 350,90 is more safe in reckognizing scenechanges ...
# however, the more you lower these values, the more there is danger that the detection
# erroneously triggers during bright/complex scenery with lots of motion.
thSCD1 = (dark == true) ? 350 : 400
thSCD2 = (dark == true) ? 90 : 130
# See if SetMTMode is used. If yes, change it to the most adequate (?) for the script.
try {
SMTMdefaultmode = GetMTMode()
SMTM = (SMTMdefaultmode!=0)
} catch(err_msg) {SMTM = false}
Script error. Expected '('
((null), line 340, column 4)
Thanks.
Edit: I had to split the script between two posts.
################################################################################################
### ###
### Simple MDegrain - SMDegrain() ###
### ###
### By Caroliano ###
### ###
### Special Thanks: Didée, Jawed, onesloth, rkalwaitis, Sagekilla and MVtools people ###
### ###
### v0.4 - 03 Sep 2011 ###
### ###
################################################################################################
###
### General purpose pure temporal denoiser, not targeted to a specific source. It is a
### simple wrapper for MDegrain1/2/3, to facilitate using and experimenting with it, with
### minimal dependencies. But it also offers many optional optimizations, plus an internal
### contra-sharpener to make things easier.
###
### Doom9 topic: http://forum.doom9.org/showthread.php?p=1523412
###
### +-----------+
### | CHANGELOG |
### +-----------+
###
###
### v0.4: - Merged changes by Dogway:
### Added parameters "lsb" and "lsb_out", for MVtools2 mod version from cretindesalpes' Dither
### (http://forum.doom9.org/showthread.php?p=1386559#post1386559)
### - Added parameters "hpad" and "vpad"
### - Misc: Fully updated the documentation, copying part of Dogway's updated documentation.
### - Misc: Cosmetics changes on the source code
###
### v0.3 : - Added external prefilted clip option for motion-search (thanks onesloth)
### - Added contrasharpening option (thanks rkalwaitis) <-- new dependencies
### - Shamelesly copied some parts from Jawed's Killer.avsi:
### Added "Refine Motion" (MRecalculate), for possibly improved speed/quality
### Added experimental fake "MDegrain5" with tr = 5
### - Added chroma option for motion-search
### - Experimental SETMOD() support (copied from onesloth mod on fastdegrain())
### - Fix: Plane parameter now works
### - Attention: Changed the defaults for thSAD and overlap.
### - Misc: Cosmetics changes on the source code
### - Misc: A bit more fool-proof
###
### v0.2 : - Added this introductory section
### - Added more parameters
###
### v0.1 : - Basic working version
### - Not released
###
###
### +--------------+
### | DEPENDENCIES |
### +--------------+
###
### Required:
### ------------
### -> MVtools2 (v2.5.11.2 or higher)
### (http://avisynth.org.ru/mvtools/mvtools2.html)
### *or*
###
### -> Dither (1.9.5 or higher) (MVtools2 v2.5.11.2mod included)
### (http://forum.doom9.org/showthread.php?p=1386559#post1386559)
### Optional:
### ------------
### -> MaskTools (v2a48 or higher for lsb=true and/or contrasharp=true) (http://manao4.free.fr/)
### -> Repair (only for contrasharpening=true)
###
###
###
### +------------------+
### | BASIC PARAMETERS |
### +------------------+
###
###
### tr [int: 1, "2", 3, 5]
### --------------
### Temporal radius. Select between MDegrain 1, 2 or 3. Higher is better, but also much slower.
### tr = 5 is an "fake MDegrain5": experimental and incompatible (?) with "LSB = true" and pel > 1.
###
###
### thSAD [int: "200"]
### --------------
### Strenght of denoising. Low values can result in staggered denoising,
### large values can result in ghosting and artefacts.
###
###
### blksize [int: 4, "8", 16]
### --------------
### Size of a block (horizontal). Larger blocks are less sensitive to noise, are faster, but also
### less accurate, leading to ghosting and artefacts. You may use 16 for more speed, when using
### RefineMotion, or for HD resolutions like 1080p.
###
###
### RefineMotion [bool: true, "false"]
### --------------
### Use MRecalculate to refine motion estimation, improving quality at a given blksize (8 or 16 only).
### Using blksize=16 should give quality very similar to blksize=8 but with performance that's somewhat faster.
### Turn it on for better motion vectors, specially when dealing with ghosting issues and whatnot.
### You can think about it like half-steps in quality/speed between 4 and 8 and 16 block sizes.
###
###
### Contrasharp [bool= true, "false"]
### --------------
### "Sharpens the denoised clip, but doesn't add more to any pixel than what was removed previously"
### In the practice you will get a slightly sharper result than the source, which is welcome, but may reintroduce
### artfacts in the source, decreasing the denoising effectiveness, and haloing. Requires MaskTools2.
###
###
###
###
### +---------------------------------+
### | 16 BIT PROCESSING AND DITHERING |
### +---------------------------------+
###
###
### LSB [bool= true, "false"]
### --------------
### This enables 16 bit depth precision for denoising, avoiding banding thanks to a dither algorithm friendly for optimum encodings.
### For this to be used you will need the Dither package and its version of mvtools2 plus MaskTools2a48 or above.
###
###
### LSB_OUT [bool= true, "false"]
### --------------
### If you set LSB to true, you can also choose to output in 16 bits so you can keep filtering in 16 bits or/and use your own ditherpost.
### For this to be used you will need the Dither package and its version of mvtools2 plus MaskTools2a48 or above.
###
###
###
###
### +---------------------+
### | ADVANCED PARAMETERS |
### +---------------------+
###
###
### limit [int: 1 - "255"]
### --------------
### Maximal change of pixel luma (post-process like DeGrainMedian plugin
### and LimitChange function of SSETools plugin, to prevent some artefacts).
###
###
### limitc [int: 1 - "255"]
### --------------
### Maximal change of pixel chroma.
###
###
### pel [int: 1, "2", 4]
### --------------
### Accuracy of the motion estimation. 1 means a precision to the pixel.
### 2 means a precision to half a pixel. 4 means a precision to quarter a pixel, produced by
### spatial interpolation (more accurate but slower and not always better due to big level scale step).
###
###
### overlap [int: "blksize/2"]
### --------------
### Must be *even* and *less* than block size. Try use overlap value from blksize/4 to blksize/2.
### The greater overlap, the more blocks number, and the lesser the processing speed.
###
###
### sharp [int: 0, 1, "2"]
### --------------
### Subpixel interpolation method for pel=2,4.
### Use 0 for soft interpolation (bilinear), 1 for bicubic interpolation (4 tap Catmull-Rom),
### 2 for sharper Wiener interpolation (6 tap, similar to Lanczos.
###
###
### plane [int: 1, 2, 3, "4"]
### --------------
### Select the planes you wish to denoise:
### 0 - luma only, 1 - chroma U, 2 - chroma V, 3 - both chromas, 4 - all.
### Keep in mind that plane=4 can sometimes create chroma smearing.
###
###
### Chroma [bool= "true", false]
### --------------
### Takes chroma planes into consideration for calculating the motion vectors.
### Turn it off for more speed with little cost in quality.
###
###
### Search [int: 0, 1, 2, 3, "4", 5]
### --------------
### 0= 'OneTimeSearch', 1 = 'NStepSearch', 2= Logarithmic, 3= Exhaustive, 4= Hexagon, 5= Uneven Multi Hexagon
### See details at MVtools documentation: http://avisynth.org.ru/mvtools/mvtools2.html
###
###
### Hpad, Vpad [int= "blksize"]
### --------------
### It is horizontal/vertical padding added to source frame (both left and right). Small padding is added for more correct
### motion estimation near frame borders. Turn it to 0 if you are running out of resources in your system.
###
###
### pre [clip: - ]
### --------------
### Sets a different clip that will be used ONLY to obtain the motion vectors. Useful for very damaged/grainy sources.
### You should define the new clip in a variable and reference it here. For example:
###
### blured = last.Blur(1.58) # or a strong and fast denoiser of your preference
### SMDegrain(pre=blured)
###
###
### Dark [bool: true, "false"]
### --------------
### Tweaks scene change detection, to be more sensitive, but can erroneously trigger scene change during
### bright/complex scenery with lots of motion.
###
###
###
###
###
### +-------------+
### | FINAL NOTES |
### +-------------+
###
### If there is an important parameter not implemented, please ask.
### Or better yet, implement it yourself and post in the Doom9 thread.
###
### Many paremeters will likely never be implemented,
### and you are better off using the original MVtools way.
###
################################################################################################
function SMDegrain ( clip input, clip "pre", int "tr", int "thSAD", int "plane", int "limit", int "limitc", int "pel",
\ int "sharp", int "blksize", int "overlap", int "search", bool "RefineMotion", bool "dark", bool "chroma",
\ int "hpad", int "vpad", bool "lsb", bool "lsb_out", bool "contrasharp", bool "preout")
{
o = input
tr = default( tr, 2 )
thSAD = default( thSAD, 200 )
plane = default( plane, 4 )
limit = default( limit, 255 )
limitc = default( limitc, limit)
pel = default( pel, 2 )
sharp = default( sharp, 2 )
chroma = default( chroma, true )
blksize = default( blksize, 8 )
overlap = default( overlap, blksize/2 )
search = default( search, 4 )
hpad = default( hpad, blksize)
vpad = default( vpad, blksize)
lsb_out = default( lsb_out, false)
lsb = default( lsb , lsb_out)
contrasharp = default( contrasharp, false) # contrasharpening off by default.
preout = default( preout , false )
dark = default( dark , false )
RefineMotion = default( RefineMotion, false) # true means MRecalculate will be used to improve motion vectors
# Invalid input handling and setting adtional internal variables.
lsb_out ? Assert (lsb == true, "lsb_out requires: lsb=true") : NOP
lsb ? Assert (tr <= 3, "tr > 3 isn't supported when lsb=true") : NOP
pel = (tr > 3) ? 1 : pel
o = o.assumeframebased() # MSuper pel=2 is faster with this
RefineMotion ? Assert (blksize >= 8 , "For RefineMotion you need a blksize of 8 or 16") : NOP
halfblksize = blksize/2 # MRecalculate works with half block size
halfoverlap = (overlap == 2) ? overlap : overlap/2 # Halve the overlap to suit the halved block size
halfthSAD = thSAD/2 # MRecalculate uses a more strict thSAD, which defaults to 150 (half of function's default of 300)
# The default values thSCD1=400, thSCD2=130 often do not reckognize some scenechanges,
# especially in dimmed/dark scenery. lowering to sth like 350,90 is more safe in reckognizing scenechanges ...
# however, the more you lower these values, the more there is danger that the detection
# erroneously triggers during bright/complex scenery with lots of motion.
thSCD1 = (dark == true) ? 350 : 400
thSCD2 = (dark == true) ? 90 : 130
# See if SetMTMode is used. If yes, change it to the most adequate (?) for the script.
try {
SMTMdefaultmode = GetMTMode()
SMTM = (SMTMdefaultmode!=0)
} catch(err_msg) {SMTM = false}