Log in

View Full Version : My first avisynth script out of bounds memory error


Umamio
19th August 2008, 17:36
Is there a way to output variables to screen without using subtitle? I am trying to debug my script and I am clearly making some logical errors that I can't find.

I have been asked to add an intro-logo animation to a collection of different videos
The videos come in a variety of frame sizes and aspect ratios
They can have stereo or 5.1 audio
The colourspace is either YV12 or RGB32
They can be short (requiring a trim of the intro logo) or feature length
They can be NTSC, PAL, Film, Super8 framerate

I am trying to create a single function that will take these variables into account and output the correctly scaled and cropped or bordered logo animation.

My script gives memory errors for certain source aspect ratios (<1.8 approximately) and appears to work above this (in Bordering Vs Cropping) but I think that is just dumb luck rather than correctness.

My code is a complete mess but any help at all would be much appreciated. I feel like I am making some massively basic mistake that I haven't noticed.

I also assume the script is called more than is strictly necessary. If there is a way to "flow" my code to optimise it in this way I would be grateful for any such information.

Function Logoise (clip c, int TruePixel, int SourcePixel)
{
# Source Logo Intro Animation Audio & Video
LogoV = DirectShowSource("C:\Compressionism\_Video\Source\Logos\Raindance TV Logo").ConvertToRGB32
AudioStereo = WavSource("C:\Compressionism\_Video\Source\Logos\RDTV-Logo-Feature-Stereo.wav")
Audio51 = DirectShowSource ("C:\Compressionism\_Video\Source\Logos\RDTV-Logo-Feature-51.ac3")

# Frame duration before which film is classified as "Short"
MaxShortFilmFrames = 53946
# Trim Intro Logo frame constants for short Film
TrimStart=124
TrimeEnd=201
# True Source Aspect Ratio, taking into account pixel shape
# e.g Anamorphic Wide: (720/576)*(1024/720)
# e.g Square Pixels: (720/404)*(1/1)
SourceAR = (c.width/c.height)*(TruePixel/SourcePixel)
LogoAR = (LogoV.width/LogoV.height)


Logo = (c.Audiochannels == 6) ? AudioDub(LogoV,Audio51) : AudioDub(LogoV,AudioStereo)
Logo = (c.Framecount<MaxShortFilmFrames) ? Logo.Trim(TrimStart,TrimeEnd) : Logo
Logo = (c.Framerate > 25)||(c.Framerate < 23) ? Logo.ChangeFPS(c.FramerateNumerator , c.FramerateDenominator, true).ResampleAudio(c.Audiorate) : Logo.AssumeFPS(c.FramerateNumerator , c.FramerateDenominator, true).ResampleAudio(c.Audiorate)
LogoCrop = Round(((Logo.Width)-((Logo.Height)*SourceAR))/2)
LogoBord = Round((((Logo.Height)*SourceAR)-(Logo.Width))/2)
Logo = (SourceAR < LogoAR) ? Logo.Crop(LogoCrop,0,-LogoCrop,0) : Logo.AddBorders(LogoBord,0,LogoBord,0)
Logo = Logo.Spline36Resize(c.width, c.height)
Logo = (c.IsYV12 ) ? Logo.ConvertToYV12 : Logo
return (Logo+c)
}

function SharedResize (clip v1)
{return v1.Spline36Resize(1024,472)}

v = DGDecode_mpeg2source("BonneAnnee.d2v",info=3).ColorMatrix(hints=true)
a = DirectShowSource("BonneAnnee T80 2_0ch 192Kbps DELAY 0ms.ac3")

Main = AudioDub(v,a).Crop(0,52,-2,-52).Trim(1,14666).SharedResize

Main.Logoise(1,1)

:thanks:

