View difference between Paste ID: 3qLmyvdd and 84b2rGtS
SHOW: | | - or go back to the newest paste.
1
# AnimeIVTC() by thetoof
2-
# v2.21 2018-02-28 mod
2+
# v2.22 2018-04-17 mod
3
# last update by AmjadSONY was:- make "precision=1" use "nnedi3" only for "Toriko Anime" by using it like this:- AnimeIVTC(1, precision=1)
4
# add mode22 bool to use it in mode 2 for Spatial field-blend (field-blend in a part of the picture), ex:- AnimeIVTC(2, bbob=1, mode22=true)
5
# TC file now will out in V2 ;) , add ediext clip to use it with QTGMC and add bob4p to change QTGMC Preset , add extbob clip to use an External bobber with bbob/cbob=5 , chrfix in mode 1 and other things fixed by doom9 member
6
# make chrfix work. add dchr bool, can help chrfix with some source, add palf bool for no decimate in mode 1 and make fps 24 instead of 25 for mode 2 in pal source, add tcfv1 bool to made TC file v1 and make it true by default
7
# add nvfr bool for VFR noisy sources, add real30p bool to not use daa with 30p, and some fix in for PAL cases and other things
8
# add TFM (mode, cthresh, blockx, blocky, MI) and some fix
9
# add extbobf string to use external bob function, old external bob clip (extbob) still exist, and if you use both the old extbob will win
10
# make precision=0 use pp=0 in tfm for speed and quality too, add precision=4 same as precision=3 but no blend, add precision=5 to use yadifmod (usefull for very old anime)
11
# add precision=6 to use extbobf\extbob with ConvertFPS to back to original fps, add precision=7 to use extbobf\extbob with SelectEven to back to original fps (no blend), and precision=8 for already half bob fps
12
# add autoAssuf to auto set field to match from in tfm to help with noisy old telecined source, add tfm pp and metric
13
# tweak autoAssuf in mode=1 with another method, others modifications
14
# add tfm micmatching for it important to set it to 0 (zero) in many dvd 20XX anime (maybe other source need that too)
15
# add ediandnn to chose between nnedi3 if set to 1 or eedi3 if set to 2 or eedi3+nnedi3 if set to 3, others modifications
16
# add yadifrepwithtdeint to use yadifmod with less Artefacts
17
# yadifrepwithtdeint more tweak
18
# add o3025cfr to out 25 in PAL and 30 in NTSC, and it useful to avoid blended with omode=1
19
# palf and o3025cfr more tweak, now palf work in pal only and in mode 1 and 3 will out 24
20
# fix nnedi3_rpow2 and make credconv accept external clip for credits
21
# workaround for RgTools Repair in yadifrepwithtdeint
22
# add bobpresmooth for more stability
23
# add bbob4_params and cbob4_params to use more settings for QTGMC, add precision=9 to use bbob (maybe you need it with bbob=4 to use QTGMC with TFM)
24
# add ediandnn=4 to use QTGMC in yadifmod in yadifrepwithtdeint
25
# make precision=6 TDeint + motion mask add b/c bob 6 TDeint + motion mask
26
# chrfix now work with YUY2 in avs 2.6
27
# yadifrepwithtdeint now repwithtdeint and work with bbob 3 and 4 and precision 5
28
# add crepwithtdeint for cbob 3 and 4
29
# tweak autoAssuf
30
# add tdeint sharp bool and type int to set interpolation for c/repwithtdeint and b/cbob precision 6
31
# fix chrfix bug
32
# update chroma_rep/chroma_rep2 to http://forum.doom9.org/showthread.php?p=1268074&highlight=chroma_rep#post1268074 (this not work without some edit I did in 2014), chrfix now will accept float as thr, add mChroma/chroma tfm
33
# ediext clip now can be used instead of ediandnn, add prefiltered_i to use it instead of bobpresmooth 
34
# add yadifmod2 and other things for yadifmod, make the cache more for mode22 and chrfix
35
# add tmm2
36
# added vidDetect parameter for VFR
37
# added mode 5 same as 3 but use nnrep method to ediandnn, mode 6 too, but it's like 4, and now you can use negative value for use nnedi3 with Padding to avoids edges distortion on top and bottom
38
39
# Read the documentation for all the required info to know how to use this function, With note that there are some things have changed in this MOD
40
41
function AnimeIVTC (clip i, int "mode", int "aa", int "precision", int "killcomb", int "cache", bool "ifade", float "sfthr", bool "sfshow"\
42
		, val "chrfix" \
43
		, bool "blend" \  
44
		, bool "normconv" \
45
		, int "pattern" \
46
		, int "pass", bool "rendering" \
47
		, int "bbob", int "cbob", string "edimode", int "degrain", int "omode", int "cthresh", int "blockx", int "blocky", int "MI", int "tfmm", int "pp", int "metric", int "micmatching", bool "mChroma", bool "Chroma" \
48
		, int "i1", int "i2", int "e1", int "e2", int "e3", int "p1", int "p2", bool "dchr", bool "palf", bool "tcfv1", bool "nvfr", bool "real30p", bool "autoAssuf", int "ediandnn", bool "o3025cfr", string "bbob4_params", bool "crepwithtdeint", int "tdeinttype" \
49
		, int "overlap", int "pel", int "search", bool "nnedi3pel", val "credconv", bool "mode22", val "ediext", string "bob4p", clip "extbob", string "extbobf", bool "repwithtdeint", bool "bobpresmooth", string "cbob4_params", bool "tdeintsharp", val "prefiltered_i" \
50
		, float "dark", int "thin", int "sharp", int "smooth", bool "stabilize", int "tradius", int "aapel", int "aaov", int "aablk", string "aatype", int "vidDetect"){
51
52
###General arguments###
53
Assert(defined(mode), "Specify a mode... please read the documentation.")
54
55
#Highest quality by default
56
precision 	= default ( precision, 		  3 ) 
57
58
#change pal fps
59
palf	= default ( palf,         false )
60
o3025cfr	= default ( o3025cfr,       false )
61
62
#VFR default optional
63
nvfr	= default ( nvfr,         false )
64
65
#boolean "creds" is set to true if any of the i/p arguments are defined (i.e. if there's a 30i or 30p section to process)
66
creds = defined(i1) ? true : false
67
creds = defined(i2) ? true : creds
68
creds = defined(p1) ? true : creds
69
creds = defined(p2) ? true : creds
70
creds = defined(e1) ? true : creds
71
creds = defined(e2) ? true : creds
72
creds = defined(e3) ? true : creds
73
74
# real30p
75
real30p	 = default( real30p,        false)
76
77
# auto set field to match from to help with noisy old telecined source
78
autoAssuf= default( autoAssuf,      false)
79
80
###Framerate preparation###
81
normconv = default( normconv, false)
82
#Determine source region by analysing framerate
83
Ifrate 	= round(framerate(i))==30 ? 1 : framerate(i)==25 ? 2 : 3
84
assert(ifrate!=3, "What is your input clip?? It's not 30fps NTSC nor 25fps PAL... maybe you're using the function for a purpose it was not meant to. Please post in the AnimeIVTC thread.")
85
86
#Set the output to the other region if normconv (norm-conversion) is set to true, use same as input if not
87
Ofrate 	= Ifrate==1 && normconv ? 2 : Ifrate==2 && normconv ? 1 : Ifrate
88
89
#prepare arguments for srestore and tdecimate based on user settings (as seen previously)
90
frate  	= Ofrate==1 ? o3025cfr ? 29.970 : 23.976 : palf ? 24 : 25
91
tnum	= Ofrate==1 ? o3025cfr ? 30000 : 24000 : mode!=4 && palf ? 24 : ((mode==1 || mode==3) && o3025cfr) || mode==2 ? 25 : 20
92
tden	= Ofrate==1 ? 1001 : 1
93
94
95
96
#Set pattern=0 (tdecimate) for DHT (safest)
97
pattern		= default ( pattern,		  0 )
98
99
#Set defaults of bobbing filters to use to general optimal quality
100
ediandnn	= default ( ediandnn, 	          1 )
101
reptdei         = default (repwithtdeint,      false)
102
creptdei        = default (crepwithtdeint,      false)
103
bobpresmooth    = default (bobpresmooth      , false)
104
bbob		= default ( bbob, 	          3 )
105
cbob		= default ( cbob, 	          4 )
106
107
108
yadiffun=VersionNumber() < 2.6 ? "yadifmod" : "yadifmod2"
109
nonyuy2=!(VersionNumber() < 2.6) && i.isyuy2()
110
111
prefiltered_i = defined(prefiltered_i) ? isclip(prefiltered_i) ? prefiltered_i : Eval("i." + prefiltered_i) : undefined()
112
iforbob = defined(prefiltered_i) ? prefiltered_i : bobpresmooth ? i.QTGMC_bob(0,0.5).nonyuy2clipin(nonyuy2).reduceflicker(strength=2).nonyuy2clipout(nonyuy2).interlaced60or50(BFF=!(GetParity(i))) : i
113
iforbob = bobpresmooth ? isyuy2(i) ? iforbob.SeparateFields.Interleaved2Planar.Repair(i.SeparateFields.Interleaved2Planar,Planar=true).Planar2Interleaved.weave : iforbob.SeparateFields.Repair(i.SeparateFields).weave : iforbob
114
bob5_with_extbob= (cbob == 5 || bbob == 5 || (precision >= 7 && precision != 9)) ? (defined(extbobf) || defined(extbob)) ? 1 : 0 : 2
115
Assert(bob5_with_extbob!=0 , "please specify extbobf or extbob if you use bbob or cbob 5 or precision 7 or 8.")
116
extbob = defined(extbobf) && !defined(extbob) ? Eval("iforbob." + extbobf) : extbob
117
118
#Sets output mode to 1 (23.976fps for NTSC and 25fps for PAL) when no 30i or 30p sections are specified and sets it to 0 to use NOP() for every operation where it needs to be specified by the user
119
omode = (creds==false && mode!=4) || ofrate==2 || normconv ? 1 : default (omode, 0)
120
Assert(omode!=0, "Specify an output mode (omode)... please read the documentation.")
121
normconv ? assert(mode==2, "Why would you use normconv=true with a telecined source?") : nop()
122
123
###Framerate conversion arguments###
124
bs		= (i.width>1100) ? 16 : 8
125
overlap 	= default ( overlap,	       bs/2 )
126
pel       	= default ( pel, 		  2 )
127
search 		= default ( search, 		  4 )
128
assert(search >= 2, "Using a lower search than 2 will most probably lead to weird artifacts")
129
nnedi3pel 	= default ( nnedi3pel, 	      false )
130
credconv	= default ( credconv, 	    omode==2 ? "a" : "blah" )
131
creds && !isclip(credconv) ? assert(credconv!= "blah", "Please specify credconv. Check in the docs to see which is more appropriate to your source.") : nop()
132
133
#VFR - If this is pass=2 and that the user made a rendering pass out of pass=1, use input directly for decimation instead of recomputing everything
134
pass		= default (pass,		  1 )
135
rendering 	= default ( rendering,	      false )
136
137
#Ask if hard telecine (mode=1) is actually blend telecine (patter = 3 clean frames followed by 2 blended ones)
138
blend		= default ( blend, 	      false )
139
140
#Ask if double chroma blend removal is needed (see guide for more info about this problem)
141
chrfix_f=defined(chrfix) ? isfloat(chrfix) : false
142
defined(chrfix) ? Assert(chrfix_f || isbool(chrfix),"'chrfix' only accepts float and bool inputs") : nop()
143
chrfix_b= default ( chrfix_f ? true : chrfix,       false )
144
dchr	= default ( dchr,       false )
145
chr_rep_thr = chrfix_f ? chrfix : 0.125
146
147
#mode22 for Spatial field-blend
148
mode22	= default ( mode22,       false )
149
150
#Set cache to 10 frames for all functions using scriptclip to prevent seeking issues + frame order mess-up with temporal filters
151
cache		= default ( cache,		 10 )
152
153
#Let the user decide which edimode (optimal varies greatly depending on source) and degrain (++ affects quality vs speed) settings to use in qTGMC
154
degrain         = default ( degrain,              1 )
155
bbob4_params    = default (bbob4_params,          "")
156
cbob4_params    = default (cbob4_params,          "")
157
158
#Set decombing and antialiasing filters to off by default
159
killcomb	= default ( killcomb,		  0 )
160
aa		= default ( aa,			  0 )
161
aa = killcomb==3 && aa==2 ? 0 : aa
162
163
#Set interlaced fade ins detection (and correction to off by default)
164
ifade		= default ( ifade,	       false )
165
#Also turn it off if aa=2 (use daa()), since it applies the same operation on the whole clip as ifade would have had selectively)
166
ifade		= aa==2 || killcomb==3 ? false : ifade
167
sfthr	= default ( sfthr,  0.4 ) 
168
sfshow = default ( sfshow, false )
169
170
171
usefm = mode==1 || (mode==4 && (pass==2 || creds || omode==1))
172
usehfm = mode==4 && pass==1 && usefm==false
173
174
#For later NOP() use if blendbob is not needed
175
usebbob = (chrfix_b && blend) || mode==2 || (precision==9 && (usefm || usehfm))
176
177
#For later NOP() use if clearbob is not needed
178
usecbob = mode==3 || defined(i1) || chrfix_b && blend==false
179
180
#Assign clip to prevent double computation
181-
edeint= ((usecbob && cbob < 6) || (usebbob && bbob < 6) || ((usefm || usehfm) && precision < 6)) || autoAssuf ? defined(ediext) ? ediext : ediandnn == 1 ? iforbob.nnedi3(-2) : ediandnn == 2 ? iforbob.eedi3(-2) : ediandnn == 3 ? i.eedi3(-2,sclip=iforbob.nnedi3(-2)) : i.eedi3(-2,sclip=iforbob.nnedi3(-2)) : nop()
181+
182
edeintn= ((usecbob && cbob < 6) || (usebbob && bbob < 6) || ((usefm || usehfm) && precision < 6)) || autoAssuf ? defined(ediext) ? ediext : ediandnn != 2 || ediandnn != -2 ? ediandnn < 0 ? iforbob.Padding(2,4,2,4).nnedi3(-2).crop(2,4,-2,-4,true) : iforbob.nnedi3(-2) : nop() : nop()
183
edeint= ((usecbob && cbob < 6) || (usebbob && bbob < 6) || ((usefm || usehfm) && precision < 6)) || autoAssuf ? defined(ediext) ? ediext : ediandnn == 1 ? edeintn : ediandnn == 2 ? iforbob.eedi3(-2) : ediandnn == 5 || ediandnn == 6 ? i.eedi3(-2,sclip=edeintn).Repair(edeintn,9) : i.eedi3(-2,sclip=edeintn) : edeintn
184
emask = (usebbob && (bbob==2 || ((bbob==3 || bbob==4) && reptdei) || bbob==6)) || (usecbob && (cbob==2 || ((cbob==3 || cbob==4) && reptdei) || cbob==6)) || ((usefm || usehfm) && precision==3) ? iforbob.tmm2_ortmm1(1) : nop()
185
186
187
###Alright, let's start doing something :p ###
188
189
#########
190
#Bobbing#
191
#########
192
193
#Use non-motion-compensated bobber for blended clips since blends have a negative impact on motion detection (if blends are averaged with frames, they can be harder to detect/remove) (mode=2 and mode=1 with blend and chrfix because blend telecine... well has a lot of blends)
194
blendbob 	= usebbob ?	bbob<=0 ? iforbob.tdeint(1) 			 		 	                : 
195-
\				bbob==3 ? reptdei ? ediandnn==4 ? Eval("i.yadifmodclipin(nonyuy2)."+yadiffun+"(mode=3,edeint=iforbob.QTGMC(Preset=bob4p,edimode=edimode,ediext= !defined(edimode) && !defined(ediext) ? edeint : ediext,tr2=degrain" + bbob4_params + ").yadifmodclipin(nonyuy2))").yadifmodclipout(nonyuy2) : eval("i.yadifmodclipin(nonyuy2)."+yadiffun+"(mode=3,edeint=edeint.yadifmodclipin(nonyuy2))").yadifmodclipout(nonyuy2) : eval("iforbob.yadifmodclipin(nonyuy2)."+yadiffun+"(mode=1,edeint=edeint.yadifmodclipin(nonyuy2))").yadifmodclipout(nonyuy2) 		 		        :
195+
196
\				bbob==2 ? iforbob.tdeint(1,		edeint=edeint,emask=emask)	 	        : 
197
\				bbob==3 ? reptdei ? ediandnn==4 || ediandnn==6 ? Eval("i.yadifmodclipin(nonyuy2)."+yadiffun+"(mode=3,edeint=iforbob.QTGMC(Preset=bob4p,edimode=edimode,ediext= !defined(edimode) && !defined(ediext) ? edeint : ediext,tr2=degrain" + bbob4_params + ").yadifmodclipin(nonyuy2))").yadifmodclipout(nonyuy2) : eval("i.yadifmodclipin(nonyuy2)."+yadiffun+"(mode=3,edeint=edeint.yadifmodclipin(nonyuy2))").yadifmodclipout(nonyuy2) : eval("iforbob.yadifmodclipin(nonyuy2)."+yadiffun+"(mode=1,edeint=edeint.yadifmodclipin(nonyuy2))").yadifmodclipout(nonyuy2) 		 		        :
198
\				bbob==4 ? Eval("iforbob.QTGMC(Preset=bob4p,edimode=edimode,ediext= !defined(edimode) && !defined(ediext) ? edeint : ediext,tr2=degrain" + bbob4_params + ")")	:
199
\				bbob==5 ? extbob	 	        : 
200
\				          i.tdeint(1, emask=emask, sharp=tdeintsharp, type=tdeinttype)                      	                                        : NOP()
201
blendbob 	= usebbob ?	((bbob==3 || bbob==4) && reptdei) ? isyuy2(i) ? blendbob.Interleaved2Planar.Repair(i.tdeint(1,emask=emask, sharp=tdeintsharp, type=tdeinttype).Interleaved2Planar,Planar=true).Planar2Interleaved : blendbob.Repair(i.tdeint(1,emask=emask, sharp=tdeintsharp, type=tdeinttype)) : blendbob : nop()
202
203
#Allow usage of mo-comp bobber (TempGaussMC) when source is not blended. Highly recommended for stability. (mode=3, interlaced credits, used in chrfix because impact is minimal compared to bob flicker on the whole clip)
204
clearbob 	= usecbob ?	cbob<=0 ? iforbob.tdeint(1)						                : 
205-
\				cbob==3 ? creptdei ? ediandnn==4 ? Eval("i.yadifmodclipin(nonyuy2)."+yadiffun+"(mode=3,edeint=iforbob.QTGMC(Preset=bob4p,edimode=edimode,ediext= !defined(edimode) && !defined(ediext) ? edeint : ediext,tr2=degrain" + bbob4_params + ").yadifmodclipin(nonyuy2))").yadifmodclipout(nonyuy2) : eval("i.yadifmodclipin(nonyuy2)."+yadiffun+"(mode=3,edeint=edeint.yadifmodclipin(nonyuy2))").yadifmodclipout(nonyuy2) : eval("iforbob.yadifmodclipin(nonyuy2)."+yadiffun+"(mode=1,edeint=edeint.yadifmodclipin(nonyuy2))").yadifmodclipout(nonyuy2)			                :
205+
206
\				cbob==2 ? iforbob.tdeint(1,		edeint=edeint,emask=emask)	                : 
207
\				cbob==3 ? creptdei ? ediandnn==4 || ediandnn==6 ? Eval("i.yadifmodclipin(nonyuy2)."+yadiffun+"(mode=3,edeint=iforbob.QTGMC(Preset=bob4p,edimode=edimode,ediext= !defined(edimode) && !defined(ediext) ? edeint : ediext,tr2=degrain" + bbob4_params + ").yadifmodclipin(nonyuy2))").yadifmodclipout(nonyuy2) : eval("i.yadifmodclipin(nonyuy2)."+yadiffun+"(mode=3,edeint=edeint.yadifmodclipin(nonyuy2))").yadifmodclipout(nonyuy2) : eval("iforbob.yadifmodclipin(nonyuy2)."+yadiffun+"(mode=1,edeint=edeint.yadifmodclipin(nonyuy2))").yadifmodclipout(nonyuy2)			                :
208
\			        cbob==4 ? Eval("iforbob.QTGMC(Preset=bob4p,edimode=edimode,ediext= !defined(edimode) && !defined(ediext) ? edeint : ediext,tr2=degrain" + cbob4_params + ")")	:
209
\				cbob==5 ? extbob	                : 
210
\				          i.tdeint(1, emask=emask, sharp=tdeintsharp, type=tdeinttype)                                                        	: NOP()
211
clearbob 	= usecbob ?	((cbob==3 || cbob==4) && creptdei) ? isyuy2(i) ? clearbob.Interleaved2Planar.Repair(i.tdeint(1,emask=emask, sharp=tdeintsharp, type=tdeinttype).Interleaved2Planar,Planar=true).Planar2Interleaved : clearbob.Repair(i.tdeint(1,emask=emask, sharp=tdeintsharp, type=tdeinttype)) : clearbob : nop()
212
213
############################
214
#Chroma swap between fields# chrfix
215
############################
216
217
#Repair double chroma blending if requested by user using xbob depending on source (known by the mode)
218
chrdeb = chrfix_b ? blend || mode==2 ? dchr ? blendbob.chroma_rep2(cache*2,chr_rep_thr) : blendbob.chroma_rep(cache*2,chr_rep_thr) : dchr ? clearbob.chroma_rep2(cache*2,chr_rep_thr) : clearbob.chroma_rep(cache*2,chr_rep_thr) : nop()
219
220
#Remove duplicates (like a safe selecteven/odd) for further processing before final decimation (hybrid decimation (except blend decimation to prevent having 2 calls of tdecimate) or blend telecine IVTC)
221
#Once bobbed, in mode=1 (tdecimate(1,3,5), in mode=1 + blend = back to 30fps for further deblending, in mode=2 srestore will do the job, in mode=3 tdecimate(1,3,5), in mode 4 VFR needs 30, CFR can do it (personal notes)
222
debprep = chrfix_b ? mode==1 && blend || mode==4 && omode==2 ? chrdeb.tdecimate(1,1,2) : chrdeb : i
223
224
################
225
#Field matching# MODE=1 AND 4
226
################
227
228
#Field match for mode 1, pass 2 of mode 4 (hybrid without tfm.txt output) or mode=4 with blend decimation (no need for txt file) or mode=4 with interlaced credits (txt file unusable)
229
230
tfmcli2=(precision==0 && ((usefm && !blend) || usehfm)) ? undefined : 
231
\	(precision==1 && ((usefm && !blend) || usehfm)) ? edeint.SelectEven() : 
232
\	(precision==2 && ((usefm && !blend) || usehfm)) ? iforbob.tdeint(2,edeint=edeint) : 
233-
\	(precision==5 && ((usefm && !blend) || usehfm)) ? reptdei ? ediandnn==4 ? Eval("i.yadifmodclipin(nonyuy2)."+yadiffun+"(mode=2,edeint=iforbob.QTGMC(Preset=bob4p,edimode=edimode,ediext= !defined(edimode) && !defined(ediext) ? edeint : ediext,tr2=degrain" + bbob4_params + ").SelectEven().yadifmodclipin(nonyuy2))").yadifmodclipout(nonyuy2) : eval("i.yadifmodclipin(nonyuy2)."+yadiffun+"(mode=2,edeint=edeint.SelectEven().yadifmodclipin(nonyuy2))").yadifmodclipout(nonyuy2) : eval("iforbob.yadifmodclipin(nonyuy2)."+yadiffun+"(edeint=edeint.SelectEven().yadifmodclipin(nonyuy2))").yadifmodclipout(nonyuy2) : 
233+
234
\	(precision==4 && ((usefm && !blend) || usehfm)) ? iforbob.tdeint(0,edeint=edeint.SelectEven(),emask=iforbob.tmm2_ortmm1(0)) : 
235
\	(precision==5 && ((usefm && !blend) || usehfm)) ? reptdei ? ediandnn==4 || ediandnn==6 ? Eval("i.yadifmodclipin(nonyuy2)."+yadiffun+"(mode=2,edeint=iforbob.QTGMC(Preset=bob4p,edimode=edimode,ediext= !defined(edimode) && !defined(ediext) ? edeint : ediext,tr2=degrain" + bbob4_params + ").SelectEven().yadifmodclipin(nonyuy2))").yadifmodclipout(nonyuy2) : eval("i.yadifmodclipin(nonyuy2)."+yadiffun+"(mode=2,edeint=edeint.SelectEven().yadifmodclipin(nonyuy2))").yadifmodclipout(nonyuy2) : eval("iforbob.yadifmodclipin(nonyuy2)."+yadiffun+"(edeint=edeint.SelectEven().yadifmodclipin(nonyuy2))").yadifmodclipout(nonyuy2) : 
236
\	(precision==6 && ((usefm && !blend) || usehfm)) ? i.tdeint(0,emask=iforbob.tmm2_ortmm1(0), sharp=tdeintsharp, type=tdeinttype) : 
237
\	(precision==7 && ((usefm && !blend) || usehfm)) ? extbob.SelectEven : 
238
\	(precision==8 && ((usefm && !blend) || usehfm)) ? extbob : 
239
\	(precision==9 && ((usefm && !blend) || usehfm)) ? blendbob.SelectEven : 
240
\	nop()
241
tfmcli2=(usefm && !blend) || usehfm ? precision==5 && reptdei ? isyuy2(i) ? tfmcli2.Interleaved2Planar.Repair(i.tdeint(0,emask=iforbob.tmm2_ortmm1(0), sharp=tdeintsharp, type=tdeinttype).Interleaved2Planar,Planar=true).Planar2Interleaved : tfmcli2.Repair(i.tdeint(0,emask=iforbob.tmm2_ortmm1(0), sharp=tdeintsharp, type=tdeinttype)) : tfmcli2 : nop()
242
243
#field match for hard telecine or blend telecine restoration for mode==1
244
245
global fm=(precision==0 && usefm) ? blend ? debprep.srestore(omode="pp0") : i.tfm(slow=2,mode=tfmm,cthresh=cthresh,blockx=blockx,blocky=blocky,MI=MI,metric=metric,micmatching=micmatching,pp=0,mChroma=mChroma,Chroma=Chroma) : 
246
\	  (precision==1 && usefm) ? blend ? debprep.srestore(omode="pp1") : i.tfm(slow=2,mode=tfmm,cthresh=cthresh,blockx=blockx,blocky=blocky,MI=MI,metric=metric,micmatching=micmatching,pp=pp,clip2=tfmcli2,mChroma=mChroma,Chroma=Chroma) : 
247
\	  (precision==2 && usefm) ? blend ? debprep.srestore(omode="pp2") : i.tfm(slow=2,mode=tfmm,cthresh=cthresh,blockx=blockx,blocky=blocky,MI=MI,metric=metric,micmatching=micmatching,pp=pp,clip2=tfmcli2,mChroma=mChroma,Chroma=Chroma) : 
248
\	  (precision==3 && usefm) ? blend ? debprep.srestore(omode="pp3") : i.tfm(slow=2,mode=tfmm,cthresh=cthresh,blockx=blockx,blocky=blocky,MI=MI,metric=metric,micmatching=micmatching,pp=pp,clip2=tfmcli2,mChroma=mChroma,Chroma=Chroma) : 
249
\	  (precision==4 && usefm) ? blend ? debprep.srestore(omode="pp3") : i.tfm(slow=2,mode=tfmm,cthresh=cthresh,blockx=blockx,blocky=blocky,MI=MI,metric=metric,micmatching=micmatching,pp=pp,clip2=tfmcli2,mChroma=mChroma,Chroma=Chroma) : 
250
\	  (precision==5 && usefm) ? blend ? debprep.srestore(omode="pp3") : i.tfm(slow=2,mode=tfmm,cthresh=cthresh,blockx=blockx,blocky=blocky,MI=MI,metric=metric,micmatching=micmatching,pp=pp,clip2=tfmcli2,mChroma=mChroma,Chroma=Chroma) : 
251
\	  (precision==6 && usefm) ? blend ? debprep.srestore(omode="pp3") : i.tfm(slow=2,mode=tfmm,cthresh=cthresh,blockx=blockx,blocky=blocky,MI=MI,metric=metric,micmatching=micmatching,pp=pp,clip2=tfmcli2,mChroma=mChroma,Chroma=Chroma) : 
252
\	  (precision==7 && usefm) ? blend ? debprep.srestore(omode="pp3") : i.tfm(slow=2,mode=tfmm,cthresh=cthresh,blockx=blockx,blocky=blocky,MI=MI,metric=metric,micmatching=micmatching,pp=pp,clip2=tfmcli2,mChroma=mChroma,Chroma=Chroma) : 
253
\	  (precision==8 && usefm) ? blend ? debprep.srestore(omode="pp3") : i.tfm(slow=2,mode=tfmm,cthresh=cthresh,blockx=blockx,blocky=blocky,MI=MI,metric=metric,micmatching=micmatching,pp=pp,clip2=tfmcli2,mChroma=mChroma,Chroma=Chroma) : 
254
\	  (precision==9 && usefm) ? blend ? debprep.srestore(omode="pp3") : i.tfm(slow=2,mode=tfmm,cthresh=cthresh,blockx=blockx,blocky=blocky,MI=MI,metric=metric,micmatching=micmatching,pp=pp,clip2=tfmcli2,mChroma=mChroma,Chroma=Chroma) : 
255
\	  nop()
256
257
autoAssuf ? eval("""
258
sourford = i.getparity() ? 1 : 0
259
global iyadifmc = eval("i.yadifmodclipin(nonyuy2)."+yadiffun+"(mode=3, edeint=edeint.yadifmodclipin(nonyuy2))").yadifmodclipout(nonyuy2)
260
261
global invfm = usefm ? autoAssuf ? i.Tfm(field=sourford==1 ? 0 : 1,slow=2,mode=tfmm,cthresh=cthresh,blockx=blockx,blocky=blocky,MI=defined(MI) ? Int(MI*5/4) : undefined,metric=metric,pp=precision==0 ? 0 : pp,clip2=tfmcli2,micmatching=0, mchroma=false,Chroma=Chroma) : nop() : nop()
262
fminv2       = usefm ? autoAssuf ? ScriptClip(Interleave(fm,fm), "
263
						invfv=Interleave(iyadifmc.DeleteFrame(0).SelectEven(),invfm).crop(16,16,-16,-16).cFrameDiff(prevf=true, chroma=false, denoise=true, nt=1)
264
						fv   =Interleave(iyadifmc.SelectEven(),                  fm).crop(16,16,-16,-16).cFrameDiff(prevf=true, chroma=false, denoise=true, nt=1)
265
						fv > 0.5 && invfv < 2 ? fv > invfv ? Interleave(invfm,invfm) : last : last
266
						").Selectodd() : fm : nop()
267
fm       = usefm ? autoAssuf ? conditionalfilter(fm.crop(16,16,-16,-16),fminv2,fm,"cFrameDiff(prevf=false, chroma=false, denoise=true, nt=1)","<","3") : fm : nop() 
268
""") : nop()
269
270
fm = usefm ? ifade ? fm.smartfademod(sfthr, sfshow, cache) : fm : nop()
271
272
#Field match + tfm.txt output for VFR clips (mode=4, pass=1)
273
274
global hybridfm=(usehfm && precision==0) ? i.tfm(slow=2,mode=tfmm,cthresh=cthresh,blockx=blockx,blocky=blocky,MI=MI, output="tfm.txt",metric=metric,micmatching=micmatching,pp=0,mChroma=mChroma,Chroma=Chroma) : 
275
\		(usehfm && precision==1) ? i.tfm(slow=2,mode=tfmm,cthresh=cthresh,blockx=blockx,blocky=blocky,MI=MI, output="tfm.txt",metric=metric,micmatching=micmatching,pp=pp,clip2=tfmcli2,mChroma=mChroma,Chroma=Chroma) : 
276
\		(usehfm && precision==2) ? i.tfm(slow=2,mode=tfmm,cthresh=cthresh,blockx=blockx,blocky=blocky,MI=MI, output="tfm.txt",metric=metric,micmatching=micmatching,pp=pp,clip2=tfmcli2,mChroma=mChroma,Chroma=Chroma) : 
277
\		(usehfm && precision==3) ? i.tfm(slow=2,mode=tfmm,cthresh=cthresh,blockx=blockx,blocky=blocky,MI=MI, output="tfm.txt",metric=metric,micmatching=micmatching,pp=pp,clip2=tfmcli2,mChroma=mChroma,Chroma=Chroma) : 
278
\		(usehfm && precision==4) ? i.tfm(slow=2,mode=tfmm,cthresh=cthresh,blockx=blockx,blocky=blocky,MI=MI, output="tfm.txt",metric=metric,micmatching=micmatching,pp=pp,clip2=tfmcli2,mChroma=mChroma,Chroma=Chroma) : 
279
\		(usehfm && precision==5) ? i.tfm(slow=2,mode=tfmm,cthresh=cthresh,blockx=blockx,blocky=blocky,MI=MI, output="tfm.txt",metric=metric,micmatching=micmatching,pp=pp,clip2=tfmcli2,mChroma=mChroma,Chroma=Chroma) : 
280
\		(usehfm && precision==6) ? i.tfm(slow=2,mode=tfmm,cthresh=cthresh,blockx=blockx,blocky=blocky,MI=MI, output="tfm.txt",metric=metric,micmatching=micmatching,pp=pp,clip2=tfmcli2,mChroma=mChroma,Chroma=Chroma) : 
281
\		(usehfm && precision==7) ? i.tfm(slow=2,mode=tfmm,cthresh=cthresh,blockx=blockx,blocky=blocky,MI=MI, output="tfm.txt",metric=metric,micmatching=micmatching,pp=pp,clip2=tfmcli2,mChroma=mChroma,Chroma=Chroma) : 
282
\		(usehfm && precision==8) ? i.tfm(slow=2,mode=tfmm,cthresh=cthresh,blockx=blockx,blocky=blocky,MI=MI, output="tfm.txt",metric=metric,micmatching=micmatching,pp=pp,clip2=tfmcli2,mChroma=mChroma,Chroma=Chroma) : 
283
\		(usehfm && precision==9) ? i.tfm(slow=2,mode=tfmm,cthresh=cthresh,blockx=blockx,blocky=blocky,MI=MI, output="tfm.txt",metric=metric,micmatching=micmatching,pp=pp,clip2=tfmcli2,mChroma=mChroma,Chroma=Chroma) : 
284
\		nop()
285
286
invhybridfm    = usehfm ? autoAssuf ? conditionalfilter(hybridfm.crop(16,16,-16,-16),i.Tfm(field=sourford==1 ? 0 : 1,slow=2,mode=tfmm,cthresh=cthresh,blockx=blockx,blocky=blocky,MI=defined(MI) ? Int(MI*5/4) : undefined,metric=metric,pp=precision==0 ? 0 : pp,clip2=tfmcli2,micmatching=0, mchroma=false,Chroma=Chroma),hybridfm,"IsCombedTIVTC(15,13,false,8,4,1)","=","true") : hybridfm : nop()
287
hybridfm       = usehfm ? autoAssuf ? conditionalfilter(blankclip(hybridfm,length=1).crop(16,16,-16,-16)+invhybridfm.crop(16,16,-16,-16),hybridfm,invhybridfm,"IsCombedTIVTC(10,7,false,4,4,0)","=","true") : hybridfm : nop()
288
289
hybridfm = usehfm ? ifade ? hybridfm.smartfademod(sfthr, sfshow, cache) : hybridfm : nop()
290
291
###############        ######################
292
#Field blended# MODE=2 #Double hard telecine# MODE=3
293
###############	       ######################
294
295
#Since during double chroma blend removal it was checked whether to use blendbob or clearbob depending on the source (blendbob was used for field blended and clearbob was used for double hard telecine), use chrbob when chrfix=true, else use the appropriate one
296
297
fbbob = mode==2 ? chrfix_b ? debprep : blendbob : nop()
298
299
dhtbob = mode==3 ? chrfix_b ? debprep : clearbob : nop()
300
301
################
302
#CFR decimation# OMODE=1
303
################
304
305
#HT decimation (mode=1), remove 3 frames out of 5 when chrfix=true since the clip has been bobbed to 60fps
306
fmdecim = mode==1 ? chrfix_b ? (palf && Ofrate==2) ? debprep.tdecimate(1,13,25) : (o3025cfr) ? debprep.tdecimate(1,3,6) : debprep.tdecimate(1,3,5) : (palf && Ofrate==2) ? fm.tdecimate(1,1,25) : (o3025cfr) ? fm : (autoAssuf) ? fm.tdecimate(1) : fm.tdecimate() : nop()
307
308
#Field blended blend removal & decimation (mode=2) No need to check for chrfix since it was done in the previous step
309
fbdecim = mode==2 ? mode22 ? chrfix_b ? fbbob.srestore(omode=2, mode=4, thresh=44, cache=cache*3/2, dclip=fbbob.crop(16,16,-16,-16)).srestore(frate=frate, mode=4, speed=-4, cache=cache) : 	fbbob.srestore(omode=2, mode=4, thresh=44, cache=cache*3/2, dclip=fbbob.crop(16,16,-16,-16)).srestore(frate=frate, mode=-4, speed=-4, cache=cache) 	:
310
\chrfix_b ? fbbob.srestore(frate=frate, cache=cache) : 	fbbob.srestore(frate=frate, cache=cache, dclip=i.bob(-0.2,0.6).nonyuy2clipin(nonyuy2).reduceflicker(strength=1).nonyuy2clipout(nonyuy2)) 	: nop()
311
312
#Pattern finding and decimation for double hard telecine (mode=3) No need to check for chrfix since it was done in the previous step
313
a= mode==3 && (pattern==1 || pattern==-1) ? palf && Ofrate==2 ? dhtbob.selectevery(4,0,2).tdecimate(1,1,25) : o3025cfr ? dhtbob.selectevery(4,0,2) : dhtbob.selectevery(5,0,3) : NOP()
314
b= mode==3 && (pattern==2 || pattern==-1) ? palf && Ofrate==2 ? dhtbob.selectevery(4,1,3).tdecimate(1,1,25) : o3025cfr ? dhtbob.selectevery(4,1,3) : dhtbob.selectevery(5,1,4) : NOP()
315
c= mode==3 && (pattern==3 || pattern==-1) ? palf && Ofrate==2 ? dhtbob.selectevery(4,0,1).tdecimate(1,1,25) : o3025cfr ? dhtbob.selectevery(4,0,1) : dhtbob.selectevery(5,0,2) : NOP()
316
d= mode==3 && (pattern==4 || pattern==-1) ? palf && Ofrate==2 ? dhtbob.selectevery(4,1,2).tdecimate(1,1,25) : o3025cfr ? dhtbob.selectevery(4,1,2) : dhtbob.selectevery(5,1,3) : NOP()
317
e= mode==3 && (pattern==5 || pattern==-1) ? palf && Ofrate==2 ? dhtbob.selectevery(4,2,3).tdecimate(1,1,25) : o3025cfr ? dhtbob.selectevery(4,2,3) : dhtbob.selectevery(5,2,4) : NOP()
318
dhtdecim = mode==3 ? 			pattern==-1 ? stackvertical(stackhorizontal(a.subtitle("pattern=1"),b.subtitle("pattern=2"),c.subtitle("pattern=3")),stackhorizontal(d.subtitle("pattern=4"),e.subtitle("pattern=5"),e.blackness())) : 
319
\					pattern==1 ? a : 
320
\					pattern==2 ? b : 
321
\					pattern==3 ? c : 
322
\					pattern==4 ? d : 
323
\					pattern==5 ? e : 
324
\ palf && Ofrate==2 ? tdecimate(1,13,25) : o3025cfr ? dhtbob.tdecimate(1,3,6) : dhtbob.tdecimate(1,3,5) : nop()
325
326
#Hybrid CFR blend decimation of 30p into 24p
327
blenddecim = (mode==4 && omode==1) ? chrfix_b ? (palf && Ofrate==2) ? debprep.tdecimate(1,13,25,hybrid=1) : o3025cfr ? debprep.tdecimate(1,3,6) : debprep.tdecimate(1,3,5,hybrid=1) : o3025cfr ? fm : (palf && Ofrate==2) ? fm.tdecimate(1,1,25,hybrid=1) : fm.tdecimate(hybrid=1) : nop()
328
329
#########
330
#Credits# CREDS=TRUE (USER SPECIFIES I1, I2, P1, P2, E1, E2 OR E3)
331
#########
332
333
#Interlaced : use the same smart-bobbed clip as before; we don't care if the background is blended or not since it is unrecoverable anyways (at least for now... see developments about using masking to isolate creds from background)
334
credbob = defined(i1) ? clearbob.selecteven() : nop()
335
336
#Progressive : Blend deinterlace the 24t background while doing minimal damage on the 30p credits
337
blendbg= defined(p1) ? real30p ? i : i.daa3() : nop()
338
339
###CFR conversion###
340
#######################
341
###Framerate conversion (recommended for static or low-motion backgrounds since it is prone artifacts... it reduces framerate/motion based on motion vectors)
342
343
####Convert the framerate of the interlaced credits
344
#Determine if usage of the following conversion is required
345
usemocompi = isclip(credconv) ? defined(i1) : defined(i1) && credconv=="mocomp"
346
347
#External pelclip on source with nnedi, if requested
348
upsi = 		nnedi3pel && usemocompi ? pel==2 ? credbob.nnedi3_rpow2(rfactor=2) : credbob.nnedi3_rpow2(rfactor=2).nnedi3_rpow2(rfactor=2) : nop()
349
350
#Prepare super clip for the interlaced credits
351
credbobsuper	= usemocompi ? 			credbob.	MSuper(pel=pel, levels=0) 					 : nop()
352
credbobupsuper	= usemocompi && nnedi3pel ? 	credbob.	MSuper(pel=pel, levels=0, pelclip=upsi) 			 : nop()
353
354
#Calculate vectors
355
bvi = 		usemocompi ? nnedi3pel ? 	credbobupsuper.	MAnalyse(isb = true,search=search, blksize=bs, overlap=overlap)  : 
356
\						credbobsuper.	MAnalyse(isb = true,search=search, blksize=bs, overlap=overlap)  : nop()
357
358
fvi = 		usemocompi ? nnedi3pel ? 	credbobupsuper.	MAnalyse(isb = false,search=search, blksize=bs, overlap=overlap) : 
359
\						credbobsuper.	MAnalyse(isb = false,search=search, blksize=bs, overlap=overlap) : nop()
360
361
#Apply framerate conversion
362
fpsconvi =  	usemocompi ? nnedi3pel ? 	credbob.	MFlowFps(credbobupsuper,bvi, fvi, tnum, tden) 			 : 
363
\						credbob.	MFlowFps(credbobsuper,  bvi, fvi, tnum, tden) 			 : nop()
364
365
###Convert the framerate of the progressive credits
366
#Determine if usage of the following conversion is required
367
usemocompp = isclip(credconv) ? defined(p1) : defined(p1) && credconv=="mocomp"
368
369
#External pelclip on source with nnedi, if requested
370
upsp = 		nnedi3pel && usemocompp ? pel==2 ? blendbg.nnedi3_rpow2(rfactor=2) : blendbg.nnedi3_rpow2(rfactor=2).nnedi3_rpow2(rfactor=2) : nop()
371
372
#Prepare super clip for the progressive credits
373
blendbgsuper	= usemocompp ?			blendbg.MSuper(pel=pel, levels=0) 						 : nop()
374
blendbgsuperup	= usemocompp && nnedi3pel ? 	blendbg.MSuper(pel=pel, levels=0, pelclip=upsp) 				 : nop()
375
376
#Calculate vectors
377
bvp = 		usemocompp ? nnedi3pel ? 	blendbgsuperup.	MAnalyse(isb = true,search=search, blksize=bs, overlap=overlap)  : 
378
\						blendbgsuper.	MAnalyse(isb = true,search=search, blksize=bs, overlap=overlap)  : nop()
379
380
fvp = 		usemocompp ? nnedi3pel ? 	blendbgsuperup.	MAnalyse(isb = false,search=search, blksize=bs, overlap=overlap) : 
381
\						blendbgsuper.	MAnalyse(isb = false,search=search, blksize=bs, overlap=overlap) : nop()
382
383
#Apply framerate conversion
384
fpsconvp = 	usemocompp ? nnedi3pel ?	blendbg.MFlowFps(blendbgsuperup,bvp, fvp, tnum, tden) 				 : 
385
\						blendbg.MFlowFps(blendbgsuper,  bvp, fvp, tnum, tden) 				 : nop()
386
387
#######################
388
###Blend 30p creds into 24t (ugly and fast, but can lead to less disturbing artifacts when you have a high motion background)
389
blendi = isclip(credconv) ? nop() : defined(i1) && credconv=="blend" ? o3025cfr ? credbob : credbob.convertfps(tnum,tden) : nop()
390
391
blendp = isclip(credconv) ? nop() : defined(p1) && credconv=="blend" ? o3025cfr ? blendbg : blendbg.convertfps(tnum,tden) : nop()
392
393
#######################
394
###Drop frames 30p creds into 24t (ugly and fast, will lead to stuttery motion)
395
drop_credconv = isclip(credconv) ? nop() : (credconv=="drop" && normconv) ? 1 : 0
396
397
assert(drop_credconv!=1, "Please choose another credconv. drop not compatible with normconv=true.")
398
399
dropi = isclip(credconv) ? nop() : defined(i1) && credconv=="drop" ? (mode!=4 && palf && Ofrate==2) ? credbob.tdecimate(1,1,25) : o3025cfr ? credbob : credbob.tdecimate(1) : nop()
400
401
dropp = isclip(credconv) ? nop() : defined(p1) && credconv=="drop" ? (mode!=4 && palf && Ofrate==2) ? blendbg.tdecimate(1,1,25) : o3025cfr ? blendbg : blendbg.tdecimate(1) : nop()
402
403
########
404
#SPLICE# CREDS=TRUE (USER SPECIFIES I1, I2, P1, P2, E1, E2 OR E3)
405
########
406
407
#Determine the "mix" mode (how the different sections (30i, 24t, 30p) are spliced together)
408
#Also check for user error when entering the frame numbers
409
410
mix22a17	= defined(e1) && defined(e2) && defined(e3) && defined(i1) && defined(p1)	? true : false
411
mix7 		= defined(e1) && defined(e2) && defined(e3) && defined(i1) && defined(i2)	? true : false
412
mix14 		= defined(e1) && defined(e2) && defined(e3) && defined(p1) && defined(p2)	? true : false
413
414
mix21a20a16a15 	= defined(e1) && defined(e2) && defined(i1) && defined(p1) && mix22a17==false	? true : false
415
mix6a3 		= defined(e1) && defined(e2) && defined(i1) && defined(i2) && mix7==false	? true : false
416
mix13a10	= defined(e1) && defined(e2) && defined(p1) && defined(p2) && mix14==false	? true : false
417
418
mix19a18	= defined(e1) && defined(p1) && defined(i1) && mix21a20a16a15==false	? true : false 
419
mix9 		= defined(e1) && defined(p1) && defined(p2) && mix13a10==false		? true : false
420
mix2 		= defined(e1) && defined(i1) && defined(i2) && mix6a3==false		? true : false
421
mix4 		= defined(e1) && defined(e2) && defined(i1) && mix21a20a16a15==false && mix6a3==false	? true : false
422
mix11 		= defined(e1) && defined(e2) && defined(p1) && mix21a20a16a15==false && mix13a10==false	? true : false
423
424
mix1a5 	= defined(e1) && defined(i1) && mix19a18==false && mix2==false && mix4==false		? true : false
425
mix8a12 = defined(e1) && defined(p1) && mix19a18==false && mix11==false && mix9==false		? true : false
426
427
428
#Getting the "mix" mode based on user input
429
mix = 0
430
mix = mix1a5 		&& i1<e1 		? 1 : mix
431
mix = mix2 		&& i1<e1<i2 		? 2 : mix
432
mix = mix6a3 		&& i1<e1<i2<e2 		? 3 : mix
433
mix = mix4 		&& e1<i1<e2 		? 4 : mix
434
mix = mix1a5 		&& e1<i1 		? 5 : mix
435
mix = mix6a3 		&& e1<i1<e2<i2 		? 6 : mix
436
mix = mix7 		&& e1<i1<e2<i2<e3 	? 7 : mix
437
mix = mix8a12 		&& p1<e1 		? 8 : mix
438
mix = mix9 		&& p1<e1<p2 		? 9 : mix
439
mix = mix13a10 		&& p1<e1<p2<e2 		? 10 : mix
440
mix = mix11 		&& e1<p1<e2 		? 11 : mix
441
mix = mix8a12 		&& e1<p1 		? 12 : mix
442
mix = mix13a10 		&& e1<p1<e2<p2 		? 13 : mix
443
mix = mix14 		&& e1<p1<e2<p2<e3 	? 14 : mix
444
mix = mix21a20a16a15 	&& e1<i1<e2<p1 		? 15 : mix
445
mix = mix21a20a16a15 	&& i1<e1<p1<e2 		? 16 : mix
446
mix = mix22a17 		&& e1<i1<e2<p1<e3 	? 17 : mix
447
mix = mix19a18 		&& i1<e1<p1 		? 18 : mix
448
mix = mix19a18 		&& p1<e1<i1 		? 19 : mix
449
mix = mix21a20a16a15 	&& e1<p1<e2<i1 		? 20 : mix
450
mix = mix21a20a16a15 	&& p1<e1<i1<e2 		? 21 : mix
451
mix = mix22a17 		&& e1<p1<e2<i1<e3 	? 22 : mix
452
mix = defined(i2) && defined(i1)==false ? 0 : mix
453
mix = defined(p2) && defined(p1)==false ? 0 : mix
454
mix = defined(e2) && defined(e1)==false ? 0 : mix
455
mix = defined(e3) && defined(e2)==false ? 0 : mix
456
mix = defined(e3) && defined(e1)==false ? 0 : mix
457
mix = defined(i1) && defined(e1)==false ? 0 : mix
458
mix = defined(p1) && defined(e1)==false ? 0 : mix
459
creds ? assert(mix!=0, "Mistake in entering i1, e1.... parameters. Please check.") : nop()
460
461
#Determine frame numbers based on mix mode and user input of i/p/e1/2/3
462
istart1=mix==1 || mix==2 || mix==3 || mix==16 || mix==18 					? 0 	: \
463
	mix==4 || mix==5 || mix==6 || mix==7 || mix==15 || mix==17 || mix==19 || mix==21  	? e1+1 	: \
464
	mix==20	|| mix==22									? e2+1  : nop()
465
466
istart2=mix==2 || mix==3 ? e1+1 : mix==6 || mix==7 ? e2+1 : nop()
467
468
pstart1=mix==8 || mix==9 || mix==10 || mix==19 || mix==21 					? 0 	: \
469
	mix==11 || mix==12 || mix==13 || mix==14 || mix==16 || mix==18 || mix==20 || mix==22  	? e1+1 	: \
470
	mix==15	|| mix==17									? e2+1  : nop()
471
472
pstart2=mix==9 || mix==10 ? e1+1 : mix==13 || mix==14 ? e2+1 : nop()
473
474
estart1=mix==4 || mix==5 || mix==6 || mix==7 || mix==11 || mix==12 || mix==13 || mix==14 || mix==15 || mix==17 || mix==20 || mix==22	? 0 	: \
475
	mix==1 || mix==2 || mix==3 || mix==16 || mix==18  										? i1+1 	: \
476
	mix==8 || mix==9 || mix==10 || mix==19 || mix==21										? p1+1  : nop()
477
478
estart2=mix==4 || mix==6 || mix==7 || mix==15 || mix==17 || mix==21  	? i1+1 	: \
479
	mix==3 								? i2+1  : \
480
	mix==11 || mix==13 || mix==14 || mix==16 || mix==20 || mix==22 	? p1+1 	: \
481
	mix==10								? p2+1  : nop()
482
483
estart3=mix==7 ? i2+1 : mix==14 ? p2+1 : mix==17 ? p1+1 : mix==22 ? i1+1 : nop()
484
485
maxfps = defined(i1) ? framerate(i) : defined(p1) ? framerate(i) : nop()
486
487
#Final 24fps ivtced clip and deinterlaced + framerate converted for CFR (omode=1)
488
tocfrfinalt = omode==1 ? (mode==1) ? fmdecim : (mode==2) ? fbdecim : (mode==3) ? dhtdecim : (mode==4 && omode==1) ? blenddecim : nop() : nop()
489
tocfrfinali = omode==1 && creds ? isclip(credconv) ? credconv : (credconv=="mocomp") ? o3025cfr ? credbob : fpsconvi : (credconv=="blend") ? blendi : credconv=="drop" ? dropi : nop() : nop()
490
tocfrfinalp = omode==1 && creds ? isclip(credconv) ? credconv : (credconv=="mocomp") ? o3025cfr ? blendbg : fpsconvp : (credconv=="blend") ? blendp : credconv=="drop" ? dropp : nop() : nop()
491
492
#Final 30fps clips (prepare for hybrid decimation, make everything 30fps) for hybrid use fm since it will be spliced (txt file will be useless) (used when creds=true)
493
tovfrfinalt = omode==2 && creds ? (mode==1) ? fm : (mode==2) ? !(Ofrate==2 && palf) || !normconv ? fbdecim : fbdecim.changefps(maxfps) : (mode==3) ? (o3025cfr && !(palf && Ofrate==2)) ? dhtdecim : dhtdecim.changefps(maxfps) : (mode==4 && omode==2) ? fm : nop() : nop()
494
tovfrfinali = omode==2 && creds ? credbob : nop()
495
tovfrfinalp = omode==2 && creds ? blendbg : nop()
496
497
#Final clip to splice
498
spliceprept = mix!=0 ? omode==1 ? tocfrfinalt : omode==2 ? tovfrfinalt : nop() : nop()
499
spliceprepi = mix!=0 ? omode==1 ? tocfrfinali : omode==2 ? tovfrfinali : nop() : nop()
500
spliceprepp = mix!=0 ? omode==1 ? tocfrfinalp : omode==2 ? tovfrfinalp : nop() : nop()
501
502
#######################
503
###Trim
504
#Factor to get the proper trim values after decimating
505
factor = omode==1 ? defined(i1) ? float(framerate(tocfrfinali)/framerate(i)) : defined(p1) ? float(framerate(tocfrfinalp)/framerate(i)) : nop() : nop()
506
507
et1 = 	defined(e1) ? omode==2 ? spliceprept.trim(estart1,e1) : spliceprept.trim(int(estart1*factor),int(e1*factor)) : nop()
508
et2 = 	defined(e2) ? omode==2 ? spliceprept.trim(estart2,e2) : spliceprept.trim(int(estart2*factor),int(e2*factor)) : nop()
509
et3 = 	defined(e3) ? omode==2 ? spliceprept.trim(estart3,e3) : spliceprept.trim(int(estart3*factor),int(e3*factor)) : nop()
510
511
ci1 = 	defined(i1) ? omode==2 ? spliceprepi.trim(istart1,i1) : spliceprepi.trim(int(istart1*factor),int(i1*factor)) : nop()
512
ci2 = 	defined(i2) ? omode==2 ? spliceprepi.trim(istart2,i2) : spliceprepi.trim(int(istart2*factor),int(i2*factor)) : nop()
513
514
#Prepare 30p sections for splicing
515
cp1 = 	defined(p1) ? omode==2 ? spliceprepp.trim(pstart1,p1) : spliceprepp.trim(int(pstart1*factor),int(p1*factor)) : nop()
516
cp2 = 	defined(p2) ? omode==2 ? spliceprepp.trim(pstart2,p2) : spliceprepp.trim(int(pstart2*factor),int(p2*factor)) : nop()
517
518
spliced=(mix==1) ? 	ci1 + 	et1 : \
519
	(mix==2) ? 	ci1 + 	et1 + 	ci2 : \
520
	(mix==3) ? 	ci1 + 	et1 + 	ci2 + 	et2 : \ 
521
	(mix==4) ? 	et1 + 	ci1 + 	et2 : \
522
	(mix==5) ? 	et1 + 	ci1 : \ 
523
	(mix==6) ? 	et1 + 	ci1 + 	et2 + 	ci2 : \
524
	(mix==7) ? 	et1 + 	ci1 + 	et2 + 	ci2 + 	et3 : \
525
	(mix==8) ? 	cp1 + 	et1 : \
526
	(mix==9) ? 	cp1 + 	et1 + 	cp2 : \
527
	(mix==10) ? 	cp1 + 	et1 + 	cp2 + 	et2 : \ 
528
	(mix==11) ? 	et1 + 	cp1 + 	et2 : \
529
	(mix==12) ? 	et1 + 	cp1 : \ 
530
	(mix==13) ? 	et1 + 	cp1 + 	et2 + 	cp2 : \
531
	(mix==14) ? 	et1 + 	cp1 + 	et2 + 	cp2 + 	et3 : \
532
	(mix==15) ? 	et1 + 	ci1 + 	et2 + 	cp1 : \
533
	(mix==16) ? 	ci1 + 	et1 + 	cp1 + 	et2 : \
534
	(mix==17) ?	et1 + 	ci1 + 	et2 + 	cp1 +	et3 : \
535
	(mix==18) ? 	ci1 + 	et1 + 	cp1 : \
536
	(mix==19) ? 	cp1 + 	et1 + 	ci1 : \ 
537
	(mix==20) ? 	et1 + 	cp1 + 	et2 + 	ci1 : \
538
	(mix==21) ? 	cp1 + 	et1 + 	ci1 + 	et2 : \
539
	(mix==22) ? 	et1 + 	cp1 + 	et2 + 	ci1 +	et3 : \
540
	NOP()
541
542
finalcfr =  omode==1 ? creds ? spliced : tocfrfinalt : nop()
543
tovfrdec1 = omode==2 ? creds ? spliced : chrfix_b ? debprep : hybridfm : nop()
544
tovfrdec2 = omode==2 ? rendering ? i : creds ? spliced : chrfix_b ? debprep : fm : nop()
545
546
finalvfr = 	omode==2 && pass==1 ? nvfr ? tovfrdec1.TDecimate(4, output="stats.txt",denoise=true,vidThresh=0.8,dupThresh=0.9,vidDetect=vidDetect) : tovfrdec1.TDecimate(4, output="stats.txt",vidDetect=vidDetect) :
547
\		omode==2 && pass==2 ? nvfr ? tovfrdec2.TDecimate(5,hybrid=2,tfmin=creds ? "" : "tfm.txt",input="stats.txt",mkvout="timecodes.txt",tcfv1=tcfv1,batch=true,vidThresh=0.4,dupThresh=0.6,vidDetect=vidDetect) : tovfrdec2.TDecimate(5,hybrid=2,tfmin=creds ? "" : "tfm.txt",input="stats.txt",mkvout="timecodes.txt",tcfv1=tcfv1,batch=true,vidDetect=vidDetect) : nop()
548
549
topp = omode==1 ? finalcfr : omode==2 ? finalvfr : nop()
550
551
#Kill combing depending on user settings
552
dec = 	killcomb==0 ? topp : 
553
\	killcomb==1 ? topp.vinverse() : 
554
\	killcomb==2 ? topp.vinverseD() : 
555
\	killcomb==3 ? topp.daa3() : 
556
\		interleave(	topp.		 subtitle("killcomb=0",align=9),
557
\				topp.vinverse(). subtitle("killcomb=1",align=9),
558
\				topp.vinverseD().subtitle("killcomb=2",align=9),
559
\				topp.daa3().subtitle("killcomb=3",align=9))
560
561
aaed = 	aa==0 ? dec : 
562
\	aa==1 ? dec.ediaa() : 
563
\	aa==2 ? dec.daa3() : 
564
\	aa==3 ? dec.maa() : 
565
\	aa==4 ? dec.sharpaamcmod(dark,thin,sharp,smooth,stabilize,tradius,aapel,aaov,aablk,aatype) : 
566
\			interleave(	dec.		subtitle("aa=0",align=9),
567
\					dec.ediaa().	subtitle("aa=1",align=9),
568
\					dec.daa3().	subtitle("aa=2",align=9),
569
\					dec.maa().	subtitle("aa=3",align=9),
570
\					dec.sharpaamcmod(dark,thin,sharp,smooth,stabilize,tradius,aapel,aaov,aablk,aatype).subtitle("aa=4",align=9))
571
572
return omode==2 && pass==1 ? finalvfr : aaed
573
}
574
575
576
function chroma_rep(clip sourceo, int "cache", float "thr")
577
{
578
###### parameters & other necessary vars ######
579
    cache   = default(cache,-1)
580
global  rep_thr = default(thr, 0.125)
581
582
583
avs26=!(VersionNumber() < 2.6)
584
nonyuy2=avs26 && sourceo.isyuy2()
585
586
source=nonyuy2 ? sourceo.nonyuy2clipin(true) : sourceo
587
588
###### source preparation & lut ######
589
global  out1    = source
590
global  out2    = mergechroma(source,mt_adddiff(source.trim(1,0),mt_makediff(source.trim(1,0),source.trim(2,0),y=1,u=3,v=3),y=1,u=3,v=3).blur(1))
591
592
593
###### initialise variables ######
594
global  alfr     = -100
595
596
597
###### evaluation call & output calculation ######
598
scriptclip( source, """
599
600
 ### preparation ###
601
        cfr = current_frame
602
        ajmp = alfr+1==cfr
603
        
604
    global  alfr = cfr
605
606
        al_v = LumaDifference(out1.trim(1,0),out1.trim(2,0))
607
        ac_v = ChromaUDifference(out1.trim(1,0),out1.trim(2,0)) + ChromaVDifference(out1.trim(1,0),out1.trim(2,0))
608
609
  ## luma value shifting ##
610
    l10 = ajmp ? l01 : al_v
611
global 		l01	= ajmp ? l12 : al_v
612
global 		l12	= al_v
613
  
614
  ## chroma value shifting ##
615
    c10 = ajmp ? c01 : ac_v
616
global 		c01 = ajmp ? c12 : ac_v
617
global 		c12 = ac_v
618
	
619
 ### condition ###
620
    change  = l12*2<l01 && c01*1.25<c12 && c01*l12/c12/l01<rep_thr
621
    chango  = l01*2<l10 && c10*1.25<c01 && c10*l01/c01/l10<rep_thr
622
    
623
    change ? out2 : chango ? out1.trim(1,0) : out1
624
625
""")
626
627
nonyuy2 ? nonyuy2clipout(true) : last
628
629
630
###### final decimation & caching ######
631
cache<0 ? last : last.RequestLinear(8, cache, 5, false, false)
632
633
return last
634
}
635
636
637
function chroma_rep2(clip sourceo, int "cache", float "thr")
638
{
639
###### parameters & other necessary vars ######
640
    cache   = default(cache,-1)
641
global  rep_thr = default(thr, 0.125)
642
643
644
avs26=!(VersionNumber() < 2.6)
645
nonyuy2=avs26 && sourceo.isyuy2()
646
647
source=nonyuy2 ? sourceo.nonyuy2clipin(true) : sourceo
648
649
###### source preparation & lut ######
650
global  out1    = source
651
global  out2    = mergechroma(source,mt_adddiff(source.trim(1,0),mt_makediff(source.trim(1,0),source.trim(2,0),y=1,u=3,v=3),y=1,u=3,v=3).blur(1))
652
653
654
###### initialise variables ######
655
global  alfr     = -100
656
657
658
###### evaluation call & output calculation ######
659
chrixout = scriptclip( source, """
660
661
 ### preparation ###
662
        cfr = current_frame
663
        ajmp = alfr+1==cfr
664
        
665
    global  alfr = cfr
666
667
        al_v = LumaDifference(out1,out1.trim(1,0))
668
        ac_v = ChromaUDifference(out1,out1.trim(1,0)) + ChromaVDifference(out1,out1.trim(1,0))
669
670
  ## luma value shifting ##
671
    l10 = ajmp ? l01 : al_v
672
global 		l01	= ajmp ? l12 : al_v
673
global 		l12	= al_v
674
  
675
  ## chroma value shifting ##
676
    c10 = ajmp ? c01 : ac_v
677
global 		c01 = ajmp ? c12 : ac_v
678
global 		c12 = ac_v
679
	
680
 ### condition ###
681
    change  = l12*2<l01 && c01*1.25<c12 && c01*l12/c12/l01<rep_thr
682
    chango  = l01*2<l10 && c10*1.25<c01 && c10*l01/c01/l10<rep_thr
683
    
684
    change ? out2 : chango ? out1.trim(1,0) : out1
685
686
""")
687
688
chrixout=nonyuy2 ? chrixout.nonyuy2clipout(true) : chrixout
689
690
691
###### final decimation & caching ######
692
chrixout2 = cache<0 ? sourceo.mergechroma(chrixout) : sourceo.mergechroma(chrixout).RequestLinear(8, cache, 5, false, false)
693
694
return chrixout2
695
}
696
697
698
#based on smartfade v0.2 by martino - Aimed at removing interlaced fades in anime. Uses luma difference between two fields as activation threshold.
699
#mod by thetoof : removed degrainmedian post-processing, 
700
#		changed how the fields are blended together (average of 2 nnedi interpolations + contra-sharpening to retain more detail) and 
701
#		added cache parameter to forward the setting of animeivtc to this function
702
#		renamed global parameter to something less general than "threshold"
703
704
function smartfademod(clip c, float "sfthr", bool "sfshow", int "cache") {
705
    
706
global sfthr	= default ( sfthr,  0.4 ) # Threshold for fade detection.
707
show		= default ( sfshow, false ) # Displays luma difference between fields without processing anything.
708
cache		= default ( cache,   10 ) # Cache the frames to help seeking and other functions requesting many frames
709
710
show ? scriptclip(c, "subtitle(string(abs(	  separatefields().selectodd().averageluma() \
711
            				- separatefields().selecteven().averageluma())))") : \
712
       scriptclip(c, "sep = separatefields() \
713
       avg = sep.selectodd().averageluma() - sep.selecteven().averageluma() \
714
       abs(avg) > sfthr ? interleave(sep.selecteven(),sep.selectodd()).weave().daa3() : last")
715
716
cache<0 ? last : last.RequestLinear(8, cache, 5, false, false)
717
718
    return last
719
720
}
721
722
#Suggested by Mystery Keeper in "Denoise of tv-anime" thread
723
function ediaa(clip a) {return a.EEDI2(field=1).TurnRight().EEDI2(field=1).TurnLeft().spline36resize(a.width,a.height,-0.5,-0.5)}
724
725
#Anti-aliasing with contra-sharpening by Didée
726
function daa(clip c) {
727
nn	= c.nnedi2(field=-2)
728
dbl   	= mt_average(selecteven(nn),selectodd(nn),U=3,V=3)
729
dblD 	= mt_makediff(c,dbl,U=3,V=3)
730
shrpD 	= mt_makediff(dbl,dbl.removegrain((width(c)>1100) ? 20 : 11),U=3,V=3)
731
DD 	= shrpD.repair(dblD,13)
732
return dbl.mt_adddiff(DD,U=3,V=3) }
733
734
#Anti-aliasing with edge masking by martino, mask using "sobel" taken from Kintaro's useless filterscripts and modded by thetoof for spline36
735
function maa(clip input, int "mask") {
736
mask = input.mt_edge("sobel",7,7,5,5).mt_inflate()
737
aa_clip=input.spline36Resize(width(input)*2,height(input)*2).TurnLeft().SangNom().TurnRight().SangNom().spline36Resize(width(input),height(input)).MergeChroma(input) 
738
return mt_merge(input,aa_clip,mask) }
739
740
#Developped in the "fine anime antialiasing thread"
741
function SharpAAMCmod(clip orig, float "dark", int "thin", int "sharp", int "smooth", bool "stabilize", int "tradius", int "aapel", int "aaov", int "aablk", string "aatype")
742
{
743
dark	= default ( dark,     0.2 ) # strokes darkening strength
744
thin	= default ( thin,      10 ) # Presharpening
745
sharp	= default ( sharp,    150 ) # Postsharpening
746
smooth	= default ( smooth,    -1 ) # Postsmoothing
747
stabilize= default ( stabilize,false ) # Use post stabilization with Motion Compensation
748
Tradius	= default ( Tradius,    2 ) # 2 = MDegrain2 / 3 = MDegrain3 
749
aapel	= default ( aapel,      1 ) # accuracy of the motion estimation (Value can only be 1, 2 or 4. 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 (better but slower).)
750
aaov	= default ( aaov,       (orig.width>1100) ? 8 : 4 ) # block overlap value (horizontal). Must be even and less than block size. (Higher = more precise & slower)
751
aablk	= default ( aablk,      (orig.width>1100) ? 16 : 8 ) # Size of a block (horizontal). It's either 4, 8 or 16 ( default is 8 ). Larger blocks are less sensitive to noise, are faster, but also less accurate.
752
aatype	= default ( aatype, "Sangnom" ) # Use Sangnom() or EEDI2() for anti-aliasing
753
754
w=width(orig)
755
h=height(orig)
756
m=mt_logic( orig.DEdgeMask(0,255,0,255,"5 10 5 0 0 0 -5 -10 -5", divisor=4,Y=3,U=3,V=3)
757
 \       ,orig.DEdgeMask(0,255,0,255,"5 0 -5 10 0 -10 5 0 -5", divisor=4,Y=3,U=3,V=3)
758
 \       ,"max").mt_lut("x 128 / 0.86 ^ 255 *")
759
preaa=(thin==0 && dark==0) ? orig : (thin==0) ? orig.Toon(dark) : (dark==0) ? orig.awarpsharp2(depth=thin) : orig.Toon(dark).awarpsharp2(depth=thin)
760
aa= (aatype=="Sangnom") ? preaa.spline36resize(w*2,h*2).TurnLeft().SangNom().TurnRight().SangNom().spline36resize(w,h) : (aatype=="EEDI2") ? preaa.ediaa() : blankclip(pixel_type="YV12").subtitle("Please use Sangnom or EEDI2 for aatype")
761
postsh=(sharp==0 && smooth==0) ? aa : aa.lsfmod(edgemode=1,strength=sharp,overshoot=1,soft=smooth)
762
merged=mt_merge(orig,postsh,m,Y=3,U=3,V=3)
763
764
sD=mt_makediff(orig,merged)
765
766
origsuper= orig.MSuper(pel=aapel)
767
sDsuper  = sD.  MSuper(pel=aapel, levels=1)
768
769
770
fv3 = tradius==3 ? origsuper.MAnalyse(isb=false,delta=3,overlap=aaov,blksize=aablk) : nop()
771
fv2 = tradius>=2 ? origsuper.MAnalyse(isb=false,delta=2,overlap=aaov,blksize=aablk) : nop()
772
fv1 = tradius>=1 ? origsuper.MAnalyse(isb=false,delta=1,overlap=aaov,blksize=aablk) : nop()
773
bv1 = tradius>=1 ? origsuper.MAnalyse(isb=true, delta=1,overlap=aaov,blksize=aablk) : nop()
774
bv2 = tradius>=2 ? origsuper.MAnalyse(isb=true, delta=2,overlap=aaov,blksize=aablk) : nop()
775
bv3 = tradius==3 ? origsuper.MAnalyse(isb=true, delta=3,overlap=aaov,blksize=aablk) : nop()
776
sDD = tradius==1 ? sD.MDegrain1(sDsuper,bv1,fv1) : tradius==2 ? sD.MDegrain2(sDsuper,bv1,fv1,bv2,fv2) : sD.MDegrain3(sDsuper,bv1,fv1,bv2,fv2,bv3,fv3)
777
778
reduc = 0.4
779
sDD = mt_lutxy(sD,sDD,"x 128 - abs y 128 - abs < x y ?").mergeluma(sDD,1.0-reduc)
780
781
return stabilize ? orig.mt_makediff(sDD,U=2,V=2) : merged
782
}
783
784
# Kill Combing Function from mcbob
785
function VinverseD(clip clp, float "sstr", int "amnt", int "uv")
786
{
787
uv   = default(uv,3)
788
sstr = default(sstr,2.7)
789
amnt = default(amnt,255)
790
uv2  = (uv==2) ? 1 : uv
791
STR  = string(sstr)
792
AMN  = string(amnt)
793
vblur  = clp.mt_convolution("1","50 99 50",U=uv,V=uv)
794
vblurD = mt_makediff(clp,vblur,U=uv2,V=uv2)
795
Vshrp  = mt_lutxy(vblur,vblur.mt_convolution("1","1 4 6 4 1",U=uv2,V=uv2),expr="x x y - "+STR+" * +",U=uv2,V=uv2)
796
VshrpD = mt_makediff(Vshrp,vblur,U=uv2,V=uv2)
797
VlimD  = mt_lutxy(VshrpD,VblurD,expr="x 128 - y 128 - * 0 < x 128 - abs y 128 - abs < x y ? 128 - 0.25 * 128 + x 128 - abs y 128 - abs < x y ? ?",U=uv2,V=uv2)
798
mt_adddiff(Vblur,VlimD,U=uv,V=uv)
799
(amnt>254) ? last : (amnt==0) ? clp : mt_lutxy(clp,last,expr="x "+AMN+" + y < x "+AMN+" + x "+AMN+" - y > x "+AMN+" - y ? ?",U=uv,V=uv) 
800
return(last)
801
}
802
803
804
function yadifmodclipin(clip i, bool "doyv16")
805
{
806
i.nonyuy2clipin(doyv16)
807
pointresize(width(),height()+8,0,-4,width(),height()+8.0001)
808
}
809
810
function yadifmodclipout(clip i, bool "doyuy2")
811
{
812
i.crop(0,4,-0,-4)
813
nonyuy2clipout(doyuy2)
814
}
815
816
function tmm2_ortmm1(clip clip, int "mode", int "order", int "field", int "length", int "mtype", int "ttype", int "mtqL", int "mthL", int "mtqC", int "mthC", int "nt", int "minthresh", int "maxthresh", int "cstr", int "opt")
817
{
818
avs26=!(VersionNumber() < 2.6)
819
nonyuy2=avs26 && clip.isyuy2()
820
avs26 ? clip.nonyuy2clipin(nonyuy2).tmm2(mode, order, field, length, mtype, ttype, mtqL, mthL, mtqC, mthC, nt, minthresh, maxthresh, cstr, opt).nonyuy2clipout(nonyuy2) : \
821
        clip.TMM(mode, order, field, length, mtype, ttype, mtqL, mthL, mtqC, mthC, nt, minthresh, maxthresh, cstr)
822
}
823
824
function nonyuy2clipin(clip i, bool "doyv16")
825
{
826
doyv16 ? Eval("try { i.PackedToPlanar() } catch(error_msg) { i.converttoyv16() }") : i
827
}
828
829
function nonyuy2clipout(clip i, bool "doyuy2")
830
{
831
doyuy2 ? Eval("try { i.PlanarToPacked() } catch(error_msg) { i.converttoyuy2() }") : i
832
}