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
[edit | edit source]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
[edit | edit source]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:
# Set DAR in encoder to 4 : 3. The following lines are for automatic signalling global MeGUI_darx = 4 global MeGUI_dary = 3 # 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
[edit | edit source]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.
# gets the DAR from the SAR function getDAR(clip c, float SAR) { return Float(c.width) * SAR / Float(c.height) } # gets the SAR from the DAR function getSAR(clip c, float DAR) { return DAR * Float(c.height) / Float(c.width) } # sets the DAR function setDAR(float DAR) { global MeGUI_darx = Round(1000 * DAR) global MeGUI_dary = 1000 }
An example of using these functions in a script:
# input the video DGDecode_mpeg2source("input.d2v") # set the DAR to the input's DAR DAR = 1.3672 # suppose we know the input is ITU 4:3 # calculate the SAR, because that doesn't change when cropping SAR = last.getSAR(DAR) crop( 10, 0, -10, -2) # calculate the DAR, because that shouldn't be changed when resizing DAR = last.getDAR(SAR) LanczosResize(300,300) # signal the DAR to MeGUI setDAR(DAR) # ensure that we are actually returning a video return last