Post subject: Script that can encode into both SD and HD encodes
Joined: 11/4/2007
Posts: 1772
Location: Australia, Victoria
So, hey, guys, I managed to kick the ass of the official website encoding scripts with one script. Two birds with one stone. And extra functionality. Thank Mister Epic, Aktan, Grunt, and I. See below.
#The SD and HD encoding script
#Created by Flygon
#Many great contributions come from Mister Epic and especially Grunt
#Super thanks to Aktan for the audio/video desync fixing algorithm!
#Thank you for using this script!

#This is the AVI movie source, change the filename if your source movie uses a different filename
a = AVISource("movie.avi").ConvertToRGB24()

#The below filenames are the filenames of your logo, set one for handheld consoles and TV based consoles, be sure to keep the "" tags
handheldlogo = "handheld.png"
consolelogo = "console.png"

#This sets the start time for the subtitles to start displaying, this is set as a frame number
subff = 1997

#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

#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
#Set istherebranch to true if the movie has an additional branch, otherwise, set it to false
#Be sure to keep the "" tags except for the isthereabranch flag
gametitle = "Super Example Bros."
isthereabranch = false
branchname = "Pyro Edition"
author = "Girlpyro"
time = "13:37.34"
rerecords = "80085"

#Below is the values for the left, center, or right positioning for the subtitles, DO NOT adjust unless you know what you're doing
#This is required for the next segment of this script to function
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 = 8

#Set this to false for SD encodes, set this to true for HD encodes
isthishd = false

#This setting adjust 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 = 24

#Set this to true if this is a handheld console to disable aspect correction
#This setting has no affect on the aspect of SD encodes, but is still needed to change the logo
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 !!!


#This automatically fixes length based audio/video desync if it exists inside the encode (eg. Many PCEngine games)
desyncfixer ? Eval("""
fixedaudioratefloat = (a.AudioLengthF * a.FrameRateNumerator) / (a.FrameCount * a.FrameRateDenominator)
fixedaudiorate = Floor(fixedaudioratefloat)
a.AssumeSampleRate(fixedaudiorate)
""") : Eval(""" 
""")

#High Definition
isthishd ? Eval("""
factor = (a.height > 540) ? 1 : \
         (a.height > 270) ? 2 : \
         (a.height > 180) ? 3 : 4
b = a.PointResize(a.width * factor, a.height * factor)

c = handheld ? b : ((b.width < b.height * 4 / 3) ? b.PointResize(b.height * 4 / 3, b.height) : b.PointResize(b.width, b.width * 3 / 4))
g = c.PointResize(c.width * 2, c.height * 2)

multi = (factor * 2)

#Standard Definition
""") : Eval("""
g = a.PointResize(a.width * 1, a.height * 1)
multi = 1
""")

#Logo stuffs
handheld ? Eval("""
d = ImageSource(file=handheldlogo, start=0, end=119, fps=a.FrameRate).ConvertToRGB24()
""") : Eval("""
d = ImageSource(file=consolelogo, start=0, end=119, fps=a.FrameRate).ConvertToRGB24()
""")
e = BlankClip(d, audio_rate=a.AudioRate, channels=a.AudioChannels)
f = AudioDub(d, e).Lanczos4Resize(g.width, g.height).AssumeFPS(a.FrameRateNumerator, a.FrameRateDenominator)
last = f + g

