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

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

[其他] 个人设想中的TCAX GUI生成的带python脚本代码的ASS字幕文件 [复制链接]

Rank: 4

跳转到指定楼层
楼主
发表于 2021-7-21 09:46:14 |只看该作者 |倒序浏览
本帖最后由 Seekladoom 于 2021-7-21 11:02 编辑

这个是我自己设想的一种带Python脚本代码的ASS字幕文件,第27行那里的[Python]表示ass字幕文件中的Python脚本代码分区,这部分内容我是打算如果未来有空给TCAX做GUI的话,就在GUI上加入一个专门写Python脚本代码的分区,并且这个分区的代码可以直接写入ass字幕文件(从外部加载py脚本生成特效的做法依然保留)。
做得出来的话当然是最好的,做不出来的话这个帖子也能给人留下一种TCAX GUI开发的思维方向了。。。_(:з」∠)_

  1. [Script Info]
  2. ; Script generated by TCAX 1.2.0
  3. ; http://www.tcax.org/
  4. ScriptType: v4.00+
  5. Original Timing:
  6. PlayResX: 1920
  7. PlayResY: 1080
  8. YCbCr Matrix: TV.709

  9. [TCAX Project Garbage]
  10. Audio File: ../../TCAX 1.2.0/../罪恶王冠 NCOP2.mp4
  11. Video File: ../../TCAX 1.2.0/../罪恶王冠 NCOP2.mp4
  12. Video AR Mode: 4
  13. Video AR Value: 1.777778
  14. Video Zoom Percent: 0.375000
  15. Scroll Position: 18
  16. Active Line: 21
  17. Video Position: 1327

  18. [V4+ Styles]
  19. Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
  20. Style: OPJP,FOT-Comet Std B,80,&H001F20EF,&H00000000,&H00FFFFFF,&H00000000,0,0,0,0,100,100,0,0,1,2,0,8,0,0,0,1
  21. Style: OPJP2,FOT-Comet Std B,80,&H00FFBC11,&H00000000,&H00FFFFFF,&H00000000,0,0,0,0,100,100,0,0,1,2,0,8,0,0,0,1
  22. Style: OPCN,MZhiHei PRC UltraBold,66,&H00FFFFFF,&H00000000,&H001F20EF,&H00000000,0,0,0,0,85,100,8,0,1,2,0,2,0,0,15,1
  23. Style: OPCN2,MZhiHei PRC UltraBold,66,&H00FFFFFF,&H00000000,&H00FFBC11,&H00000000,0,0,0,0,85,100,8,0,1,2,0,2,0,0,15,1

  24. [Python]
  25. from tcaxPy import *

  26. def tcaxPy_Init():
  27.     global _FD                              # frame duration, in millisecond
  28.     global _Blur, _Bord
  29.     global _FS
  30.     _FD = 1000 / GetVal(val_FXFPS)
  31.     _Blur = GetVal(val_Blur)
  32.     _Bord = GetVal(val_Bord)
  33.     _FS = GetVal(val_FontSize)

  34. def tcaxPy_Fin():
  35.     pass

  36. def tcaxPy_Main(_i, _j, _n, _start, _end, _elapk, _k, _x, _y, _a, _txt):
  37.     ASS_BUF = []        # used for saving ASS FX lines
  38.    
  39.     # ----------tcax line----------
  40.     hexagon = 'm -6 -10 l 6 -10 l 12 0 l 6 10 l -6 10 l -12 0 l -6 -10 '
  41.     hlist = []
  42.     able = []
  43.     f = 10
  44.     initx = int(GetVal(5) // 2 - _n / 2 * _FS - 55)
  45.     lastx = int(GetVal(5) // 2 + _n / 2 * _FS + 55)
  46.     inity = int(_y - _FS)
  47.     for x in range(initx - f * 1 , lastx + _a + f * 2, f * 2):
  48.         for y in range(inity - f * 0, _y + _FS + f * 1, f):
  49.             hlist.append((x, y))
  50.     for x in range(initx - f * 2 , lastx + _a + f * 1, f * 2):
  51.         for y in range(inity - f // 2 - f * 0, _y + _FS - f // 2 + f * 1, f):
  52.             hlist.append((x, y))
  53.     for (px, py) in hlist:
  54.         if (px - _x) ** 2 + (py - _y) ** 2 <= 30 ** 2:
  55.             able.append((px, py))

  56.     count = int(_k * 1.6)
  57.     for i in range(count):
  58.         pt = choice(able)
  59.         px = pt[0]
  60.         py = pt[1]
  61.         st = randint(_start + _elapk - 10, _start + _elapk + _k)
  62.         et = st + randint(55, 75)
  63.         if st >= _start + _elapk + _k - 5:
  64.             et = st + randint(70, 100)
  65.         dur = et - st - 10
  66.         transp = 50

  67.     # ----------绘图代码行----------
  68.         if _i < 6:#OPJP
  69.             ass_main(ASS_BUF, SubL(st, et, 0, 'OPJP'), pos(px, py+45) + color3('FFFFFF') + color1('1F20EF') + alpha1(255) + alpha3(transp) + bord(1) + fad(100, dur * 10) + fsc(45, 45) + p(1), hexagon)
  70.             ass_main(ASS_BUF, SubL(st, et, 0, 'OPJP'), pos(px, py+45) + color3('FFFFFF') + color1('1F20EF') + alpha1(100) + alpha3(transp) + bord(1) + fad(100, dur * 10) + fsc(52, 52) + p(1), hexagon)

  71.         if _i > 5 and _i < 12:#OPJP2
  72.             ass_main(ASS_BUF, SubL(st, et, 0, 'OPJP2'), pos(px, py+45) + color3('FFFFFF') + color1('FFBC11') + alpha1(255) + alpha3(transp) + bord(1) + fad(100, dur * 10) + fsc(45, 45) + p(1), hexagon)
  73.             ass_main(ASS_BUF, SubL(st, et, 0, 'OPJP2'), pos(px, py+45) + color3('FFFFFF') + color1('FFBC11') + alpha1(100) + alpha3(transp) + bord(1) + fad(100, dur * 10) + fsc(52, 52) + p(1), hexagon)

  74.     # ----------文本行----------
  75.     if _i < 6:#OPJP
  76.         ass_main(ASS_BUF, SubL(_start+_j*3-20,_start+_elapk,1,'OPJP'), pos(_x,_y)+blur(4)+fad(200,0), _txt)                                 #入场特效 - start2syl
  77.         ass_main(ASS_BUF, SubL(_start+_elapk,_start+_elapk+_k,1,'OPJP'), pos(_x,_y)+t(color1('FFFFFF')+color3('1F20EF'))+blur(4), _txt)     #卡拉OK特效 - syl
  78.         ass_main(ASS_BUF, SubL(_start+_elapk+_k,_end-(_n-_j-1)*3+20,1,'OPJP'), pos(_x,_y)+color1('FFFFFF')+color3('1F20EF')+blur(4)+fad(0,200), _txt)                         #退场特效 - syl2end
  79.    
  80.     if _i > 5 and _i < 12:#OPJP2
  81.         ass_main(ASS_BUF, SubL(_start+_j*3-20,_start+_elapk,1,'OPJP2'), pos(_x,_y)+color1('FFBC11')+color3('FFFFFF')+blur(4)+fad(200,0), _txt)                                 #入场特效 - start2syl
  82.         ass_main(ASS_BUF, SubL(_start+_elapk,_start+_elapk+_k,1,'OPJP2'), pos(_x,_y)+color1('FFBC11')+color3('FFFFFF')+t(color1('FFFFFF')+color3('FFBC11'))+blur(4), _txt)     #卡拉OK特效 - syl
  83.         ass_main(ASS_BUF, SubL(_start+_elapk+_k,_end-(_n-_j-1)*3+20,1,'OPJP2'), pos(_x,_y)+color1('FFFFFF')+color3('FFBC11')+blur(4)+fad(0,200), _txt)                         #退场特效 - syl2end
  84.       
  85.     if _i > 11 and _i < 18:#OPCN
  86.         ass_main(ASS_BUF, SubL(_start+_j*3-20,_end-(_n-_j-1)*3+20,1,'OPCN'), pos(_x,_y+1068)+blur(4)+fad(200,200)+fax(-0.11), _txt)  #整体特效 - line
  87.    
  88.     if _i > 17:#OPCN2
  89.         ass_main(ASS_BUF, SubL(_start+_j*3-20,_end-(_n-_j-1)*3+20,1,'OPCN2'), pos(_x,_y+1068)+blur(4)+fad(200,200)+fax(-0.11), _txt)  #整体特效 - line

  90.     return (ASS_BUF, None)

  91. [Events]
  92. Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
  93. Comment: 0,0:00:00.00,0:00:00.00,Default,,0,0,0,,--------------------OPJP--------------------
  94. Dialogue: 0,0:00:07.36,0:00:15.35,OPJP,,0,0,0,,{\k34}崩{\k56}壊{\k87}の{\k28}{\k41}交{\k53}響{\k34}曲{\k33}が{\k39}鳴{\k29}り{\k40}響{\k31}い{\k294}て
  95. Dialogue: 0,0:00:18.50,0:00:25.85,OPJP,,0,0,0,,{\k31}降{\k43}る{\k95}雨{\k42}{\k37}は{\k35}ま{\k20}る{\k34}で{\k101}涙{\k37}の{\k32}音{\k228}色
  96. Dialogue: 0,0:00:27.69,0:00:29.04,OPJP,,0,0,0,,{\k22}気{\k26}付{\k30}い{\k57}て
  97. Dialogue: 0,0:00:29.12,0:00:34.18,OPJP,,0,0,0,,{\k22}そ{\k34}の{\k19}目{\k27}は{\k76}互{\k37}い{\k36}を{\k53}認{\k84}め{\k18}る{\k20}た{\k80}め
  98. Dialogue: 0,0:00:34.70,0:00:39.92,OPJP,,0,0,0,,{\k25}そ{\k35}の{\k50}声{\k44}は{\k62}想{\k32}い{\k33}を{\k34}伝{\k75}え{\k18}る{\k13}た{\k101}め
  99. Dialogue: 0,0:00:40.30,0:00:49.85,OPJP,,0,0,0,,{\k20}そ{\k30}の{\k20}手{\k40}は{\k25}大{\k55}事{\k35}な{\k51}人{\k25}と{\k95}繋{\k145}ぐ{\k0} {\k21}た{\k224}め{\k15}に{\k15}あ{\k175}る
  100. Dialogue: 0,0:00:50.25,0:00:53.95,OPJP2,,0,0,0,,{\k74}こ{\k68}の{\k68}歌{\k28}が{\k43}聴{\k15}こ{\k22}え{\k18}て{\k34}る
  101. Dialogue: 0,0:00:54.30,0:00:57.56,OPJP2,,0,0,0,,{\k17}生{\k69}命{\k35}あ{\k26}る{\k43}全{\k19}て{\k29}の{\k40}者{\k48}よ
  102. Dialogue: 0,0:00:57.90,0:01:02.18,OPJP2,,0,0,0,,{\k73}真{\k64}実{\k63}は{\k15}あ{\k18}な{\k17}た{\k18}の{\k48}胸{\k21}の{\k41}中{\k15}に{\k15}あ{\k20}る
  103. Dialogue: 0,0:01:02.48,0:01:05.20,OPJP2,,0,0,0,,{\k55}嵐{\k39}の{\k46}海{\k13}を{\k17}行{\k18}く{\k25}時{\k59}も
  104. Dialogue: 0,0:01:05.47,0:01:11.45,OPJP2,,0,0,0,,{\k23}决{\k29}し{\k38}て{\k24}臆{\k25}す{\k18}る{\k18}こ{\k15}と{\k20}の{\k15}な{\k16}い{\k31}強{\k18}さ{\k308}を
  105. Dialogue: 0,0:01:13.12,0:01:17.47,OPJP2,,0,0,0,,{\k27}く{\k29}れ{\k13}る{\k87}か{\k279}ら
  106. Comment: 0,0:00:00.00,0:00:00.00,Default,,0,0,0,,--------------------OPCN--------------------
  107. Dialogue: 0,0:00:07.36,0:00:15.35,OPCN,,0,0,0,,{\k73}崩{\k73}溃{\k73}的{\k73}交{\k73}响{\k73}乐{\k73}章{\k73}在{\k73}响{\k73}彻{\k73}着
  108. Dialogue: 0,0:00:18.50,0:00:25.85,OPCN,,0,0,0,,{\k67}狂{\k67}乱{\k67}的{\k67}雨{\k67}仿{\k67}佛{\k67}眼{\k67}泪{\k67}的{\k67}音{\k67}色
  109. Dialogue: 0,0:00:27.69,0:00:29.04,OPCN,,0,0,0,,{\k45}醒{\k45}来{\k45}吧
  110. Dialogue: 0,0:00:29.12,0:00:34.18,OPCN,,0,0,0,,{\k51}那{\k51}双{\k51}眼{\k51}是{\k51}为{\k51}了{\k51}承{\k51}认{\k51}彼{\k51}此
  111. Dialogue: 0,0:00:34.70,0:00:39.92,OPCN,,0,0,0,,{\k52}那{\k52}声{\k52}音{\k52}是{\k52}为{\k52}了{\k52}传{\k52}达{\k52}思{\k52}念
  112. Dialogue: 0,0:00:40.30,0:00:49.85,OPCN,,0,0,0,,{\k80}那{\k80}双{\k80}手{\k80}是{\k80}为{\k80}了{\k80}握{\k80}紧{\k80}重{\k80}要{\k80}的{\k80}人
  113. Dialogue: 0,0:00:50.25,0:00:53.95,OPCN2,,0,0,0,,{\k62}能{\k62}听{\k62}见{\k62}这{\k62}首{\k62}歌
  114. Dialogue: 0,0:00:54.30,0:00:57.56,OPCN2,,0,0,0,,{\k65}万{\k65}物{\k65}生{\k65}灵{\k65}啊
  115. Dialogue: 0,0:00:57.90,0:01:02.18,OPCN2,,0,0,0,,{\k61}真{\k61}相{\k61}在{\k61}你{\k61}的{\k61}心{\k61}中
  116. Dialogue: 0,0:01:02.48,0:01:05.20,OPCN2,,0,0,0,,{\k34}教{\k34}会{\k34}我{\k34}真{\k34}正{\k34}的{\k34}坚{\k34}强
  117. Dialogue: 0,0:01:05.47,0:01:11.45,OPCN2,,0,0,0,,{\k66}就{\k66}算{\k66}在{\k66}暴{\k66}风{\k66}雨{\k66}中{\k66}航{\k66}行
  118. Dialogue: 0,0:01:13.12,0:01:17.47,OPCN2,,0,0,0,,{\k87}也{\k87}绝{\k87}不{\k87}胆{\k87}怯
复制代码
之所以这么想,是因为以前刚做字幕时到处找带特效模板的ass文件以及用Aegisub时养成的习惯——在Aegisub界面下的ass字幕文件中写好特效模板,然后点击一下应用卡拉OK模板即可生成ASS特效字幕的便利感。

在看过Aegisub和TCAX的github源码外加对ass字幕文件中的内容观察后,我才发现这两个软件生成ASS特效字幕时都是在字幕文件中有一段段文本分区的,且这些文本分区都在软件中有相应的依靠自定义字符串批量生成文本的脚本文件。文本分区如下:

--------------------Aegisub的是--------------------
[Script Info]
[Aegisub Project Garbage]
[V4+ Styles]
[Events]

--------------------TCAX的是--------------------
[Script Info]
[V4+ Styles]
[Events]


这也是我会想到在ASS字幕文件中添加[Python]的文本代码分区的原因之一,如果Aegisub当初那批老外开发时是这么设计(写个[Lua]或者[AUTO4]分区)的话,也就不至于把代码写进[Events]分区中因无法换行而挤作一团,导致代码阅读性不友好了。。。_(:з」∠)_
您需要登录后才可以回帖 登录 | 新人加入

GitHub|TCAX 主页

GMT+8, 2024-11-25 03:59

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部
RealH