forked from vadosnaprimer/TASEncodingPackage
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfunctions.avsi
More file actions
207 lines (187 loc) · 5.89 KB
/
functions.avsi
File metadata and controls
207 lines (187 loc) · 5.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# Multisegment AVI import via resizing
function AppendSegment(
\ clip sample,
\ string base,
\ int first_val,
\ int last_val,
\ string format,
\ string resizer,
\ bool hd,
\ string pix_type
\){
for (i = first_val, last_val) {
filename = base + string(i, format) + ".avi"
AviSource(filename, pixel_type=pix_type)
if (hd) {
Eval(resizer + """Resize(sample.width, sample.height)""")
} else {
scaler = float(sample.height) / float(last.height)
temp_width = float(last.width) * scaler
PointResize(int(temp_width), sample.height)
Lanczos4Resize(sample.width, sample.height)
}
if (i == first_val) {
result = last
} else {
result = result + last
}
}
return result
}
# Multisegment AVI import via letterboxing
function AppendSegmentLetterbox(
\ string base,
\ int first_val,
\ int last_val,
\ string format,
\ string pix_type
\){
biggest_width = 0
biggest_height = 0
for (i = first_val, last_val) {
filename = base + string(i, format) + ".avi"
AviSource(filename, pixel_type=pix_type)
biggest_width = biggest_width < last.width ? last.width : biggest_width
biggest_height = biggest_height < last.height ? last.height : biggest_height
}
for (i = first_val, last_val) {
filename = base + string(i, format) + ".avi"
AviSource(filename, pixel_type=pix_type)
xside = int(biggest_width - last.width) / 2
yside = int(biggest_height - last.height) / 2
AddBorders(xside, yside, xside, yside)
if (i == first_val) {
result = last
} else {
result = result + last
}
}
return result
}
# rounds an integer up or down to the nearest multiple of mod
function ForceModulo(
\ int number,
\ int mod,
\ bool up
\){
return (up \
? (int(number + mod - 1) / mod) * mod \
: int(number / mod) * mod)
}
function Remove(
\ clip c,
\ int start,
\ int end
\){
c
Trim(0, -start) + Trim(end, 0)
}
function Replace(
\ clip dest,
\ int start,
\ int end,
\ clip src
\){
Assert(start >= 0, "Replace: parameter 'start' is negative")
Assert( end >= 0, "Replace: parameter 'end' is negative")
p1 = dest.Trim(0, -start)
p2 = src.Trim(start, end)
p3 = dest.Trim(end + 1, 0)
p1 = (start == 0) ? dest.Trim(0, -1).DeleteFrame(0) : p1
p3 = ( end == 0) ? dest.Trim(0, -1).DeleteFrame(0) : p3
p1 + p2 + p3
return (dest.HasAudio) ? last.AudioDub(dest) : last
}
# HD encodes need big subtitle fonts, but AviSynth can't enlarge the halo.
# Here's the custom subtitle function by nanogyth
# It's slow, but we have subtitles for a limited time only
function ng_bighalo(
\ clip clp,
\ string text,
\ float "x",
\ float "y",
\ int "first_frame",
\ int "last_frame",
\ string "font",
\ float "size",
\ int "text_color",
\ int "halo_color",
\ int "align",
\ int "spc",
\ int "lsp",
\ float "font_width",
\ float "font_angle",
\ int "halo_radius",
\ string "mode",
\ string "halo",
\ string "shadow"
\){
#Version 16-17 2012/12/1
# - added circle_12 as default
# - reworked math to avoid bitwise functions that are only
# availible in experimental builds
#Version 15 2012/12/1
# - drop shadow added
# - halo_radius still works, but calculating the points of
# a hollow circle for halo is much faster
# - mode is depricated since memo-ing isn't as needed
first_frame = default(first_frame, 0)
last_frame = default( last_frame, first_frame + 299)
font = default( font, "Arial")
size = default( size, 112)
x = default( x, -1)
y = default( y, -1)
text_color = default( text_color, $00DDDDDD)
halo_color = default( halo_color, $80000000)
align = default( align, 5)
spc = default( spc, 0)
lsp = default( lsp, 0)
font_width = default( font_width, 0)
font_angle = default( font_angle, 0)
shadow = default( shadow, "")
w = clp.width
h = clp.height
###
###
##
#
#
#
#
#
#
#
#
#
# #
circle_12="0 0 "+\
"12 0 0 12 -12 0 0 -12 "+\
"1 12 2 12 3 11 4 11 5 11 6 10 7 10 8 9 "+\
"12 1 12 2 11 3 11 4 11 5 10 6 10 7 9 8 "+\
"-1 12 -2 12 -3 11 -4 11 -5 11 -6 10 -7 10 -8 9 "+\
"-12 1 -12 2 -11 3 -11 4 -11 5 -10 6 -10 7 -9 8 "+\
"-1 -12 -2 -12 -3 -11 -4 -11 -5 -11 -6 -10 -7 -10 -8 -9 "+\
"-12 -1 -12 -2 -11 -3 -11 -4 -11 -5 -10 -6 -10 -7 -9 -8 "+\
"1 -12 2 -12 3 -11 4 -11 5 -11 6 -10 7 -10 8 -9 "+\
"12 -1 12 -2 11 -3 11 -4 11 -5 10 -6 10 -7 9 -8 "
halo = (defined(halo_radius) && halo_radius != 0) ? mt_circle(halo_radius) : circle_12
invis = BlankClip(1, w, h, pixel_type="YV12")
tm = Subtitle(invis, text, x, y, 0, 0, font, size, $00FFFFFF,\
0, align, spc, lsp, font_width, font_angle, utf8=true)
text_mask = tm.mt_expand(mode="0 0 "+shadow, chroma="-128")
halo_mask = text_mask.mt_expand(mode=halo, chroma="-128")
h0 = halo_color%$01000000
h_color = (h0>=0) ? h0 : $01000000+h0
t0 = text_color%$01000000
t_color = (t0>=0) ? t0 : $01000000+t0
h_alpha = (halo_color>=0) ? 255-(halo_color/$01000000) : (-halo_color-1)/$01000000
t_alpha = (text_color>=0) ? 255-(text_color/$01000000) : (-text_color-1)/$01000000
lut_str = string(h_alpha)+ " x * 255 / " +string(t_alpha)+\
" " +string(h_alpha)+ " - y * 255 / +"
alpha_mask = mt_lutxy(halo_mask, text_mask, lut_str)
hc = BlankClip(1, w, h, color=h_color)
tc = Subtitle(hc, text, x, y, 0, 0, font, size, t_color,\
0, align, spc, lsp, font_width, font_angle, utf8=true)
overlay = tc.Mask(alpha_mask.ConvertToRGB32())
clp.ApplyRange(first_frame, last_frame, "Layer", overlay)
}