MeGUI/Aspect Ratio Signalling in AviSynth Scripts

MeGUI supports aspect ratio signalling in AviSynth scripts, which will allow MeGUI to read the aspect ratio you set in the script without you having to tell MeGUI. This is analogous to AR signalling in Matroska and MP4; however, since AviSynth works by emulating AVI files (which have no native support for AR signalling) a workaround is required.

Where to find the AR settings in MeGUI
MeGUI currently doesn't let you set the SAR -- you have to set the DAR. This setting is available from the video preview window in the main form.

Setting the DAR within an AviSynth script
You can add DAR signals directly to your Avisynth script with two specially-named globals: MeGUI_darx and MeGUI_dary. For example, you might have:

global MeGUI_darx = 4 global MeGUI_dary = 3 ...
 * 1) Set DAR in encoder to 4 : 3. The following lines are for automatic signalling
 * 1) other stuff which actually is the script

and MeGUI will interface with Avisynth to get the values of the variables. So you can even do something funky like

global MeGUI_darx = my_avs_func_x global MeGUI_dary = my_avs_func_y ...

to allow AviSynth to do some DAR calculations.

Some helper functions
Because cropping preserves SAR and resizing preserves DAR, it is useful to be able to use the most suitable one for any calculations you make. These AviSynth functions convert between SAR and DAR, and set the DAR so that MeGUI can read it out.

function getDAR(clip c, float SAR) {   return Float(c.width) * SAR / Float(c.height) }
 * 1) gets the DAR from the SAR

function getSAR(clip c, float DAR) {   return DAR * Float(c.height) / Float(c.width) }
 * 1) gets the SAR from the DAR

function setDAR(float DAR) {   global MeGUI_darx = Round(1000 * DAR) global MeGUI_dary = 1000 }
 * 1) sets the DAR

An example of using these functions in a script:

DGDecode_mpeg2source("input.d2v")
 * 1) input the video

DAR = 1.3672 # suppose we know the input is ITU 4:3
 * 1) set the DAR to the input's DAR

SAR = last.getSAR(DAR) crop( 10, 0, -10, -2)
 * 1) calculate the SAR, because that doesn't change when cropping

DAR = last.getDAR(SAR) LanczosResize(300,300)
 * 1) calculate the DAR, because that shouldn't be changed when resizing

setDAR(DAR)
 * 1) signal the DAR to MeGUI

return last
 * 1) ensure that we are actually returning a video