在AviSynth官方wiki里,有对subtitle一些方法实现的说明:
网址:http://avisynth.nl/index.php/Subtitle
我们可以通过一个引入参数的线性变化来控制这个参数所代表的实际意义
实现变色功能:
function test_1(clip C, string s, float f) {
return C.Subtitle(s, x=400,size=64,font="WRYH.TTF",text_color=Round(f)) //将线性变量f作为文本颜色
\ .Subtitle(String(f, "%03.3f"))
}
实现文字缩放:
function test_2(clip C, string s, float f) {
return C.Subtitle(s, align=5,size=f,font="WRYH.TTF") //将线性变量作为字号size
\ .Subtitle(String(f, "%03.3f"))
}
实现文字位移:
function test_3(clip C, string s, float f) {
return C.Subtitle(s, x=400,size=64,font="WRYH.TTF") //将线性变量f作为x坐标
\ .Subtitle(String(f, "%03.3f"))
}
实现文字旋转:
function test_4(clip C, string s, float f) { //将线性变量f作为角度angle
return C.Subtitle(s, align=5, font_angle=f)
\ .Subtitle("font_angle = "+String(f, "%03.3f"),
}
实现淡入淡出:
function test_5(clip C, string s, float f) {
return C.Subtitle(s, x=400,size=64,font="WRYH.TTF",halo_color=$ff000000,text_color=fade(f))
\ .Subtitle(String(f, "%03.3f"))
}
这里,color本身是支持透明度的,但是要以一个特殊的类型呈现,目前还不知道什么能够把整型转换成这种类型的方法
目前我是写死了一个fade函数,比较傻
function color(float f){
return Floor(f)==1?$ff000000:Floor(f)==2?$dd000000:Floor(f)==3?$bb000000:Floor(f)==4?$99000000:Floor(f)==5?$77000000:Floor(f)==6?$55000000:Floor(f)==7?$33000000:Floor(f)==8?$11000000:Floor(f)==9?$33000000:Floor(f)==10?$55000000:Floor(f)==11?$77000000:Floor(f)==12?$99000000:Floor(f)==13?$bb000000:Floor(f)==14?$dd000000:Floor(f)==15?$ee000000:$ff000000
}
引入代码:
LoadPlugin("C:/Program Files (x86)/AviSynth/plugins/x86/ffms2.dll")
FFVideoSource("C:\Users\cat\Desktop\subtitle\a.mp4")
s = "hello word!"
return Animate(Last, 0, 255, "test_1", s, 1, s, 800)
\ + Animate(Last, 0, 255, "test_2", s, 16.0, s, 64.0)
\ + Animate(Last, 0, 255, "test_3", s, 0, s, 40)
\ + Animate(Last, 0, 255, "test_4", s, 16.0, s, 64.0)
\ + Animate(Last, 0, 255, "test_5", s, 0, s, 40)