Some stuff I have cobbled together either for a need or for fun because of a request.

Flicker & GFlicker
Shake (someday?) & GShake
Collection of time strings


This is a small, recursive function that will return the greatest common divisor or, as I was taught, the highest common factor.
function gcd(int x, int y)
	t = x%y
	x = y
	y = t
	return (y>0)?gcd(x,y):x


Here is something I wrote to make it slightly easier to check the size of black borders and/or other crap on a video frame. The first four integers cause a sort of "pre-crop" and should behave exactly like crop with regards to positive and negative integers. For example, if you set the crop(s) to be 95 you would have only 5 black pixels instead of 100. No sanity checking on this so it can cause some weird stuff to happen.
function CropView(clip c, int left, int top, int right, int bottom, int "box_size", int "scale")
	box_size = default(box_size, 16)
	scale = default(scale, 4)
	left_z = (right<=0) ? width(c)-box_size+right : right-box_size
	top_z = (bottom<=0) ? height(c)-box_size+bottom : bottom-box_size
	return StackVertical( StackHorizontal( c.Pointresize(box_size*scale, box_size*scale, left,   top,   box_size, box_size), \
			c.Pointresize(box_size*scale, box_size*scale, left_z, top,   right,    box_size) ), \
		StackHorizontal( c.Pointresize(box_size*scale, box_size*scale, left,   top_z, box_size, bottom), \
			c.Pointresize(box_size*scale, box_size*scale, left_z, top_z, right,    bottom) ) )


I'm sure you are familiar with the Info() filter. This will print (most of) the info of clip A onto clip B. Useful if A is too small or you don't want to be sticking Info()s everywhere. This requires the GRunT (run-time fixer) plugin by Gavino to fix/work-around some limitations. You can get it here: It currently lacks the CPU and pitch info but those are not interesting for the purpose of this.
function InfoAB(clip a, clip b)
	### Puts the info of clip a onto clip b ###
	### Requires the GRunT (run-time fixer) plugin ###
	placeholder_frame = Select( ceil(log(framecount(a))/log(10.0)),""," ","  ","   ","    ","     ","      ","       ","        ","         ","          ","           ","            ")
	placeholder_time = Select( ceil(log( int(framecount(a)/(framerate(a)*3600)) )/log(10.0)),"           ","           ","            ","             ","              ","               ")
	str_colourspace = (isYV12(a)) ? "YV12" : (isRGB32(a)) ? "RGB32" : (isRGB24(a)) ? "RGB24" : (isYUY2(a)) ? "YUY2" : "WTF" 
	str_fieldbased = (isfieldbased(a)) ? "YES" : "NO"
	str_parity = (getparity(a)) ? "Top Field First" : "Bottom Field First"
	str_audio_has = (hasaudio(a)) ? "YES" : "NO"
	str_audio_type = (isaudioint(a)) ? "Integer" : "Float"
	b.Subtitle("Frame: "+placeholder_frame+" of "+string(framecount(a)) \
		+"\nTime: "+placeholder_time+" of "+string(floor(framecount(a)/(framerate(a)*3600)), "%.0f") \
			+":"+string(floor(framecount(a)/(framerate(a)*60))%60, "%02.0f") \
			+":"+string(floor(framecount(a)/framerate(a))%60, "%02.0f") \
			+"."+string(floor((framecount(a)*1000)/framerate(a))%1000, "%03.0f") \
		+"\nColorspace: "+str_colourspace \
		+"\nWidth: "+string(width(a))+"px, Height: "+string(height(a))+"px" \
		+"\nFramerate: "+string(framerate(a), "%.4f")+" ("+string(frameratenumerator(a))+"/"+string(frameratedenominator(a))+")" \
		+"\nFieldbased: "+str_fieldbased \
		+"\nParity: "+str_parity \
		+"\nAudio: "+str_audio_has \
		+"\nAudio channels: "+string(audiochannels(a)) \
		+"\nSample type: "+str_audio_type+" "+string(audiobits(a))+" bit" \
		+"\nSample rate: "+string(audiorate(a)) \
		+"\nAudio length: "+string(audiolengthf(a), "%.0f")+" samples, "+string(floor(audiolengthf(a)/(audiorate(a)*3600)), "%.0f") \
			+":"+string(floor(audiolengthf(a)/(audiorate(a)*60))%60, "%02.0f") \
			+":"+string(floor(audiolengthf(a)/audiorate(a))%60, "%02.0f") \
			+"."+string(floor((audiolengthf(a)*1000)/audiorate(a))%1000, "%03.0f") \
	, font="Courier New", lsp=10)
	GScriptClip("""Subtitle("       "+string(current_frame, "%"+string(ceil(log(fc)/log(10.0)))+".0f") \
		+"\n      "+string(floor(current_frame/(fr*3600)), "%.0f") \
		+":"+string(floor(current_frame/(fr*60))%60, "%02.0f") \
		+":"+string(floor(current_frame/fr)%60, "%02.0f") \
		+"."+string(floor((current_frame*1000)/fr)%1000, "%03.0f"), font="Courier New", lsp=10)""" \
		, args="fc=framecount(a), fr=framerate(a)")
    return last

Flicker & GFlicker

