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

 找回密码
 新人加入
查看: 14073|回复: 3
打印 上一主题 下一主题

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, 下载次数: 2532

script example

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

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

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



Administrator

TCAX Dev.

Rank: 7Rank: 7Rank: 7

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

加油吧, 另外, 直接milk就好.... (惭愧状
您需要登录后才可以回帖 登录 | 新人加入

GitHub|TCAX 主页

GMT+8, 2024-5-2 13:41

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部
RealH