Log in

View Full Version : How to display "µ" using Avisynth? Matrix grid comparison of videos


hristoff2
6th October 2016, 08:26
Hey,

I'm working with high speed videos and need / want to do side by side comparisons or matrix-grid comparisons.

I made a counter to display the runtime and two versions of how to compare several videos in a matrix grid. Everything works fine, except this

subtitle(mm+" µs", text_color=color, size=size, x=x, y=y)

http://666kb.com/i/dd09hvbixhgcl68xm.png

returns an A with hat as in  in front of the µ. Videos are only a few hundred frames at 210000 kHz, meaning 4.7ish µs per frame. How can I fix this?

The weird thing is, that this is displayed correctly, so it must be related to "subtitle_framerate.avs":

FFVideoSource("testclip.avi")
Subtitle("test µ",x=10,y=6,size=sz,text_color=clr)

http://666kb.com/i/dd09hz2ayriuz0omy.png



Here is the rest of the code:



##subtitle_framerate.avs
## Written by djcj
## Modified by h2
## Last change: Oct 5th 2016

function flowtime(clip last, string "mode", int "color", float "size", int "x", int "y") {
mode = Default(mode, "error")
global color = Default(color, $ffffff)
global size = size
global x = x
global y = y

/*
mode =

hmmss: 0:04:17
mmss: 04:17
Hz210000: 1 Frame = 4,762 µs

*/

# h:mm:ss
error = ScriptClip("""
subtitle("specify framerate in format (xyzkHz)", text_color=color, size=size, x=x, y=y)
""")

# h:mm:ss
hmmss = ScriptClip("""
fs = current_frame/framerate
h = string(floor((fs/60)*60)/3600, "%1.0f")
mm = string(floor(fs/60)-floor(fs/3600)*60, "%02.0f")
ss = LeftStr(string(fs-floor(fs/60)*60, "%06.3f"), 2)
subtitle(h+":"+mm+":"+ss, text_color=color, size=size, x=x, y=y)
""")

# mm:ss, Platzhalter und Vorlage für Makro Videos -- dafuer geht aber auch ShowTime()
mmss = ScriptClip("""
fs = current_frame/framerate
mm = string(floor(fs/60)-floor(fs/3600)*60, "%02.0f")
ss = LeftStr(string(fs-floor(fs/60)*60, "%06.3f"), 2)
subtitle(mm+":"+ss, text_color=color, size=size, x=x, y=y)
""")

# 210kHz...beliebig erweitern
Hz210000 = ScriptClip("""
fs = 4.762*current_frame
mm = string(fs, "%1.2f")
subtitle(mm+" µs", text_color=color, size=size, x=x, y=y)
""")


(mode=="hmmss") ? Eval("""
return hmmss
""") : \
(mode=="mmss") ? Eval("""
return mmss
""") : \
(mode=="Hz210000") ? Eval("""
return Hz210000
""") : \
Eval("""
return error
""")
}

And I display it in a matrix grid and some descriptions using avslib with

#LoadPlugin("C:\Program Files (x86)\AviSynth\plugins\ffms2.dll")
Import("subtitle_framerate.avs")

# load required modules (requires AvsLIB)

LoadModule("avslib", "array", "core")
LoadModule("avslib", "filters", "stack")

#Jetzt gehts los

sz = 16
clr = $ffffff

a= FFVideoSource("testclip.avi").\
AddBorders(6,6,6,6).\
Subtitle("text1",x=10,y=6,size=sz,text_color=clr).\
Subtitle("text2",x=10,y=24,size=sz,text_color=clr).\
flowtime(mode="Hz210000",size=20,x=10,y=132)

b= FFVideoSource("testclip.avi").\
AddBorders(6,6,6,6).\
Subtitle("text1",x=10,y=6,size=sz,text_color=clr).\
Subtitle("text2",x=10,y=24,size=sz,text_color=clr).\
flowtime(mode="Hz210000",size=20,x=10,y=132)

c= FFVideoSource("testclip.avi").\
AddBorders(6,6,6,6).\
Subtitle("text1",x=10,y=6,size=sz,text_color=clr).\
Subtitle("text2",x=10,y=24,size=sz,text_color=clr).\
flowtime(mode="Hz210000",size=20,x=10,y=132)

d= FFVideoSource("testclip.avi").\
AddBorders(6,6,6,6).\
Subtitle("text1",x=10,y=6,size=sz,text_color=clr).\
Subtitle("text2",x=10,y=24,size=sz,text_color=clr).\
flowtime(mode="Hz210000",size=20,x=10,y=132)

