Skip to content

Commit d079895

Browse files
authored
Properly scale vertical encodes to 4K (#23)
Properly scale vertical encodes to 4K For vertical encodes, YouTube will not process them in 4K and instead in 1440p as the height is always fixed to 2160. This fixes it. Also takes into account the 3840 height limit for vertical encodes.
1 parent 258ad90 commit d079895

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

encode.avs

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -156,35 +156,40 @@ if (prescaleFactor > 1 && !hd) {
156156
# Aspect ratio correction for SD encodes
157157
# if dimensions are not multiples of 4, codecs freak out, so we enforce mod 4
158158
mod = 4
159-
hdHeight= 2160
160159
height = last.height.ForceModulo(mod, true)
161160
width = (ARCorrection \
162161
? height * wAspect / hAspect \
163162
: last.width) \
164163
.ForceModulo(mod, true)
165164

166-
# Remember SD frame size for subYpos HD tweaks
167-
wARC = width
168-
hARC = height
169-
170165
# Actually go HD if we need
171166
if (hd) {
172-
height = hdHeight
173-
}
174-
175-
width = (ARCorrection \
176-
? height * wAspect / hAspect \
177-
: height * last.width / last.height) \
178-
.ForceModulo(mod, true)
179-
hStretch= height / last.height
180-
181-
# YouTube has a 4K width limit of 3840
182-
if (hd && (width > 3840)) {
183-
width = 3840
184-
height = (ARCorrection \
185-
? width * hAspect / wAspect \
186-
: width * last.height / last.width) \
187-
.ForceModulo(mod, true)
167+
vertical = width < height
168+
169+
normalAspect = ARCorrection ? float(wAspect) / hAspect \
170+
: float(last.width) / last.height
171+
reverseAspect = ARCorrection ? float(hAspect) / wAspect \
172+
: float(last.height) / last.width
173+
174+
if (vertical) {
175+
temp = normalAspect
176+
normalAspect = reverseAspect
177+
reverseAspect = temp
178+
}
179+
180+
smallerSideCap = 2160
181+
biggerSideCap = 3840
182+
183+
smallerSideHD = smallerSideCap
184+
biggerSideHD = int(smallerSideHD * normalAspect).ForceModulo(mod, true)
185+
186+
if (biggerSideHD > biggerSideCap) {
187+
biggerSideHD = biggerSideCap
188+
smallerSideHD = int(biggerSideHD * reverseAspect).ForceModulo(mod, true)
189+
}
190+
191+
width = vertical ? smallerSideHD : biggerSideHD
192+
height = vertical ? biggerSideHD : smallerSideHD
188193
}
189194

190195
# Rescaling

0 commit comments

Comments
 (0)