Ich hoffe das hier ist der richtige Bereich eine von mir erstellte Funktion vorzustellen.
Ich wollte einen Timer haben und die bei AviSynth mitgelieferte Funktion ShowTime() war mir nicht umfangreich genug, da hab ich mir was passendes zusammen gescriptet.
Das Ganze enthält zwei Funktionen, timer() und timer_cut().
timer() blendet einen Timer ein und hat folgende Optionen:
mode - der Modus, ob mit oder ohne Stunden, Millisekunden, etc:
hmmss: 0:04:17
mmss: 04:17
mss: 4:17
mssms1: 4:17.3
mssms2: 4:17.37
mssms3: 4:17.375
mssms: 4:17.375
mmssms1: 04:17.3
mmssms2: 04:17.37
mmssms3: 04:17.375
mmssms: 04:17.375
hmmssms1: 0:04:17.3
hmmssms2: 0:04:17.37
hmmssms3: 0:04:17.375
hmmssms: 0:04:17.375
reverse - Lässt den Timer rückwärts laufen.
color - Farbe (Standart weiß)
size - Schriftgröße
x, y - Position des Timers.
align - Timer-Position relativ zu x, y
timer_cut() blendet den Timer zwischen Frame a und Frame b ein. Die Optionen sind dieselben wie bei timer(), plus folgender zusätzlicher:
start, end - Start- und Endframe für den Timer.
showstart, showend - Wenn beide true gesetzt sind, wird der Timer die ganze Zeit eingeblendet, startet bei Frame a und friert bei Frame b ein. Man kann auch nur den Anfang oder das Ende einblenden.
Beispiele:
Code:colorbars().trim(0,3000) import("timer.avs") #timer() #timer(mode="mssms1",color=color_green,size=66.6) timer_cut(mode="mss",start=500,end=2500,showstart=true,showend=false,size=99.9,x=150,y=200)Code:blankclip(length=15001,width=320,height=120,fps=1000) import("timer.avs") timer(mode="mssms3",size=85,y=15)
PHP-Code:## Written by djcj
## Last change: July 14th 2012
/*
mode =
hmmss: 0:04:17
mmss: 04:17
mss: 4:17
mssms1: 4:17.3
mssms2: 4:17.37
mssms3: 4:17.375
mssms: 4:17.375
mmssms1: 04:17.3
mmssms2: 04:17.37
mmssms3: 04:17.375
mmssms: 04:17.375
hmmssms1: 0:04:17.3
hmmssms2: 0:04:17.37
hmmssms3: 0:04:17.375
hmmssms: 0:04:17.375
*/
function FormatTime(int "ms") {
_s = ms / 1000
_ms = ms % 1000
_m = _s / 60
_s = _s % 60
_h = _m / 60
_m = _m % 60
h = string(_h)
m = string(_m,"%2.0f")
mm = string(_m,"%02.0f")
ss = string(_s,"%02.0f")
ms = string(_ms,"%03.0f")
ms1 = LeftStr(string(_ms,"%03.0f"), 1)
ms2 = LeftStr(string(_ms,"%03.0f"), 2)
FormatTime = \
timer_global_mode=="hmmss" ? h+":"+mm+":"+ss : \
timer_global_mode=="mmss" ? mm+":"+ss : \
timer_global_mode=="mss" ? m+":"+ss : \
timer_global_mode=="mssms1" ? m+":"+ss+"."+ms1 : \
timer_global_mode=="mssms2" ? m+":"+ss+"."+ms2 : \
timer_global_mode=="mssms3" ? m+":"+ss+"."+ms : \
timer_global_mode=="mssms" ? m+":"+ss+"."+ms : \
timer_global_mode=="mmssms1" ? mm+":"+ss+"."+ms1 : \
timer_global_mode=="mmssms2" ? mm+":"+ss+"."+ms2 : \
timer_global_mode=="mmssms3" ? mm+":"+ss+"."+ms : \
timer_global_mode=="mmssms" ? mm+":"+ss+"."+ms : \
timer_global_mode=="hmmssms1" ? h+":"+mm+":"+ss+"."+ms1 : \
timer_global_mode=="hmmssms2" ? h+":"+mm+":"+ss+"."+ms2 : \
timer_global_mode=="hmmssms3" ? h+":"+mm+":"+ss+"."+ms : \
timer_global_mode=="hmmssms" ? h+":"+mm+":"+ss+"."+ms : NOP
return FormatTime
}
function timer(clip c, string "mode", bool "reverse", int "color", float "size", int "x", int "y", int "align") {
global timer_global_mode = Default(mode, "hmmss")
reverse = Default(reverse, false)
global timer_global_color = Default(color, $ffffff)
global timer_global_size = size
global timer_global_x = x
global timer_global_y = y
global timer_global_align = align
source = c
HasAudio(source)==true ? Eval(""" # prevents a double reverse on the sound
a = c.KillVideo
c = c.KillAudio
""") : NOP
c = reverse==true ? c.reverse() : c
c = c.ScriptClip("subtitle(FormatTime(round((current_frame * 1000) / framerate)), \
text_color=timer_global_color, size=timer_global_size, x=timer_global_x, \
y=timer_global_y, align=timer_global_align)")
c = reverse==true ? c.reverse() : c
c = HasAudio(source)==true ? AudioDub(c, a) : c # prevents a double reverse on the sound
return c
}
function timer_cut(clip c, string "mode", int "start", int "end", bool "reverse", bool "showstart",\
bool "showend", int "color", float "size", int "x", int "y", int "align") {
global timer_global_mode = Default(mode, "hmmss")
reverse = Default(reverse, false)
showstart = Default(showstart, false)
showend = Default(showend, false)
color = Default(color, $ffffff)
IsInt(start)==false || IsInt(end)==false ? Eval("""
start = round(c.framecount/3)
end = 2*round(c.framecount/3)
c = c.subtitle("No value set for parameter START and/or END!", align=2, size=round(c.width*0.05))
""") : NOP
fs = round(((end-start) * 1000) / c.framerate)
zero = reverse==true ? FormatTime(fs) : FormatTime(0)
time = reverse==true ? FormatTime(0) : FormatTime(fs)
zero = showstart==false ? "" : zero
time = showend==false ? "" : time
c = c.trim(0,start-1).subtitle(zero, text_color=color, size=size, x=x, y=y, align=align)++\
c.trim(start,end).timer(mode=timer_global_mode, reverse=reverse, color=color, size=size, x=x, y=y, align=align)++\
c.trim(end+1,0).subtitle(time, text_color=color, size=size, x=x, y=y, align=align)
return c
}
Und hier noch ein Skript das einen rotierenden Balken erzeugt (sinnfrei):
PHP-Code:function lol(clip last) {
scriptclip("""
ms = round((current_frame * 1000) / framerate) % 1000
a = " |"
b = " /"
c = "—"
d = " \"
lol = \
ms <= 125 ? a : \
ms <= 250 ? b : \
ms <= 375 ? c : \
ms <= 500 ? d : \
ms <= 625 ? a : \
ms <= 750 ? b : \
ms <= 875 ? c : d
subtitle(lol)
""")
}


Zitieren