e= FFVideoSource("testclip.avi").\
AddBorders(6,6,6,6).\
Subtitle("text1",x=10,y=6,size=sz,text_color=clr).\
Subtitle("text2",x=10,y=24,size=sz,text_color=clr).\
flowtime(mode="Hz210000",size=20,x=10,y=132)

f= FFVideoSource("testclip.avi").\
AddBorders(6,6,6,6).\
Subtitle("text1",x=10,y=6,size=sz,text_color=clr).\
Subtitle("text2",x=10,y=24,size=sz,text_color=clr).\
flowtime(mode="Hz210000",size=20,x=10,y=132)



#StackVertical(StackHorizontal(a, b),StackHorizontal(c,d))


#mit LoadModule AvsLib gehts
vids = ArrayCreate(a,b,c,d,e,f)
return Stack(vids, 2, 3)

or without AvsLib

#LoadPlugin("C:\Program Files (x86)\AviSynth\plugins\ffms2.dll")
Import("subtitle_framerate.avs")

# load required modules

#LoadModule("avslib", "array", "core")
#LoadModule("avslib", "filters", "stack")

#Jetzt gehts los

sz = 16
clr = $ffffff

a= FFVideoSource("E:\zzzzzzzzzz_avisynth\testclip.avi").\
AddBorders(6,6,6,6).\
Subtitle("text1",x=10,y=6,size=sz,text_color=clr).\
Subtitle("text2",x=10,y=24,size=sz,text_color=clr)

b= FFVideoSource("E:\zzzzzzzzzz_avisynth\testclip.avi").\
AddBorders(6,6,6,6).\
Subtitle("text1",x=10,y=6,size=sz,text_color=clr).\
Subtitle("text2",x=10,y=24,size=sz,text_color=clr)\

c= FFVideoSource("E:\zzzzzzzzzz_avisynth\testclip.avi").\
AddBorders(6,6,6,6).\
Subtitle("text1",x=10,y=6,size=sz,text_color=clr).\
Subtitle("text2",x=10,y=24,size=sz,text_color=clr)

d= FFVideoSource("E:\zzzzzzzzzz_avisynth\testclip.avi").\
AddBorders(6,6,6,6).\
Subtitle("text1",x=10,y=6,size=sz,text_color=clr).\
Subtitle("text2",x=10,y=24,size=sz,text_color=clr)

StackVertical(StackHorizontal(a, b),StackHorizontal(c,d))
flowtime(mode="Hz210000",size=20,x=16,y=316)

Groucho2004
6th October 2016, 09:00
returns an A with hat as in  in front of the µ.
That's what the "µ" character looks like when you save the script with UTF-8 character encoding. Save it in 8 bit ANSI, CP 1252, for example.

raffriff42
6th October 2016, 10:52
Chr (http://avisynth.nl/index.php/Internal_functions#Chr)(181) should do it even with a Unicode script file, but watch out:http://avisynth.nl/index.php/Internal_functions#Chr

Note that characters above the ASCII character set (ie above 127) are code page (https://en.wikipedia.org/wiki/Code_page) dependent and may render different (visual) results in different systems.

Groucho2004
6th October 2016, 11:44
Chr (http://avisynth.nl/index.php/Internal_functions#Chr)(181) should do it even with a Unicode script file
Huh? Avisynth does not accept UTF-16 or UTF-8 characters. It has to be ANSI 8 bit encoding in one of the standard Windows code pages (and of course the system locale should match that code page).
Also, if Avisynth finds a UTF-16 or UTF-8 BOM it will throw an error right away.

raffriff42
6th October 2016, 11:55
OK I see what you are saying

hristoff2
6th October 2016, 14:46
Mh, converting with Notepad++ to ANSI fixed it, now I feel stupid - thanks a lot!

While we're at it, any way to define this globally, like this (pseudo code):


AddBorders(6,6,6,6)

-->

borders = 6,6,6,6

Addborders(string(borders)) or Addborders(borders)

tried variations of that, but it didn't work

If I want to do stuff like that, do I have to write it as a plugin and call it from my actual .avs script or can I somehow write subroutines in my actual avs script?

Groucho2004
6th October 2016, 15:24
While we're at it, any way to define this globally, like this (pseudo code):


AddBorders(6,6,6,6)

-->

borders = 6,6,6,6

Addborders(string(borders)) or Addborders(borders)

tried variations of that, but it didn't work

If I want to do stuff like that, do I have to write it as a plugin and call it from my actual .avs script or can I somehow write subroutines in my actual avs script?
Frequently used stuff like that is probably best kept in a function within a .avsi in your auto-load directory. For example:
function AddBorders6(clip video)
{
return video.AddBorders(6,6,6,6)
}
or more versatile:
function AddBordersN(clip video, int "m")
{
m = default(m, 0)
return video.AddBorders(m,m,m,m)
}