Back Forum Reply New

AviSynth Useful Functions...

I don't know whether this will be an uneventful thread or a useful thread.  I was thinking back to all the little functions I use to manipulate strings and such, nothing to really do with any hard-core coding/deinterlacing or frame manipulation.  I think it would be cool for people to share their own certain scripts for string, colorspace, etc manipulation.  For example here are some of the scripts I use, some of which created:

Code:

function ColorSpace(clip a)
{ return \ (IsYUY2(a)==true)  ? quot;YUY2quot;  :  \ (IsYV12(a)==true)  ? quot;YV12quot;  :  \ (IsRGB24(a)==true) ? quot;RGB24quot; :  \ (IsRGB32(a)==true) ? quot;RGB32quot; :  \ (IsRGB(a)==true)   ? quot;RGBquot;   : quot;YUVquot;
}

function ConvertTo(clip a, string colorspace, bool quot;interlacedquot;)
{ inter=default(interlaced,false) colorspace=UCase(colorspace) return  \ (colorspace==quot;YUY2quot; ) ? a.ConvertToYUY2(interlaced=inter)  :  \ (colorspace==quot;YV12quot; ) ? a.ConvertToYV12(interlaced=inter)  :  \ (colorspace==quot;RGB24quot;) ? a.ConvertToRGB24(interlaced=inter) :  \ (colorspace==quot;RGB32quot;) ? a.ConvertToRGB32(interlaced=inter) :  \ (colorspace==quot;RGBquot;  ) ? a.ConvertToRGB(interlaced=inter)   : a
}

function TimeCode(clip a, string timecode, float quot;fpsquot;)
{ fps=default(fps,a.framerate) hours=round(int(Value(LeftStr(timecode,FindStr(timecode,quot;:quot;)-1)))*fps*60*60) timecode=RightStr(timecode,StrLen(timecode)-FindStr(timecode,quot;:quot;)) minutes=round(int(Value(LeftStr(timecode,FindStr(timecode,quot;:quot;)-1)))*fps*60) timecode=RightStr(timecode,StrLen(timecode)-FindStr(timecode,quot;:quot;)) seconds=round(int(Value(LeftStr(timecode,FindStr(timecode,quot;:quot;)-1)))*fps) timecode=RightStr(timecode,StrLen(timecode)-FindStr(timecode,quot;:quot;)) frames=int(Value(timecode)) return hours+minutes+seconds+frames
}

function FOrder(clip a)
{ return getparity(a) ? 1 : 0
}

function AddBlack(clip a, string quot;timequot;, int quot;framesquot;)
{ time=default(time,quot;00:00:01:00quot;) frames=default(frames,0) olength=(framesgt;0) ? frames : a.TimeCode(time) return (a.AddAudio()+BlankClip(pixel_type=a.ColorSpace, \ length=olength \,width=a.width,height=a.height,fps=a.framerate)).AddAudio()
}

function AddAudio(clip v1) { v2 = Blankclip() v1 = AudioDub(v1,v2) return v1
}

The TimeCode one I have found most useful, because I work a lot with Ulead Media Studio Pro and within there I can see the starting and ending point in H:M:S:f.  So it just makes sense to create a script which you can input those parameters and is converted to frame numbers.

ex.

Trim( TimeCode(quot;00:00:26:21quot;) , TimeCode(quot;00:00:33:11quot;) )
# gt;gt;gt; Same as Trim(800,1000) with 29.97fps video

Also I have found ColorSpace() useful to yield a string with the colorspace.  Then I can store that in a variable and convert back to the original colorspace using ConvertTo().

Also FOrder() to find the field order of a clip as well as AddAudio() to add audio (due to the fact that I use DV Type I and need audio in order to import the avs file).  I also created AddBlack(), so it will autodetect parameters for the input video file, instead of manually typing in the colorspace and width.

Just some quick scripts to start,
Josh
¥
Back Forum Reply New