# SimpleSlugUpscale v0.7h # # Simplifies the steps necessary to convert an interlaced, DV-size clip (4:3 or 16:9 at 720x480 or 720x576) # to a variety of progressive and interlaced, SD and HD output frame sizes. Any questions or comments, don't # hesitate to contact me: robert.martens@gmail.com or get me on Twitter @ItEndsWithTens # # Requirements # # TempGaussMC_beta2 (by default; others are supported) # MaskTools v2 # MVTools 2 # NNEDI2 # RemoveGrain & Repair 1.0 prerelease (mode 20, used by TGMCb2, only introduced in this version) # VerticalCleaner # # These can be found with a quick search online, or you can head to http://www.gyroshot.com/simpleslug.htm # to find copies I've hosted for the sake of convenience. Full source code is available for everything but # NNEDI2, which hasn't seen a public source release as of this writing. You can use whatever version of TGMC # you prefer, but if it's not beta2 you'll need to look elsewhere for the necessary plugins. # # # croptop min 0, max (source height / 4), default (source height / 8) # # Sets the position of the top of the crop rectangle used as the base for 16:9 generation. Change to reframe # video on the Y axis; default grabs a vertically centered 16:9 area. Must be even, since clip will be YV12. # # drate true or false, default false # # For progressive output, gives 60p for NTSC, 50p for PAL. No effect on interlaced output. Mutually exclusive # with shtrhack (see below for details). # # qual "low", "balance", or custom string, default "balance" # # Sets quality level by changing arguments passed into TGMC. Low quality isn't too bad for 480sq or 360sq # modes, and runs much faster than the others."Balance" is a compromise between speed and quality. A custom # string allows you to run whatever version of TGMC you like with whatever arguments you see fit. This string # begins after the underscore in the function name, so qual="alpha3()" will run that version of TGMC with its # defaults. The full gamut of options is too great to cover here, but if you want custom settings you know what # you're doing. Don't forget to surround your qual string with triple quotes if you define a custom EdiMode! # # resize default "BlackmanResize" # # Allows for change of scaling technique; argument must be name of resizer. Assuming a standard AviSynth # installation, see C:/Program Files/AviSynth 2.5/Docs/English/corefilters/resize.htm for possible values. # # shtrhack true or false, default false # # Throws an exception if both it and drate are true (an unnecessary combo, therefore probably an oversight by # the user), and has no effect on interlaced output, but for same rate progressive output false will simply # select every other frame of the bobbed stream coming from TGMC, while true will blend every pair of frames # together. The end result being that false gives you output that's 30p with a 1/60th shutter (NTSC) or 25p # with a 1/50th shutter (PAL), and true simulates the look of 30p with a 1/30th shutter (NTSC) or 25p with a # 1/25th shutter (PAL). It's a cheap hack, as per the name, so don't stake your reputation on its results. # # size default "DVfullp" # # Determines output size. 1080p modes are really pushing it with DV source, I don't recommend them unless # you're desperate. The method used to parse this variable provides some flexibility in how you type the # string, but I recommend choosing from the names I use in this table: # # name size interlaced? pillarbox # # 480sq 640x480 no none # 360sq 640x360 no none # DVfullp Same as input no none # DVwidep Same as input no none # DVwidei Same as input bottom field first none # 720p 1280x720 no none # 720pbox 1280x720 no black # 720pboxbg 1280x720 no motion # 1080isq 1920x1080 top field first none # 1080isqbox 1920x1080 top field first black # 1080isqboxbg 1920x1080 top field first motion # 1080psq 1920x1080 no none # 1080psqbox 1920x1080 no black # 1080psqboxbg 1920x1080 no motion # 1080iana 1440x1080 top field first none # 1080ianabox 1440x1080 top field first black # 1080ianaboxbg 1440x1080 top field first motion # 1080pana 1440x1080 no none # 1080panabox 1440x1080 no black # 1080panaboxbg 1440x1080 no motion # # widein true or false, default false # # Allows widescreen DV input. # # Changes # 0.7h - April 8, 2010 - Added 'widein' option for working with anamorphic DV input, changed syntax of resize # to use named arguments (allows Bicubic to work properly), corrected glaring error in # interlaced output processing (thanks to Gavino and 2Bdecided of Doom9 for setting me # straight with this), moved DV-size Assert to the top, where it belongs. # # 0.7g - April 6, 2010 - Major rewrite; new approach helps protect against attempts at NTSC<>PAL conversion, # which old script allowed but didn't do fully (handled frame size, not framerate). # List of sizes changed somewhat as appropriate, reworded some documentation and chose # new variable names to narrow script for readability (except shtrfix, which became # shtrhack to clarify how barebones an approach it is), cleaned up pillarbox function, # fixed drate/shtrhack Assert error message grammar, redesigned use of croptop and # cropheight (removing them from SimpleSlugPillars as a result), changed GaussResize in # pillarbox bg generation to target 320 by 180, then Bilinear Resize back up (provides # more severe blur, less distracting pillars), added outwidth and outheight to simplify # 'scaled' processing, moved check for valid 'size' to Assert, changed size default to # DVfullp, slightly tweaked qual to allow varying TGMC versions. # # 0.6 - 0.1 - See http://www.gyroshot.com/simpleslug.htm for changelog function SimpleSlugUpscale( clip orig, int "croptop", bool "drate", string "qual", string "resize", bool "shtrhack", \ string "size", bool "widein") { drate = Default(drate, false) qual = Default(qual, "balance") resize = Default(resize, "BlackmanResize") shtrhack = Default(shtrhack, false) size = Default(size, "DVfullp") widein = Default(widein, false) cropleft = FindStr(size,"DV") > 0 ? 0 : 8 croptop = size=="480sq"||size=="DVfullp"||widein==true ? 0 : Default(croptop, orig.Height() / 8) cropwidth = FindStr(size,"DV") > 0 ? 720 : 704 cropheight = FindStr(size,"480")>0||FindStr(size,"full")>0||widein==true ? orig.Height() : (orig.Height()/4) * 3 outwidth = size=="480sq" || size=="360sq" ? 640 : \ FindStr(size,"DV") > 0 ? 720 : \ FindStr(size,"720") > 0 ? 1280 : \ FindStr(size,"sq") > 0 ? 1920 : 1440 outheight = size=="480sq" ? 480 : \ size=="360sq" ? 360 : \ FindStr(size,"DV") > 0 ? orig.Height() : \ FindStr(size,"720") > 0 ? 720 : 1080 Assert(orig.Width()==720 && (orig.Height()==480 || orig.Height()==576), \ "SimpleSlugUpscale: Input must be DV size (720x480 or 720x576)!") Assert((StrLen(size)==5&&FindStr(size,"sq")>0)||FindStr(size,"DV")>0||FindStr(size,"720")>0||FindStr(size,"1080")>0, \ "SimpleSlugUpscale: Invalid 'size'!") Assert(!(drate==true && shtrhack==true), \ "SimpleSlugUpscale: No reason for both drate and shtrhack to be true! Please check your arguments.") Assert(croptop <= (orig.Height() / 4), "SimpleSlugUpscale: 'croptop' cannot exceed source height / 4!") Assert(croptop % 2 == 0, "SimpleSlugUpscale: 'croptop' must be even (to accommodate YV12 chroma)! ") TGMCargs = qual=="low" ? \ """beta2(1,1,0,0,0,0,EdiMode="bob",sharpness=0.0,Smode=0,SLmode=0,Sbb=0,SVthin=0.0)""" : \ qual=="balance" ? \ """beta2(1,1,3,0,0,0,EdiMode="NNEDI2",sharpness=1.0,Smode=1,SLmode=0,Sbb=0,SVthin=0.0)""" : \ qual bobbed = Eval("orig.ConvertToYV12(interlaced=true).TempGaussMC_" + TGMCargs) shtrclp = drate==true || (FindStr(size,"i")>0&&FindStr(size,"p")==0) ? bobbed : \ drate==false && shtrhack==true ? Merge(bobbed.SelectEven(),bobbed.SelectOdd()) : \ bobbed.SelectEven() scaled = FindStr(size,"box") > 0 ? shtrclp.SimpleSlugPillars(resize,size) : \ Eval("shtrclp." + resize + \ "(outwidth,outheight,src_left=cropleft,src_top=croptop,src_width=cropwidth,src_height=cropheight)") return FindStr(size,"1080i") > 0 ? scaled.AssumeTFF().SeparateFields().SelectEvery(4,0,3).Weave() : \ size=="DVwidei" ? scaled.AssumeBFF().SeparateFields().SelectEvery(4,0,3).Weave() : \ scaled } function SimpleSlugPillars(clip shtrclp, string "resize", string "size") { pheight = FindStr(size,"720") > 0 ? 720 : 1080 fwidth = FindStr(size,"720") > 0 ? 1280 : FindStr(size,"ana") > 0 ? 1440 : 1920 cwidth = FindStr(size,"720") > 0 ? 960 : FindStr(size,"ana") > 0 ? 1080 : 1440 pwidth = fwidth / 8 center = Eval("shtrclp." + resize + \ "(cwidth,pheight,src_left=8,src_top=0,src_width=704,src_height=shtrclp.Height())") bg = shtrclp.GaussResize(320,180,8,(shtrclp.Height()/8),704,((shtrclp.Height()/4)*3),p=1). \ BilinearResize(fwidth,pheight) return FindStr(size,"bg")==0 ? center.AddBorders(pwidth,0,pwidth,0) : \ StackHorizontal(bg.Crop(0,0,pwidth,pheight),center,bg.Crop(pwidth*7,0,pwidth,pheight)) }