Here is one I made when a request appeared on the doom9 forum ( for ways to ruin a video. This one produces a brightness flicker by randomly altering the gamma through Levels(). The GFlicker version requires GRunT. It is here because I like it and it is cleaner than the string concatenation.
function Flicker(clip c, float "flicker_scale")
	# More is less, that is the bigger this scale, the less the flicker.
	# Perhaps someone can offer the correct value for the random shift to that the min gamma is as dark as the max gamma is bright
	flicker_scale = default(flicker_scale, 100.0) * 10.0
	ScriptClip(c, "rand = 1.0 + float( rand(256)-64 ) / "+string(flicker_scale)+"
		Levels(0, rand, 255, 0, 255, coring=false)")""")
    return last
function GFlicker(clip c, float "flicker_scale")
	# Same as plain Flicker but requires GRunT
	flicker_scale = default(flicker_scale, 100.0) * 10.0
	ScriptClip(src, "rand = 1.0 + float( rand(256)-64 ) / flicker_scale
		Levels(0, rand, 255, 0, 255, coring=false)", args="flicker_scale")
    return last

Shake (someday?) & GShake

Here is another one to satisfy the previous request. A big thanks to Gavino for getting this working by using GRunT. And now for some explanation. The output is slightly zoomed-in otherwise black borders would be needed. The shift_fraction variable sets the maximum fraction of the image that it can move. 10 is one tenth, 20 is one twentieth, 100 is one one-hundredth. This means that the relative shaking on a 500px wide image is the same as on a 2000px wide image. It is relative in both x and y. The target_w and target_h vars should be self-explanatory. I added them because I was testing using a large still image and wanted a smaller preview. The temporal_variation string is there so you can alter the shaking in some way, not necessarily with time. You can ramp it up and/or down with a current_frame.
function GShake(clip src, int "shift_fraction", int "target_w", int "target_h", string "temporal_variation") {
	shift_fraction = default(shift_fraction, 50)
	target_w = default(target_w, width(src))
	target_h = default(target_h, height(src))
	temporal_variation = default(temporal_variation, "1.0")
	ScriptClip( BlankClip(src, width=target_w, height=target_h), "
		variation = Eval(temporal_variation)
		shift_x=float(rand(src_w/shift_fraction) - src_w/float(shift_fraction*2)) * variation
		shift_y=float(rand(src_h/shift_fraction) - src_h/float(shift_fraction*2)) * variation

		crop_left = src_w/float(shift_fraction*2) + shift_x
		crop_top  = src_h/float(shift_fraction*2) + shift_y

		crop_right  = -src_w/float(shift_fraction*2) + shift_x
		crop_bottom = -src_h/float(shift_fraction*2) + shift_y

		LanczosResize(src, target_w, target_h, crop_left, crop_top, crop_right, crop_bottom)
	", args="src, src_w=width(src), src_h=height(src), shift_fraction, target_w, target_h, temporal_variation")

Collection of time strings

Here is a collection of strings that represent time, either current position via ScriptClip() or length. The ones with current_frame in can only be used in a ScriptClip(). H is hours, M is minutes, S is seconds.
Shows the length formatted as H:MM:SS.millisecond
string(floor(framecount/(framerate*3600)), "%.0f") \
	+":"+string(floor(framecount/(framerate*60))%60, "%02.0f") \
	+":"+string(floor(framecount/framerate)%60, "%02.0f") \
	+"."+string(floor((framecount*1000)/framerate)%1000, "%03.0f")
Shows the current position formatted as H:MM:SS.millisecond
string(floor(current_frame/(framerate*3600)), "%.0f") \
	+":"+string(floor(current_frame/(framerate*60))%60, "%02.0f") \
	+":"+string(floor(current_frame/framerate)%60, "%02.0f") \
	+"."+string(floor((current_frame*1000)/framerate)%1000, "%03.0f")
And this was for some guy on IRC who wanted a timer with ' and " separators. Format M'SS"centisecond
string(floor(current_frame/(framerate*60.0)), "%02.0f") \
	+"'"+string(floor(current_frame/framerate)%60, "%02.0f") \
	+chr(34)+string(floor((current_frame*100.0)/framerate)%100, "%02.0f")


This is a short thing I wrote to automate the scaling and tiling of a background for my desktop. One 1280x1024 and one 1024x768 monitors. I often also use avisynth to cleanup an image, usually removing JPEG artifacts.
ar = float(width(image)) / float(height(image))
border_colour = $000000

(ar >= 5.0/4.0) ? LanczosResize(image, 1280, m4(height(image)*1280.0/width(image)) ) \
	: LanczosResize(image, m4(width(image)*1024.0/height(image)), 1024 )
AddBorders( (1280-width)/2, (1024-height)/2, (1280-width)/2, (1024-height)/2, border_colour )
left = last

(ar >= 4.0/3.0) ? LanczosResize(image, 1024, m4(height(image)*1024.0/width(image)) ) \
	: LanczosResize(image, m4(width(image)*768.0/height(image)), 768 )
AddBorders( (1024-width)/2, (768-height)/2, (1024-width)/2, (768-height)/2, border_colour )
right = last

StackHorizontal( left, right.AddBorders(0,0,0, 1024-height(right), border_colour) )