- UID
- 2546
- 积分
- 159
- 帖子
- 30
- 主题
- 5
- 论坛币
- 868
- 威望
- 0
- EP值
- 134
- MP值
- 0
- 阅读权限
- 50
- 注册时间
- 2015-5-9
- 在线时间
- 52 小时
- 最后登录
- 2024-10-20
|
本帖最后由 Seekladoom 于 2021-12-21 23:26 编辑
【透镜文字效果】TCAX Karaoke Effect 056.rar
(241.21 KB, 下载次数: 2190)
1080P适配版本,精简了下代码:
- from tcaxPy import *
- from util.cairo import *
- #请使用VSFilterMod以外的滤镜插件,如xy-vsfilter.dll预览字幕文件。
- #因为此滤镜预览TCAX的cairo模块生成的【矢量文字】时会导致字幕错位和字号大小的显示出问题。
- def tcaxPy_Init():
- global frameDur
- global fontSize
- global userFont
- fontSize = GetVal(val_FontSize)
- frameDur = 1000 / GetVal(val_FXFPS)
- userFont = InitFont(GetVal(val_FontFileName), GetVal(val_FaceID), fontSize, GetVal(val_Spacing), GetVal(val_SpaceScale), DecRGB(GetVal(val_1C)), 0, 0)
- # cairo
- global ctx
- vdWidth = GetVal(val_ResolutionX)
- vdHeight = GetVal(val_ResolutionY)
- surface = ImageSurface(FORMAT_ARGB32, vdWidth, vdHeight)
- ctx = Context(surface)
- def tcaxPy_Fin():
- FinFont(userFont)
- #控制透镜文字位置
- def lens_filter(x, y, param):
- orgx, orgy, f, frames = param
- px = x / 64
- py = y / 64
- rx = px - orgx
- ry = py - orgy
- rsq = rx ** 2 + ry ** 2
- rx = rx * (1 + 0.00002 * (frames - 1 - f) / (frames - 1) * rsq)
- ry = ry * (1 + 0.00005 * (frames - 1 - f) / (frames - 1) * rsq)
- px = (rx + orgx) * 64
- py = (ry + orgy) * 64
- return (px, py)
- #控制文字形变程度
- def rand_filter(x, y, n):
- rndx = randint(-n, n)
- rndy = randint(-n, n)
- return (x + rndx, y + rndy)#关键待改之处2:x、y
-
- def tcaxPy_Main(_i, _j, _n, _BT, _ET, _SK, _K, _X, _Y, _A, _TXT):
- ASS_BUF = [] # used for saving ASS FX lines
-
- #自定义坐标参数
- ux = _X
- dx = GetVal(val_ResolutionX) - GetVal(val_TextLength)[_i]
- orgx = GetVal(val_OffsetX) + GetVal(val_TextLength)[_i] / 2
- orgy = GetVal(val_OffsetY) + fontSize / 2
-
- #透镜转场效果:坐标计算
- ux += dx / 2 #ux = ux + dx / 2
- orgx += dx / 2 #orgx = orgx + dx / 2
- udx = ux - int(_A / 2 + 0.5)
- udy = _Y - int(fontSize / 2 + 0.5)
-
- #透镜转场效果:矢量文字绘图代码
- outline = TextOutlineDraw(userFont, _TXT, udx, udy)
- frames = 14
- eft = an(7) + pos(5, _Y + 980) + blur(2)
- for f in range(frames):
- ts = _BT - (frames - f) * frameDur / 10
- te = ts + frameDur / 10
- AssDraw(ctx, outline)
- path_trans(ctx, lens_filter, (orgx, orgy, f, frames))
- text = ToAssDraw(ctx)
- ass_main(ASS_BUF, SubL(ts, te), eft + p(7), text)
-
- #普通文本
- weft = an(7) + pos(ux - 20, _Y + 980) + blur(2)
- ass_main(ASS_BUF, SubL(te, _BT + _SK), weft, _TXT)
- ass_main(ASS_BUF, SubL(_BT + _SK + _K, _ET), weft, _TXT)
-
- #唱K文字绘图代码
- frames = int(10 * _K / frameDur + 0.5)
- n = 200
- for f in range(frames):
- ts = _BT + _SK + f * frameDur / 10
- te = ts + frameDur / 10
- AssDraw(ctx, outline)
- path_trans(ctx, rand_filter, n)#关键待改之处1:长度【自适应问题】还没解决
- text = ToAssDraw(ctx)
- ass_main(ASS_BUF, SubL(ts, te), eft + p(7), text)
- return (ASS_BUF, None)
复制代码
相关链接:
TCAX 时间计算及文字定位 (英文)
【具体位置可看键盘上的小键盘数字1-9的布局来强化记忆】- 1.对齐方式 1,x = GetVal(val_OffsetX),y = GetVal(val_ResolutionY) - GetVal(val_FontSize) - GetVal(val_OffsetY)
- 2.对齐方式 2,x = GetVal(val_OffsetX) + (GetVal(val_ResolutionX) - GetVal(val_TextLength) [line_index]) / 2, y = GetVal(val_ResolutionY) - GetVal(val_FontSize) - GetVal(val_OffsetY)
- 3.对齐方式 3, x = GetVal(val_ResolutionX) - GetVal(val_TextLength)[line_index] - GetVal(val_OffsetX), y = GetVal(val_ResolutionY) - GetVal(val_FontSize) - GetVal(val_OffsetY)
- 4.对齐方式 4, x = GetVal(val_OffsetX), y = GetVal(val_ResolutionY) / 2 - GetVal(val_OffsetY)
- 5.对齐方式 5, x = GetVal(val_OffsetX) + (GetVal(val_ResolutionX) - GetVal(val_TextLength)[line_index]) / 2, y = GetVal(val_ResolutionY) / 2 - GetVal(val_OffsetY)
- 6.对齐方式 6, x = GetVal(val_ResolutionX) - GetVal(val_TextLength)[line_index] - GetVal(val_OffsetX), y = GetVal(val_ResolutionY) / 2 - GetVal(val_OffsetY)
- 7.对齐方式 7, x = GetVal(val_OffsetX), y = GetVal(val_OffsetY)
- 8.对齐方式 8, x = GetVal(val_OffsetX) + (GetVal(val_ResolutionX) - GetVal(val_TextLength)[line_index]) / 2, y = GetVal(val_OffsetY)
- 9.对齐方式 9, x = GetVal( val_ResolutionX) - GetVal(val_TextLength)[line_index] - GetVal(val_OffsetX), y = GetVal(val_OffsetY)
复制代码 |
|