#This is the first set of subtitles, this shouldn't be modified unless you know what you are doing
isthereabranch ? Eval("""
Subtitle(gametitle + "\n" + branchname + "\nPlayed by " + author + "\nPlaying time: " + time + "\nRerecord count: " + rerecords, y=(ypos * multi), align=position, first_frame=subff, last_frame=(subff + 300), size=(10.0 * multi), text_color=$15FFFFFF, halo_color=$00000000, lsp=1)
""") : Eval("""
Subtitle(gametitle + "\nPlayed by " + author + "\nPlaying time: " + time + "\nRerecord count: " + rerecords, y=(ypos * multi), align=position, first_frame=subff, last_frame=(subff + 300), size=(10.0 * 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 + 300)

#This is the second set of subtitles, do not modify unless absolutely necessary
Subtitle("This is a tool\nassisted recording.\nFor details, visit\nhttp://TASVideos.org/", y=(ypos * multi), align=8, first_frame=(lastframenum + subdelay), last_frame=(lastframenum + subdelay + 300), size=(10.0 * 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
isthishd ? Eval("""
ChangeFPS(hdframerate)
""") : Eval(""" 
""")

#SD 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") 
isthishd ? Eval("""
ConvertToYV12(matrix="PC.601", chromaresample="point")
""") : Eval(""" 
ConvertToYV12(matrix="PC.601", chromaresample="lanczos4")
""")
return last
Basically... this is the most advanced and most usable AviSynth script usable for standard TASVideos encoding. ---- Old post below Exactly what it says on the tin. Set isthishd to true or false, depending on if you want HD. The subtitles are automatically adjusted, but you still need to change the y position and alignments, obviously. *code* We could use some people willing to test this script. I send massive greets to Grunt and Aktan! Without them, this script would be impossible for me to make!
Banned User
Joined: 8/30/2010
Posts: 500
Location: Argentina Bs. As.
Well, I'm one of the first to test this script Go
[18:51] <scrimpy> Oh, nothing [18:51] <mmarks> oh [18:51] <Nach> I think scrimpy is just jealous of you mmarks
Site Admin, Skilled player (1254)
Joined: 4/17/2010
Posts: 11475
Location: Lake Char­gogg­a­gogg­man­chaugg­a­gogg­chau­bun­a­gung­a­maugg
wow
#Set this to false for SD encodes, set this to true for HD encodes 
isthishd = false
#isthishd = true
just let them replace #.
#Set this to false for SD encodes, set this to true for HD encodes 
#isthishd = false
isthishd = true
Warning: When making decisions, I try to collect as much data as possible before actually deciding. I try to abstract away and see the principles behind real world events and people's opinions. I try to generalize them and turn into something clear and reusable. I hate depending on unpredictable and having to make lottery guesses. Any problem can be solved by systems thinking and acting.
Publisher
Joined: 4/23/2009
Posts: 1283
There is a mistake. The color conversions should be like this:
ConvertToYV24(matrix="PC.601", chromaresample="point")
ConvertToYV12(matrix="PC.601", chromaresample="lanczos4")
Joined: 11/4/2007
Posts: 1772
Location: Australia, Victoria
Updated with new script that accounts for handheld consoles! Massive greets are sent to Grunt! Also, thanks very much Aktan for the new algorithm! It looks far nicer!
Editor, Experienced player (860)
Joined: 8/12/2008
Posts: 845
Location: Québec, Canada
Wow, this seems very useful. I'll try it as soon as I can.
GabCM
He/Him
Joined: 5/5/2009
Posts: 901
Location: QC, Canada
Nice script Flygon! Here's a suggestion for you to make that easier. How about creating variables for the subtitles?
gamename = "Game name"
branchname = "Branch name"
time = "XX:XX:XX.XX"
authors = "name, name & name"
rerecords = "XXXX"
Subtitle(gamename + "\n" + branchname + "\nPlayed by " + authors + "\nPlaying time: " + time + "\nRerecord count: " + rerecords, y=(8 * multi), align=7, first_frame=subff, last_frame=(subff + 300), size=(13.0 * multi), text_color=$15FFFFFF, halo_color=$00000000, lsp=1) 
Subtitle("This is a tool\nassisted recording.\nFor details, visit\nhttp://TASVideos.org/", y=(8 * multi), align=7, first_frame=(subff + 301), last_frame=(subff + 601), size=(15.0 * multi), text_color=$15FFFFFF, halo_color=$00000000, lsp=1
And I may think of a workaround for those like me who uses animated logos.
Joined: 11/4/2007
Posts: 1772
Location: Australia, Victoria
Thank you for making encoding even easier, Mister Epic! I'll jack that in after I take a shower. The modifications don't work and AviSynth won't cooperate in getting them to work. This is one change that can't make it through.
GabCM
He/Him
Joined: 5/5/2009
Posts: 901
Location: QC, Canada
Flygon wrote:
The modifications don't work and AviSynth won't cooperate in getting them to work. This is one change that can't make it through.
What? That's what I usually do for my encodes! Let me check this closely, and I'll also check for a way to include a trigger that switches between animated or static logos. EDIT: That subtitles trick does work for me, you've probably done something wrong.
Joined: 8/5/2010
Posts: 1
why not just make it a function?
#the function name is ridiculous but i didnt know what to call it...

Function FlygonScript(clip c, bool "isthishd", bool "handheld", string "picture", \
string "gamename", string "branchname", string "time", string "authors", string "rerecords")
{
isthishd   = default(isthishd, false)
handheld   = default(handheld, false)
picture    = Default(picture,     "")
gamename   = default(gamename,    "")
branchname = default(branchname,  "")
time       = default(time,        "")
authors    = default(authors,     "")
rerecords  = default(rerecords,   "")

a=c.converttorgb24()

subff = 801 

#High Definition 
isthishd ? Eval(""" 
factor = (a.height > 540) ? 1 : \ 
         (a.height > 270) ? 2 : \ 
         (a.height > 180) ? 3 : 4 
b = a.PointResize(a.width * factor, a.height * factor) 

c = handheld ? b : ((b.width < b.height * 4 / 3) ? b.PointResize(b.height * 4 / 3, b.height) : b.PointResize(b.width, b.width * 3 / 4)) 
g = c.PointResize(c.width * 2, c.height * 2) 

multi = (factor * 2) 

#Standard Definition 
""") : Eval(""" 
g = a.PointResize(a.width * 1, a.height * 1) 
multi = 1 
""") 

handheld ? Eval(""" 
d = ImageSource(file=Picture, start=0, end=119, fps=a.FrameRate).ConvertToRGB24() 
""") : Eval(""" 
d = ImageSource(file=picture, start=0, end=119, fps=a.FrameRate).ConvertToRGB24() 
""") 
e = BlankClip(d, audio_rate=a.AudioRate, channels=a.AudioChannels) 
f = AudioDub(d, e).Lanczos4Resize(g.width, g.height).AssumeFPS(a.FrameRateNumerator, a.FrameRateDenominator) 
last = f + g 
#mister epics sub idea
Subtitle(gamename + "\n" + branchname + "\nPlayed by: " + authors + "\nPlaying time: " + time + "\nRerecord count: " + rerecords, \
y=(8 * multi), align=7, first_frame=subff, last_frame=(subff + 300), size=(13.0 * multi), text_color=$15FFFFFF, halo_color=$00000000, lsp=1) 
Subtitle("This is a tool\nassisted recording.\nFor details, visit\nhttp://TASVideos.org/", \
y=(8 * multi), align=7, first_frame=(subff + 301), last_frame=(subff + 601), size=(15.0 * multi), text_color=$15FFFFFF, halo_color=$00000000, lsp=1) 

isthishd ? Eval(""" 
ChangeFPS(30) 
""") : Eval(""" 
""") 

ConvertToYV24(matrix="PC.601", chromaresample="point") 
isthishd ? Eval(""" 
ConvertToYV12(matrix="PC.601", chromaresample="point") 
""") : Eval(""" 
ConvertToYV12(matrix="PC.601", chromaresample="lanczos4") 
""") 
return last
}
Save that as an avsi and put it in your avisynth plugin folder. then use it like this:
FlygonScript(false, false, "picture.png", "Game Name", "Branch Name", "time", "Player", "Rerecords")
Example video kinda Link to video
Joined: 7/13/2006
Posts: 61
This script works if your emulator is setup to output all of the lines it should. Videos should either be output at the full 240 line height or padded to 240 for an even resize to 480 less the aspect ratio get all out of whack. Also, imo, point resize looks better if you only resize to an even multiple of the original height and then use a bilinear resize down to the resolution you're going after. NES/SNES 240 to 720? PointResize to height of 960 and a BilinearResize to 720. NES/SNES 240 to 1080? PointResize to height of 1440 and a BilinearResize to 1080. The other thing that irks me, and this is on just about every single NES/SNES encode (not just Flygon's), is that the aspect ratio is off. NES/SNES video should be padded with 16 pixels on the left of the video and 11 pixels on the right of the video and then resized to whatever width you're shooting for. Again, preferably using point in an even way and then using a bilinear to get your final width. For reference I'm pulling pixel numbers for the nes/snes width from here http://wiki.nesdev.com/w/index.php/NTSC_video If you've ever captured video straight from an NES you'll see that the pulse pixel and bgcolor pixels are totally visible as seen here http://www.youtube.com/watch?v=UCkTZoDbnTw Different systems have different scanline breakdowns. NES/SNES is what I am most familiar with and if it helps us get more correct looking encodes I'm all for it. Take this all with a grain of salt if you're not all that concerned with the accuracy of the aspect ratio. Hope some of this information helps you guys out. PS @ Flygon: I appreciate the HD encodes you've been doing. You may want to start stowing away 60fps progressive encodes. 60fps at resolutions up to 720x480 are allowed in the standard Blu-Ray spec and 60fps encodes up to the full 1920x1080 are allowed in the Blu-Ray 3D spec. It doesn't necessarily have to be 3D content to take advantage of the frame rate improvements. Something tells me that YouTube and other sites won't be too far behind in supporting 60fps.
Joined: 11/4/2007
Posts: 1772
Location: Australia, Victoria
Ah hah! Another person that's taken note that the borders natural to video game consoles aren't emulated! Believe it, it actually bothers me a bit too! The reason we won't be resizing down to 1080 pixels vertically is because, well, YouTube actually already does that for us in the 1080p mode. It also ruins the Chroma Subsampling effect due to the fact that it wouldn't be a scaled integer... it's basically a your mileage may vary thing. If you want downscaled video, go 1080p... if you want downscaled video, go Original mode because Flash will downscale it anyway, unless you have a 2560*1440 monitor. :p The reasons the borders aren't used is because... well, you may want to ask people such as Grunt or adelikat about that, I don't really have any control on that scenario, but I get the feeling that they won't take well to adding the borders, sorry. As much as it is almost necessary for some games to avoid some unusual problems (Such as Shining Force II having a border to compensate for the Mega Drive's natural screen shifting to the left which is completely ignored by the encode, for the uninformed, the black border on the side is the same colour as an approximately 8 pixel border would be on the other side). Either way, this could either set an interesting precedent for encoding, or absolutely nothing will change whatsoever. Because of how conservative the staff are about not wanting to make almost every movie encode on the site invalidated, I presume the latter. We'll be uploading 60fps movies to YouTube again when the day comes, but for now, I predict that it will not be happening, particularly as there is serious performance concerns with computers decoding High Definition video at 60 frames per second, which is unsettlingly disappointing. For example, YouTubes current 3D movie support entirely relies on the two video streams being stacked side by side, something that won't change any time soon (Unless Google decides to continue being haphazard and schizophrenic). Either way, if TASVideos decides to start selling Blu-rays, we might be onto something. :3 @BIgGreen: Part of the reason I don't plan or want to make this a function is because I intend for this script to be as portable and easily modifiable as possible. Chucking stuff into the plugins folder and working from there isn't exactly the most trivial thing to do, particularly if maintainance could be required on it. I really love to maintain my work often, so... yeah.
Joined: 7/13/2006
Posts: 61
I don't know if I'd start uploading 60 fps to youtube right away. I'm pretty sure they just drop every other frame, which is annoying because you may end up with sprites that disappear. At least with AVISynth you have control over how it's converting down to 30 fps. I think it would be awesome to have the option in an emulator to have the pulse and bgcolor borders visible but I'm not aware of a single PC emulator in existence that has them viewable. I know some of the emulators available for consoles like the Xbox and Wii emulate and display the full bgcolor border. It would be a cool feature but if no one is willing to budge on putting the feature into emulators I think padding with black is just as effective. At least things look correct. You and I have different goals when encoding videos. I'm encoding to go to DVD or Blu-Ray for watching on my TV. You are encoding for web. BUT! Web and TV standards are slowly becoming one. This is a good thing!
Site Admin, Skilled player (1254)
Joined: 4/17/2010
Posts: 11475
Location: Lake Char­gogg­a­gogg­man­chaugg­a­gogg­chau­bun­a­gung­a­maugg
#Specify 'subff' as the first frame for your subtitles. It is better to set the first frame of the first level here.
Add that (or rephrase it) to the script. Some guys seem not getting it & keeping that subff the same all the time.
Warning: When making decisions, I try to collect as much data as possible before actually deciding. I try to abstract away and see the principles behind real world events and people's opinions. I try to generalize them and turn into something clear and reusable. I hate depending on unpredictable and having to make lottery guesses. Any problem can be solved by systems thinking and acting.
Joined: 11/4/2007
Posts: 1772
Location: Australia, Victoria
Updated the script wildly.
Banned User
Joined: 8/30/2010
Posts: 500
Location: Argentina Bs. As.
http://pastebin.com/HVHAHN9M I used subtitleex in 3D
[18:51] <scrimpy> Oh, nothing [18:51] <mmarks> oh [18:51] <Nach> I think scrimpy is just jealous of you mmarks
Joined: 11/4/2007
Posts: 1772
Location: Australia, Victoria
Uh... that's... just a specialized encoding script for HD movies. What exactly do you mean by 3D? Either way, I will never ever use plugins for any of my scripts. I intend for them to be as interoperable as possible and only limited by the AviSynth revision used. This also makes it easier to interpolate scripts between 32-bit and 64-bit versions of AviSynth.
sgrunt
He/Him
Emulator Coder, Former player
Joined: 10/28/2007
Posts: 1360
Location: The dark horror in the back of your mind
I'm going to advise people not to use this script for SD encodes in its current form. It is missing provisions for duplicate frame removal, which allows for a very significant reduction in file size.