TCAX 字幕特效制作工具官方论坛 | ASS | TCAS | Python | Aegisub | Lua

 找回密码
 新人加入
查看: 13934|回复: 8

tcaxPy 脚本模板详解 (英文) [复制链接]

Administrator

TCAX Dev.

Rank: 7Rank: 7Rank: 7

发表于 2011-8-7 14:14:43 |显示全部楼层
Predefined Function Interfaces

The predefined functions if any are executed by TCAX in order, there are in total four interfaces:

tcaxPy_Init

Usually, it does some initialization, and will be executed only once before any other predefined functions of the tcaxPy script.

Implementation example:
  1. def tcaxPy_Init():

  2.     # some common pre-defined global values

  3.     global fontSize    # as name implies
  4.     global resX        # horizontal resolution
  5.     global resY        # vertical resolution
  6.     global marginX     # horizontal margin
  7.     global marginY     # vertical margin
  8.     global spacing     # space between texts
  9.     global frameDur    # milliseconds per frame
  10.     global lineNum     # number of lines
  11.     global textNum     # textNum[i], number of texts in ith line
  12.     global start       # start[i], start time of a line
  13.     global end         # end[i], end time of a line
  14.     global kar         # kar[i][j], karaoke time of a syllable
  15.     global elapKar     # elapKar[i][j], elapsed karaoke time before reaching a certain syllable
  16.     global text        # text[i][j], as name implies
  17.     global textLength  # textLength[i], total width of a line
  18.     global width       # width[i][j], width of a text
  19.     global height      # height[i][j], height of a text
  20.     global advance     # advance[i][j], advance of a text, usually larger than width
  21.     global advDiff     # advDiff[i][j], distance between the current text to the first text of the line
  22.     fontSize     = GetVal(val_FontSize)
  23.     resX         = GetVal(val_ResolutionX)
  24.     resY         = GetVal(val_ResolutionY)
  25.     marginX      = GetVal(val_OffsetX)
  26.     marginY      = GetVal(val_OffsetY)
  27.     spacing      = GetVal(val_Spacing)
  28.     frameDur     = 1000 / GetVal(val_FXFPS)
  29.     lineNum      = GetVal(val_nLines)
  30.     textNum      = GetVal(val_nTexts)
  31.     start        = GetVal(val_BegTime)
  32.     end          = GetVal(val_EndTime)
  33.     kar          = GetVal(val_KarTime)
  34.     elapKar      = GetVal(val_KarTimeDiff)
  35.     text         = GetVal(val_Text)
  36.     textLength   = GetVal(val_TextLength)
  37.     width        = GetVal(val_TextWidth)
  38.     height       = GetVal(val_TextHeight)
  39.     advance      = GetVal(val_TextAdvance)
  40.     advDiff      = GetVal(val_TextAdvanceDiff)

  41.     # some user-defined global values

  42.     global font
  43.     global fontBord
  44.     font     = InitFont(GetVal(val_FontFileName), GetVal(val_FaceID), fontSize, GetVal(val_Spacing), GetVal(val_SpaceScale), MakeRGB(255, 255, 255), 0, 0)
  45.     fontBord = InitFont(GetVal(val_FontFileName), GetVal(val_FaceID), fontSize, GetVal(val_Spacing), GetVal(val_SpaceScale), MakeRGB(0, 0, 0), 2, 1)
复制代码
tcaxPy_Main

It provides some easy to use information through the parameters, and the function will be executed many times, which is decided by the number of syllables or texts.

Description of parameters:
# _i          the current line being handled whose index is _i
# _j          the current text being handled whose index is _j in the current line
# _n          number of texts in the current line
# _start      start time of the current line
# _end        end time of the current line
# _elapk      elapsed time from the first text of the line to the current text
# _k          the karaoke time of the current text
# _x          the horizontal position of the current text (an5)
# _y          the vertical position of the current text (an5)
# _a          the advance of the current text
# _txt        the content of the current text

Note:
1. the existing time of the current text is from _start + _elapk to _start + _elapk + _k
2. you can replace the parameter names with whatever you preferred.

Implementation example:
  1. def tcaxPy_Main(_i, _j, _n, _start, _end, _elapk, _k, _x, _y, _a, _txt):

  2.     ASS_BUF  = []        # used for saving ASS FX lines
  3.     TCAS_BUF = []        # used for saving TCAS FX raw data

  4.     #############################
  5.     # TODO: write your codes here #

  6.     ass_main(ASS_BUF, SubL(_start, _end), pos(_x, _y) + K(_elapk) + K(_k), _txt)

  7.     #############################

  8.     return (ASS_BUF, TCAS_BUF)
复制代码
tcaxPy_User

It will be executed only once and if this function is used, tcaxPy_Main function will be ignored. The difference between tcaxPy_User function and tcaxPy_Main function is that tcaxPy_User function leaves all the work to be done by the user, while tcaxPy_Main function leaves the I/O task to TCAX. The structure of tcaxPy_Main function is somewhat dull, not as flexible as tcaxPy_User function. However, you can make your own script template by implementing the tcaxPy_User interface.

Implementation example:
  1. def tcaxPy_User():
  2.     ASS = CreateAssFile(GetVal(val_OutFile) + '.ass', GetVal(val_AssHeader))

  3.     for i in range(lineNum):
  4.         initPosX = (resX - textLength[i]) / 2 + marginX        # if marginX = 0, then it's just on the middle
  5.         initPosY = marginY
  6.         for j in range(textNum[i]):
  7.             ASS_BUF = []    # you can put the BUF anywhere according to your usage
  8.             if text[i][j] == '' or text[i][j] == ' ' or text[i][j] == ' ':
  9.                 continue
  10.             posX = initPosX + advDiff[i][j] + advance[i][j] / 2
  11.             posY = initPosY
  12.             ass_main(ASS_BUF, SubL(start[i], end[i]), an(8) + pos(posX, posY) + K(elapKar[i][j]) + K(kar[i][j]), text[i][j])
  13.             WriteAssFile(ASS, ASS_BUF)
  14.             Progress(i, j)

  15.     FinAssFile(ASS)
复制代码
tcaxPy_Fin

Usually, it does some finalization, and it will be executed only once after any other predefined functions of the tcaxPy script.

Implementation example:
  1. def tcaxPy_Fin():
  2.     FinFont(font)
  3.     FinFont(fontBord)
  4.     Pause()
复制代码
TCC Options to Enable/Disable the Interfaces

You can change the options about whether to use these functions through the TCC file:

< tcaxpy init = true >
true - will use tcaxPy_Init function, and you should implement the tcaxPy_Init interface in your tcaxPy scripts.

< tcaxpy user = false >
false - will use tcaxPy_Main function instead, and you should implement the tcaxPy_Main interface in your tcaxPy scripts.

< tcaxpy fin = false >
false - will not use tcaxPy_Fin function, so you do not have to implement it.

you can change the settings according to your usage.


Miscellaneous

Python is a powerful scripting language, you can break the limitations of TCAX,  and enhance it by using external modules and co-operate with your own tcaxPy script template, which can be achieved by using your own implementation of the predefined tcaxPy_User interface. Though such task is never easy, and requires your better understanding of Python programming and the concepts of TCAX.

Here is an example of implementing a new tcaxPy_User function.
http://www.tcax.org/forum.php?mod=viewthread&tid=278


tcaxPy_template_example.py

2.82 KB, 下载次数: 2489

script example

Rank: 4

发表于 2011-10-26 18:56:20 |显示全部楼层
唉……英文不好看不怎么懂啊……怎么办啊……

Administrator

TCAX Dev.

Rank: 7Rank: 7Rank: 7

发表于 2011-10-26 19:01:26 |显示全部楼层
diehell 发表于 2011-10-26 18:56
唉……英文不好看不怎么懂啊……怎么办啊……

其实可以不用看这个...

http://www.tcax.org/forum.php?mod=viewthread&tid=17

直接看这个教程... 里面有讲解...

Rank: 4

发表于 2011-10-26 19:05:27 |显示全部楼层
milkyjing 发表于 2011-10-26 19:01
其实可以不用看这个...

http://www.tcax.org/forum.php?mod=viewthread&tid=17

这个……怎么说呢,现在就是在折腾怎么写出自己的py脚本文件……Milk大人有没有什么好的建议么……

Administrator

TCAX Dev.

Rank: 7Rank: 7Rank: 7

发表于 2011-10-26 19:07:02 |显示全部楼层
diehell 发表于 2011-10-26 19:05
这个……怎么说呢,现在就是在折腾怎么写出自己的py脚本文件……Milk大人有没有什么好的建议么……{:onio ...


通常都是先从改例子入手的...

http://www.tcax.org/forum.php?mod=forumdisplay&fid=42


如果有什么疑问, 也可以加我QQ, http://www.tcax.org/forum.php?mod=viewthread&tid=124



Rank: 4

发表于 2011-10-26 19:10:30 |显示全部楼层
milkyjing 发表于 2011-10-26 19:07
通常都是先从改例子入手的...

http://www.tcax.org/forum.php?mod=forumdisplay&fid=42

谢谢Milk大人。鄙人会努力的。现在正在学会看懂别人的特效代码

Administrator

TCAX Dev.

Rank: 7Rank: 7Rank: 7

发表于 2011-10-26 19:14:46 |显示全部楼层
diehell 发表于 2011-10-26 19:10
谢谢Milk大人。鄙人会努力的。现在正在学会看懂别人的特效代码

加油吧, 另外, 直接milk就好.... (惭愧状

Rank: 4

发表于 2011-10-26 19:18:33 |显示全部楼层
milkyjing 发表于 2011-10-26 19:14
加油吧, 另外, 直接milk就好.... (惭愧状

嗯,谢谢milk

Rank: 4

发表于 2013-8-4 05:25:17 |显示全部楼层
本帖最后由 tomo 于 2013-8-6 00:56 编辑

想问。。。alpha的意思,还有alpha (数字) dec value,数字代表什么呢,这些有什么特别网站逐一解说吗?毕竟新手想问问题会很多


def alpha(a):                                    # note that a is a dec value
    return '\\alpha&H{0}&'.format(FmtHex(a))

def alpha1(a):
    return '\\1a&H{0}&'.format(FmtHex(a))

def alpha2(a):
    return '\\2a&H{0}&'.format(FmtHex(a))

def alpha3(a):
    return '\\3a&H{0}&'.format(FmtHex(a))

def alpha4(a):
    return '\\4a&H{0}&'.format(FmtHex(a))

不好意思,找到解说了,是透明度。。。。真的不好意思!

Rank: 4

发表于 2021-7-10 00:11:52 |显示全部楼层
本帖最后由 Seekladoom 于 2021-7-12 18:37 编辑

【此部分为TCAX的时间控制函数相关内容,跟Aegisub的retime比较类似】
tcaxPy_Main

通过参数提供一些便于使用的信息,函数会被执行很多次,这取决于音节或文本的数量。

参数说明:
# _i          当前行,即第i行,i是文本行的计数器(相当于Aegisub的$li)
# _j          当前行的第j个文字,j是当前行的文字序号的计数器相当于Aegisub的syl.i、$si)
# _n          当前行的文本总数,其功能跟Aegisub的char修饰语有类似之处
# _start      当前行的开始时间(相当于Aegisub的line.start、$lstart)【坛友修改后的写法以_BT居多】
# _end        当前行的结束时间(相当于Aegisub的line.end_time、$lend)【坛友修改后的写法以_ET居多】
# _elapk      从当前行的第一个文本到当前文本经过的时间(相当于Aegisub的syl.start_time、start2syl)【坛友修改后的写法以_SK居多】
# _k          当前文本的卡拉 OK 时间(相当于Aegisub的$dur、$sdur、$kdur、syl)【坛友修改后的写法以_KT居多】
# _x          当前文本的横坐标 (an5)(相当于Aegisub的$center、$scenter、$lcenter)
# _y          当前文本的纵坐标 (an5)(相当于Aegisub的$middle、$smiddle、$lmiddle)
# _a          当前文本的宽度(相当于Aegisub的syl.width、line.width、$swidth、$lwidth)
# _txt        当前文本的内容(相当于Aegisub的syl.text、line.text)

Rank: 4

发表于 2021-7-12 00:47:22 |显示全部楼层
本帖最后由 Seekladoom 于 2021-7-12 00:47 编辑

EFT和EXT特效里面可以找到t标签在TCAX的python脚本里面的规范写法。[tv_思考]

eft_003.py和eft_004.py还有具体的t标签写法案例:
【eft_003.py】
EFT = pos(_x, _y) + bord(0) + alpha1(255) + color3(_2C) + t(3 * _k, 6 * _k, bord(10) + blur(5) + alpha3(150)) + t(6 * _k, 6 * _k, alpha3(255))
t代码为:t(6 * _k, 6 * _k, alpha3(255))

【eft_004.py】
EFT1 = alpha1(0) + color1(FFFFFF) + alpha3(255) + t(0, 4 * _k + _FD, 1.3, fs(Fs2))
t代码为:t(0, 4 * _k + _FD, 1.3, fs(Fs2))
您需要登录后才可以回帖 登录 | 新人加入

GitHub|TCAX 主页

GMT+8, 2024-3-29 14:08

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部
RealH