Gavino
19th August 2008, 18:32
My script gives memory errors for certain source aspect ratios (<1.8 approximately) and appears to work above this (in Bordering Vs Cropping) but I think that is just dumb luck rather than correctness.
...
Function Logoise (clip c, int TruePixel, int SourcePixel)
{...
SourceAR = (c.width/c.height)*(TruePixel/SourcePixel)
LogoAR = (LogoV.width/LogoV.height)
...
You need to force floating point divide, not integer. So...
SourceAR = (float(c.width)/c.height)*(float(TruePixel)/SourcePixel)
LogoAR = float(LogoV.width)/LogoV.height

Umamio
19th August 2008, 22:56
Thanks for the help Gavino!
This is my script now. In the end it's really just the basis for a general purpose Splicing function...
Maybe one already exists and I wasted my time. Oops.

function Logoise (clip c, int TruePixel, int SourcePixel)
{
# Source Logo Intro Animation Audio & Video
LogoV = DirectShowSource("Intro of power.avi").ConvertToRGB32
AudioStereo = DirectShowSource ("Demo Minimal Edit Man Tc0 L2 2ch 48 224 DELAY 0ms.mp2")
Audio51 = DirectShowSource ("Demo Minimal Edit Man Tc0 L2 6ch 48 224 DELAY 0ms.ac3")

# Frame duration before which film is classified as "Short"
MaxShortFilmFrames = 53946

# Trim Intro Logo frame constants for short Film
TrimStart=124
TrimEnd=201

# True Source Aspect Ratio, taking into account pixel shape
# e.g Anamorphic Wide: (720/576)*(1024/720)
# e.g Square Pixels: (720/404)*(1/1)
SourceAR = (float(c.width)/c.height)*(float(TruePixel)/SourcePixel)
#Logo Aspect Ratio (Assume Square Pixels Intro Logo)
LogoAR = float(LogoV.width)/LogoV.height
#Acceptable Logo Aspect Ratio error Percentage
ARerror = 3
#Acceptable Logo Speedup/Slowdown Percentage
SpeedMod = 5

# Match Audio Channels and Dub
Logo = (c.Audiochannels == 6) ? AudioDub(LogoV,Audio51) : AudioDub(LogoV,AudioStereo)
# Determine Intro Type (Short/Long) & Trim accordingly
Logo = (c.Framecount<MaxShortFilmFrames) ? Logo.Trim(TrimStart,TrimEnd) : Logo

# Match Framerate
#If framerate difference greater than acceptable; change fps (decimate duplicate), otherwise, speedup / slowdown logo to match film.
Logo = ( (c.FramerateNumerator == Logo.FramerateNumerator) && (c.FramerateDenominator == Logo.FramerateDenominator) ? Logo :
\ (c.Framerate > float(c.Framerate*(1+(SpeedMod/100)))) || (c.Framerate < float(c.Framerate*(1-(SpeedMod/100)))) ? Logo.ChangeFPS(c.FramerateNumerator , c.FramerateDenominator, true) : Logo.AssumeFPS(c.FramerateNumerator , c.FramerateDenominator, true))
#Match True Aspect Ratio
LogoModifier = Abs(Round((((Logo.Height)*SourceAR)-(Logo.Width))/2))
Logo = ( (SourceAR < float((1-(ARerror/100))*LogoAR)) ? Logo.Crop(LogoModifier,0,-LogoModifier,0) :
\ (SourceAR > float((1+(ARerror/100))*LogoAR)) ? Logo.AddBorders(LogoModifier,0,LogoModifier,0) : Logo)
#Match Frame Dimensions
Logo = Logo.Spline36Resize(c.width, c.height)
#Match Colourspace
Logo = ( (c.IsYV12) ? ConvertToYV12(Logo) :
\ (c.IsRGB24) ? ConvertToRGB24(Logo) :
\ (c.IsYUY2) ? ConvertToYUY2(Logo) :
\ (c.IsYUV) ? ConvertToYUV(Logo) :
\ (c.IsRGB) ? ConvertToRGB(Logo) : Logo)
#Match Sample Rate
Logo = (c.Audiorate == Logo.Audiorate) ? Logo : Logo.ResampleAudio(c.Audiorate)
#Match AudioBits
Logo = ( (c.Audiobits == Logo.Audiobits) ? Logo :
\ (c.Audiobits == 16) ? Logo.ConvertAudioTo16bit :
\ (c.Audiobits == 24) ?Logo.ConvertAudioTo24bit :
\ (c.Audiobits == 32) ?Logo.ConvertAudioTo32bit :
\ (c.Audiobits == 8) ?Logo.ConvertAudioTo8bit : Logo )


return Logo
}


:thanks: