SimpleSlugUpscale

An AviSynth scaling helper script, aimed at simplifying the process of converting one arbitrary input size and pixel aspect ratio to another. The only three vitally important things you must do to make it work as expected are:
For example, to scale a progressive, anamorphic input clip to square pixel 1080p output, use

     SimpleSlugUpscale(prog=true,widein=true,size="1080psq")

A somewhat more detailed introduction to SSU is present in the script itself. For more advanced usage, see the parameter descriptions below. Those unfamiliar with AviSynth are free to see what they can gain from this tutorial covering the use of this script: SD video to HD dimensions with AviSynth

Download

Prerequisites

     AviSynth 2.5.x (I've tested SSU as far back as 2.5.6)
     TempGaussMC_beta2 (by default; other versions, and other bob deinterlacers, are also supported)
          MaskTools v2 - source code included
          MVTools 2 - source code included
          NNEDI2 - no source provided, non GPL
          RemoveGrain & Repair - source code
          VerticalCleaner - source code included

Examples

     Click any thumbnail to see the full size image; please note these are merely samples of output sizes and shapes, not quality level. They're only JPEGs, after all.

SimpleSlugUpscale(outwidth=640,DARout=2.35)

SimpleSlugUpscale(size="720pboxbg")

SimpleSlugUpscale(widein=true,size="480sqbox")

SimpleSlugUpscale(prog=true,size="DVfullpPALbox",boxcolor=color_green,boxvideoDAR=2.35)

SimpleSlugUpscale(prog=true,size="DVwidepNTSCbox",boxcolor=color_red,boxshiftv=128)

SimpleSlugUpscale(size="360sqboxbg",boxvideoDAR=1.7/2.9,boxshifth=160)

SimpleSlugUpscale(outwidth=357,outheight=623,size="box",modw=1,modh=1,qual="LeakKernelBob(order=1)")


Usage

SimpleSlugUpscale(clip orig, bool "prog", bool "widein", float "PARin", bool "drate", bool "shtrhack", int "hshift", int "vshift", int "boxcolor", int "boxbgblur", string "qual", string "resize", string "ep0", string "ep1", string "size", float "outwidth", float "outheight", float "PARout", float "modw", float "modh", float "DARout", float "boxvideoDAR", int "boxshifth", int "boxshiftv")

orig
     Input material can be any size and any pixel aspect ratio, but interlaced footage must be in the proper colorspace for whichever bob deinterlacer you choose. By default, I use TempGaussMC, so you'll need to feed YV12 into SimpleSlug, either by the 'pixel_type' parameter of your source filter or by using ConvertToYV12(interlaced=true).

prog - bool, default false
     Lets you process progressive footage, bypassing the deinterlacing procedure.

widein - bool, default false
     Allows anamorphic widescreen input; only covers DV NTSC wide (40:33 PAR), DV PAL wide (118:81 PAR), and anamorphic 1080 HD (4:3 PAR). For other anamorphic input, leave this set to false and specify a custom pixel aspect with PARin.

PARin - float
     Sets pixel aspect ratio of input clip. Presets account for the most common types of input, but you can specify your own if you like. Enter the value as either a float or a formula (i.e. 1.333333 or 4.0/3.0).

drate - bool, default false
     For progressive output from interlaced input, this gives 60p for NTSC, 50p for PAL. No effect on interlaced output. Mutually exclusive with shtrhack.

shtrhack - bool, 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 deinterlacer's output, 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.

hshift, vshift - int, default 0
     With some combinations of output settings, input video will be cropped as necessary to fit the shape of the output frame. These two parameters let you reframe your video, if for example a subject's head has been cut off by the default position of the crop area. Please note that these act as offsets for said crop area, and are relative to 0. Use negative numbers to shift the video down and to the right, positive numbers to bring it up and left. Maximum is +/- (input width - cropwidth) / 2 for hshift, (input height - cropheight) / 2 for vshift; should you enter too large a value, an error message will pop up and present you with the maximum for your particular combination of input clip and output size.

boxcolor - int, default color_black
     Determines color of pillarbox or letterbox bars. See your AviSynth plugins directory for colors_rgb.avsi, which lists a series of global variables that correspond to commonly used colors. If you want a color not defined there, see the "Colors" section of the AviSynth documentation for more info on defining RGB values.

boxbgblur - float, 1.0 through 100.0, default 2.0
     For "bg" size options, sets blur for background video. Blur is achieved by GaussResize, this value sets 'p', so lower numbers blur more.

qual - string, "dumbbob", "low", "balance", or custom string, default "balance"
     Sets quality of deinterlacing. Any bob deinterlacer will work, but presets use TempGaussMC_beta2. "dumbbob" is the default for downconversions where the output height is 1.5 times or more smaller than the input height. "balance" is a compromise between speed and quality, and is default for everything else. "low" is another preset I've made available, and though the tendency toward aliasing makes me uncomfortable using it for anything by default, you may wish to try it out; it's noticeably faster than "balance", and the slight quality drop may be worth it for the extra speed.
     You can also enter a custom string here to run any bob deinterlacer you like with whatever arguments you see fit. The string must be the call to the deinterlacer function, so if, for example, you wanted to use LeakKernelBob, you would use qual="LeakKernelBob(order=1)". If you have a need to, you can also string multiple filters together here. qual="TempGaussMC_alpha3().Invert()", for example. How useful that will prove to most people, I'm not sure, but the option is there. The full gamut of possibilities 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 said string contains its own quotes!

resize - string, default "BlackmanResize" for upscaling in AviSynth 2.5.8, "Lanczos4Resize" for upscaling in earlier versions, "BilinearResize" for downscaling
     Allows for change of scaling technique; argument must be the name of the resizer. See the AviSynth manual for all possible values (Core filters->Geometric deformation filters->BilinearResize / etcetera).

ep0, ep1 - string
     These let you specify extra parameters for the resizer; b and c for Bicubic, taps for Blackman and Lanczos, and p for Gauss. You must type the entire assignment, mind you: ep0="b=0.0",ep1="c=1.0"

size - string, default "720p"
     Determines output size. Anything above 720p is really pushing it with DV source, I don't recommend larger frames 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:

          deint
               Same size and PAR as input
          480sq
               640x480, 1:1 PAR
          360sq
               640x360, 1:1 PAR
          DVfullpNTSC
               720x480, 10:11 PAR
          DVfulliNTSC
               720x480, 10:11 PAR, interlaced bottom field first
          DVfullpPAL
               720x576, 59:54 PAR
          DVfulliPAL
               720x576, 59:54 PAR, interlaced bottom field first
          DVwidepNTSC
               720x480, 40:33 PAR
          DVwideiNTSC
               720x480, 40:33 PAR, interlaced bottom field first
          DVwidepPAL
               720x576, 118:81 PAR
          DVwideiPAL
               720x576, 118:81 PAR, interlaced bottom field first
          720p
               1280x720, 1:1 PAR
          1080psq
               1920x1080, 1:1 PAR
          1080isq
               1920x1080, 1:1 PAR, interlaced top field first
          1080pana
               1440x1080, 4:3 PAR
          1080iana
               1440x1080, 4:3 PAR, interlaced top field first

Add "box" or "boxbg" to the end of any name to trigger pillar or letterboxed output; the entire area of the input frame will be retained and padded either horizontally or vertically to fit the shape of the output. Box will simply use a solid color, set by 'boxcolor', while bg will use a cropped, blurred version of the input, whose blur can be adjusted with 'boxbgblur'.

outwidth, outheight - float
     If you desire a custom output frame size, use these parameters to set it. Odd values can be used only with RGB video. Output dimensions in all cases, preset or custom, will be rounded to the closest multiple of 8 that's less than or equal to the desired dimension. If you have RGB video, and you want to use an odd number for one of the axes, you'll need to set 'modw' or 'modh' (or both) as appropriate. See below for details.

PARout - float
     Sets pixel aspect for output. Uses the same presets as PARin, so if you want a custom output PAR, use this to define it.

modw, modh - float, default 1.0 for size "deint", modw 16.0 and modh 8.0 for "360sq" and all 1080 'size' presets, 16.0 for both otherwise
     Allows for easier codec-friendly output sizing. All output dimensions respect this, so frame size and box edges all land on multiples of modw and modh. The resulting aspect ratios will therefore be slightly different than what you ask for, but they'll be close enough that you likely won't notice. Hopefully the improvement in compression efficiency will make up for that. Of course, you can change these values as you see fit, so if you know what you're doing go right ahead.

DARout - float, default same as input unless custom outwidth and outheight are both requested
     If you want a custom output display aspect, define it here. For example, if you want output that's 640 pixels wide, and has a display aspect of 2.35, but you don't know the vertical dimension, use DARout=2.35 along with outwidth=640 to have SimpleSlug auto-calculate an appropriate height.

boxvideoDAR - float, default same as input DAR
     Only for "box" and "boxbg" sizes, this lets you set the display aspect of the video frame as distinct from the display aspect of the overall frame. By default the entire area of the input clip is retained, and simply padded to match the desired output DAR. If you want your input cropped to a certain aspect, however, you can define it here.

boxshifth, boxshiftv - int, default 0
     In addition to shifting the crop area with hshift and vshift, you can slide your video frame up and down (for letterboxed output) or left and right (for pillarboxed output) within the output frame. Maximum values for the given combination of input and output will be presented in an error message should you exceed them.

Changes

     0.9 - July 20th, 2010 - Added DARout parameter, and associated logic, to allow auto generation of custom output dimensions when only some information is known, added boxvideoDAR to let users change shape of center section in "box" or "boxbg" modes, added boxshifth and boxshiftv for shifting center frame up and down or back and forth within overall frame, changed modw default to 16.0, changed modh default to 8.0 for "360sq" and all 1080 presets, 16.0 for everything else, simplified qual logic, redesigned resize condition to allow for older versions of AviSynth, removed two Asserts (unnecessary since hshift and vshift are silently rounded to mod 4 and 2, respectively), removed final BilinearResize in Box function as new design generates proper sizes without it, changed boxbgblur to float, wrapped outwidth, outheight, modw and modh in Float function (not strictly required, but I feel safer explicitly casting my variables), changed Round for outwidth, outheight, ctrwidth, and ctrheight to Ceil to allow mod values greater than the requested output dimension to function correctly, changed gausswidth in Box function to derive from outwidth instead of inwidthf, removed unnecessary Round of outwidth and outheight after crop argument calculation in main function, removed redundant "return" statement for both functions, passed inwidthf and inheightf straight into Box function from main instead of recalculating them, removed several unnecessary order-of-operations parentheses throughout script, added extra conditions to 'outwidth' check to improve reliability.

     0.8 - May 10th, 2010 - Redesigned script to allow arbitrary frame sizes and pixel aspect ratios for both input and output, restructured deinterlacing process to allow the use of any bob deinterlacer available for AviSynth, added 'prog' parameter to allow progressive input to bypass colorspace conversion and deinterlacing, rebuilt pillarbox function to handle both pillar and letter boxes, added 'ep0' and 'ep1' to allow extra parameters for whichever resizer is used, added 'PARin' and 'PARout' to facilitate use of custom pixel aspect ratios, removed 'croptop' parameter and replaced its functionality with 'vshift', also added 'hshift' to control horizontal offset of video for certain conversions, added 'boxcolor' to let user define color of letterbox/pillarbox, added 'boxbgblur' for control over amount of blur used when generating background video for "boxbg" sizes, added "dumbbob" qual preset, rewrote error handling for excessive 'vshift' and 'hshift' values (maximum values are now calculated automatically and presented to the user in the error message), removed colorspace conversion from script, reinstated 'size' default of "720p", resored some TGMC defaults for "balance" 'qual' setting.

     0.7h - April 8th, 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 6th, 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 - April 1st, 2010 - Put 'croptop' and 'cropheight' in alphabetical order for input to SimpleSlugPillars, allowed custom TGMC arguments, reintroduced "balance" qual option, eliminated "TGMCdefault", changed cropheight calc to remove data type conversions.

     0.5 - March 21st, 2010 - Slightly simplified Assert for bad 'croptop' value, provided safer fallback for bad 'qual', changed default() calls to use capital Ds (AviSynth isn't case sensitive, but things like that still bother me), added 'resizer' var to allow for different scaling, rejiggered "bobbed" variable and removed "balance" qual option, making it the default.

     0.4b - March 13th, 2010 - Exposed croptop parameter to function interface (requested by mj.cj), recognized unnecessarily complex equation for auto calculation of same, realized I don't understand software version numbering, renamed last version.

     0.4a - March 12th, 2010 - Fixed crop dimensions to produce more accurate aspect ratios, eliminated cropargs variable, changed syntax of some lines to clean up script's presentation, changed quintuple Blur to one GaussResize for "boxbg" pillar generation, added croptop and cropheight variables, eliminated base variable, revised size table in comments, removed interlacing checks from shtrclp variable, swapped default value of shtrfix, reworded fallback subtitle for invalid 'size' setting.

     0.3 - March 9th, 2010 - Reworked background generation for "boxbg" modes, no more need for VariableBlur and the associated FFTW3.

     0.2 - March 4th, 2010 - Added 1440 modes (thanks to Per Magne Handegård for the reminder), renamed existing 1080 options to better reflect their output, cleaned up some unnecessary checks.

     0.1 - March 1st, 2010 - Initial release