# The downloadable / HD encoding script
# Rewritten and maintained by Brandon. Originally created by Flygon.
# Many great contributions come from Mister Epic and especially Grunt
# Super thanks to Aktan for the audio/video desync fixing algorithm!
# I send greets to JEEB and J_Darnley of FreeNode's (irc.freenode.net) #avisynth channel
# for assisting with the automatic detection of the branch name
# Thank you for using this script!
# The below filenames are the filenames of your logo, set one for handheld consoles and TV
# based consoles, be sure to keep the "" tags.
file = "logo.png"
# This sets the start time for the subtitles to start displaying, this is set as a frame
# number.
subff = 1595
# This controls how long the subtitles stay on the screen.
sublength = 300
# This is the delay for the second set of subtitles to come in.
# This is useful if it is more asthetically pleasing to delay the second set of subtitles.
# Do not set this lower than 1, otherwise the subtitles will overlap and look ugly.
subdelay = 1
# Below is the size for the subtitles, standard encodes use a size of 10.
subsize = 10
# Adjust the below items to adjust the subtitles.
# This is so that the movie will have the correct subtitles.
# All the required information will be on the movies submission page.
# Be sure to keep the "" tags everywhere, even when branch is blank (Making it "").
game = ""
branch = ""
author = ""
time = ""
rerecords = ""
# Below is the values for the left, center, or right positioning for the subtitles below
# in the script, modification shouldn't be attempted unless you know what you're doing.
positionleft = 7
positioncenter = 8
positionright = 9
# This sets the position of the subtitles in terms of direction, it can be left, right, or
# center.
# Set positionleft for left, set positioncenter for center, set positionright for right.
# Setting this to positioncenter is considered standard practice, other positions
# shouldn't be used unless it looks far better.
position = positioncenter
# This sets the y position for the subtitles, basically, how high or low they are up on
# the screen.
# The higher the number, the lower the subtitles.
ypos = 2
# Set this to true for HD encode resolutions.
hd = false
# Passes for downloadable/streaming encodes:
# 0: audio extraction / streaming (archive.org 512kb; AR correction);
# 1: DupMC (no AR correction);
# 2: DeDup (no AR correction).
pass = 1
# This setting adjusts the framerate for HD encodes when uploading to YouTube. This is to
# save space due to YouTube having a maximum framerate of 30 anyway. It is suggested to be
# at either 24 fps or 30fps for NTSC games (Depending on if they use alternating frame
# flicker or not).
# PAL games should generally be set to 30 fps, it can be set to 25 fps if there is no
# flickering, but it's difficult to notice the strobing effect in 30fps anyway.
hdframerate = 30
# Set this to true if this is a handheld console to disable aspect correction.
handheld = false
# This setting turns the audio/video desync fixer on and off according to true and false.
# The below should always be set to true, barring the unusual occasion that it actually
# desyncs the audio.
# This should only be needed for PCEngine dumps, but may be useful for other consoles.
desyncfixer = true
# THE BELOW CODE SHOULDN'T BE MODIFIED UNLESS YOU KNOW EXPLICITLY WHAT YOU ARE DOING!
sourcevideo = AVISource("movie.avi").ConvertToRGB24().Trim(0, 53561).ConvertToRGB24() # 197150
# This automatically fixes length based audio/video desync if it exists inside the encode
# (eg. Many PCEngine games).
num = sourcevideo.AudioLengthF * sourcevideo.FrameRateNumerator
denom = sourcevideo.FrameCount * sourcevideo.FrameRateDenominator
fixedaudiorate = Round(num / denom)
desyncfixer ? sourcevideo.AssumeSampleRate(fixedaudiorate) : 0
# High Definition.
factor = hd ? ((sourcevideo.height > 540) ? 1 : \
(sourcevideo.height > 270) ? 2 : \
(sourcevideo.height > 180) ? 3 : 4) \
: 1
b = sourcevideo.PointResize( \
sourcevideo.width * factor, sourcevideo.height * factor \
)
width= (b.width > b.height * 4 / 3) ? b.width : b.height * 4 / 3
width = (width % 4 == 1) ? width + 3 : \
(width % 4 == 2) ? width + 2 : \
(width % 4 == 3) ? width + 1 : width
height = (b.width > b.height * 4 / 3) ? b.width * 3 / 4 : b.height
height = (height % 4 == 1) ? height + 3 : \
(height % 4 == 2) ? height + 2 : \
(height % 4 == 3) ? height + 1 : height
c = handheld ? b : ( \
hd ? b.PointResize(width, height) : b.Lanczos4Resize(width, height) \
)
g = hd ? c.PointResize(c.width * 2, c.height * 2) \
: ((pass == 0) ? c : sourcevideo)
multi = g.height / 224
multi = (multi > (g.height / sourcevideo.height)) ? multi : (g.height / sourcevideo.height)
# Logo.
d = ImageSource( \
file=file, start=0, end=int((sourcevideo.FrameRate * 2) - 1), \
fps=sourcevideo.FrameRate \
).ConvertToRGB24().AssumeFPS( \
sourcevideo.FrameRateNumerator, sourcevideo.FrameRateDenominator \
)
e = BlankClip( \
d, audio_rate=sourcevideo.AudioRate, channels=sourcevideo.AudioChannels \
)
f = AudioDub(d, e).Lanczos4Resize(g.width, g.height)
last = f + g
# This is the first set of subtitles.
# This shouldn't be modified unless you know what you are doing
Subtitle( \
game + "\n" + ( \
(branch == "") ? "" : branch + "\n" \
) + "Played by " + author + "\nPlaying time: " + \
time + "\nRerecord count: " + rerecords, y=(ypos * multi), \
align=position, first_frame=subff, last_frame=(subff + sublength), \
size=subsize * multi, text_color=$15FFFFFF, halo_color=$00000000, lsp=1 \
)
# The below line is for calculating the frame number for the second subtitles to begin.
lastframenum=(subff + sublength)
# This is the second set of subtitles, do not modify unless absolutely necessary.
Subtitle( \
"This is a tool\nassisted recording.\nFor details, visit\n" + \
"http://TASVideos.org/", y=(ypos * multi), align=position, \
first_frame=(lastframenum + subdelay), last_frame=( \
lastframenum + subdelay + sublength), size=(subsize * multi \
), text_color=$15FFFFFF, halo_color=$00000000, lsp=1 \
)
# This activates the frame dropper for HD encodes.
# This depends on if the game simulates transperancy with alternating frame flicker.
# The frame dropper saves filesize without image loss, because YouTube caps at 30fps.
hd ? ChangeFPS(hdframerate) : 0
# Downloadable encodes need a resizing filter for the colourspace reduction.
# HD encodes need to be point resized to keep the colour information faithful.
ConvertToYV24(matrix="PC.601", chromaresample="point")
ConvertToYV12(matrix="PC.601", chromaresample=(hd ? "point" : "lanczos4"))
pass == 1 ? DupMC(log="dup.txt") : last
pass == 2 ? DeDup( \
threshold=0.00001, trigger2=100, show=false, dec=true, maxcopies=20, \
maxdrops=20, log="dup.txt", times="times.txt" \
) : last