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

 找回密码
 新人加入
查看: 3767|回复: 3

[完整特效] [J]munto_ed_shanzhai [附工程] [复制链接]

Moderator

Effect Researcher.

Rank: 5Rank: 5

发表于 2015-9-11 17:46:53 |显示全部楼层
本帖最后由 面麻 于 2015-9-11 17:54 编辑

说明:这是milk前辈从X大写的效果移植过来的,用了种子填充算法,正好应Alex的要求。
具体见脚本,就不解释了(我也还没看)。
用TCAS生成了,渲染效率高点。
附上工程,可以 prase 看看。附件去掉了片源和字体,体积太大就不放了。

munto_ed_shanzhai_temp.zip (8.45 KB, 下载次数: 1461)

如果有疑问,直接跟帖。
  1. ##### 基本函数库, 必须包含 #####

  2. from tcaxPy import *


  3. ##### 额外的一些库 #####

  4. from collections import deque


  5. def RandomDouble_Gauss(l, h):
  6.     return RandomDouble_Gauss_(l, h, 6)

  7. def RandomDouble_Gauss_(l, h, g):
  8.     sum = 0
  9.     for i in range(g):
  10.         sum += RandomDouble(l, h)
  11.     return sum / g

  12. def RandomDouble(l, h):
  13.     return l + (h - l) * random()


  14. ##### 初始化函数, 用于设定一些全局变量 #####

  15. def tcaxPy_Init():

  16.     ##### 声明全局变量 #####

  17.     global _FontFileName        # 字体文件名
  18.     global _FaceID                # 字体Face序号
  19.     global _Fs                        # 字体大小
  20.     global _TextWidth                # 文字宽度
  21.     global _TextHeight                # 文字高度
  22.     global _TextLength
  23.     global _TextAdvDiff
  24.     global _ResolutionX
  25.     global _OffsetX
  26.     global _FD                        # 一帧的持续时间, 40毫秒
  27.     global Font                        # 首要字体
  28.     global FontOut                # 字体边框

  29.     ##### 获取预定义的值 #####

  30.     _FontFileName = GetVal(val_FontFileName)
  31.     _FaceID       = GetVal(val_FaceID)
  32.     _Fs           = GetVal(val_FontSize)
  33.     _TextHeight   = GetVal(val_TextHeight)
  34.     _TextWidth    = GetVal(val_TextWidth)
  35.     _TextLength   = GetVal(val_TextLength)
  36.     _TextAdvDiff  = GetVal(val_TextAdvanceDiff)
  37.     _ResolutionX  = GetVal(val_ResolutionX)
  38.     _OffsetX      = GetVal(val_OffsetX)
  39.     _FD           = 1000 / GetVal(val_FXFPS)

  40.     ##### 设置自定义变量的值 #####

  41.     Font    = InitFont(_FontFileName, _FaceID, _Fs, GetVal(val_Spacing), GetVal(val_SpaceScale), 0xFFFFFF, 0, 0)        # 0xFFFFFF为16进制表示的白色
  42.     FontOut = InitFont(_FontFileName, _FaceID, _Fs, GetVal(val_Spacing), GetVal(val_SpaceScale), 0xFFFFFF, 4, 1)        # 最后一个参数置为1表示只提取边框



  43. ##### 结束函数, 用于一些收尾工作 #####

  44. def tcaxPy_Fin():

  45.     ##### 清理一些全局变量 #####

  46.     FinFont(Font)
  47.     FinFont(FontOut)


  48. ##### 脚本主函数, 会对每个文字执行一次 #####
  49. # _i                第_i句, 即当前操作的文字所在的句子序号
  50. # _j                第_i句中的第_j个文字, 即当前操作文字的序号
  51. # _n                第_i句中有_n个文字, 即当前句子所包含的文字数
  52. # _start        句子的开始时间
  53. # _end                句子的结束时间
  54. # _elapk        到第_j个字经过的时间, _start + _elapk 到 _start + _elapk + _k 即为当前文字的存在时间
  55. # _k                第_j个文字的卡拉OK时间
  56. # _x                第_j个文字的水平坐标
  57. # _y                第_j个文字的垂直坐标
  58. # _a                第_j个文字的水平跨距, 可以看作文字的宽度, 同样_Fs也可近似看成文字的高度
  59. # _txt                第_j个文字的内容

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

  61.     ASS_BUF  = []        # 保存ASS特效
  62.     TCAS_BUF = []        # 保存TCAS特效

  63.     ##### 主要特效编写操作 #####

  64.     if _i > 2 and _i % 2 == 1:
  65.         _x = _ResolutionX - _TextLength[_i] - _OffsetX + _TextAdvDiff[_i][_j]

  66.     t0 = _start - 60 + 5 * _j
  67.     t1 = t0 + 40
  68.     t2 = _end + 60 + 5 * _j
  69.     t3 = t2 + 40

  70.     for i in range(1, 5):
  71.         ass_main(ASS_BUF, SubL(t0 + 3 * i, t1 + 3 * i), \
  72.                  mov(_x + 30, _y - 30, _x, _y) + alpha1(255) + blur(2) + \
  73.                  fad(20 * (t1 - t0), 0) + fry(-180) + \
  74.                  animation1(0, 10 * (t1 - t0), fry(0)), _txt)
  75.     ass_main(ASS_BUF, SubL(t0, t1), \
  76.              mov(_x + 30, _y - 30, _x, _y) + alpha1(255) + blur(2) + \
  77.              fad(10 * (t1 - t0), 0) + fry(-180) + \
  78.              animation1(0, 10 * (t1 - t0), fry(0)), _txt)
  79.     ass_main(ASS_BUF, SubL(_start + _elapk, t2), \
  80.              pos(_x + 1, _y + 1) + alpha1(255) + alpha3(119) + color3('000000') + \
  81.              bord(8) + blur(8) + fad(20, 20), _txt)
  82.     ass_main(ASS_BUF, SubL(t1, t2), \
  83.              pos(_x, _y) + alpha1(255) + blur(2), _txt)
  84.     ass_main(ASS_BUF, SubL(t0, t1), \
  85.              mov(_x + 31, _y - 29, _x + 1, _y + 1) + alpha1(255) + alpha3(119) + color3('000000') + \
  86.              bord(8) + blur(8) + fad(10 * (t1 - t0), 0) + fry(-180) + \
  87.              animation1(0, 10 * (t1 - t0), fry(0)), _txt)
  88.     ass_main(ASS_BUF, SubL(t1, _start + _elapk + 2), \
  89.              pos(_x + 1, _y + 1) + alpha1(255) + alpha3(119) + color3('000000') + \
  90.              bord(8) + blur(8) + fad(0, 20), _txt)
  91.     for i in range(1, 5):
  92.         ass_main(ASS_BUF, SubL(t2 + 3 * i, t3 + 3 * i), \
  93.                  mov(_x, _y, _x - 30, _y + 30) + alpha1(0) + blur(2) + \
  94.                  fad(0, 20 * (t3 - t2)) + animation1(0, 10 * (t3 - t2), fry(180)), _txt)
  95.     ass_main(ASS_BUF, SubL(t2, t3), \
  96.              mov(_x, _y, _x - 30, _y + 30) + alpha1(0) + blur(2) + fad(0, 10 * (t3 - t2)) + \
  97.              animation1(0, 10 * (t3 - t2), fry(180)), _txt)

  98.     # gradient
  99.     seed(_j)
  100.     ptString = '{\\p8}m 0 0 l 128 0 128 128 0 128'

  101.     dx = _x - int(_a / 2 + 0.5)                # 一个固定操作, 将an5的坐标转换为an7
  102.     dy = _y - int(_Fs / 2 + 0.5)        # ASS特效默认采用an5坐标, TCAS特效则采用an7坐标

  103.     PIX = TextPix(Font, _txt)    # get the pixel info
  104.     PIX_t = PIX
  105.     width = PIX[1][0]
  106.     height = PIX[1][1]
  107.     # get points of the text from PIX, to get the colors from points use PIX[2][...]
  108.     text = []
  109.     for h in range(height):
  110.         for w in range(width):
  111.             if PIX[2][(h * width + w) * 4 + 3] != 0:
  112.                 text.append((w, h))
  113.     # make the boundary
  114.     boundary = []
  115.     for h in range(height):
  116.         boundary.append([])
  117.         for w in range(width):
  118.             boundary[h].append(-1)    # -1 indicates the boundary
  119.     num = len(text)    # number of points
  120.     for i in range(num):
  121.         w = text[i][0]
  122.         h = text[i][1]
  123.         boundary[h][w] = i    # non-boundary area
  124.     dx0 = (0, 1, 0, -1)
  125.     dy0 = (1, 0, -1, 0)
  126.     # make the index
  127.     index = []
  128.     for i in range(num):
  129.         index.append(-1)
  130.     # rearrange the index
  131.     left = num
  132.     while (left > 0):
  133.         q = deque()
  134.         for i in range(num):
  135.             if index[i] == -1:
  136.                 q.append(i)
  137.                 index[i] = 0
  138.                 break
  139.         while (len(q) > 0):
  140.             left -= 1
  141.             s = q.popleft()
  142.             pt = text[s]
  143.             for i in range(4):
  144.                x1 = pt[0] + dx0[i]
  145.                y1 = pt[1] + dy0[i]
  146.                if x1 >= 0 and x1 < width and y1 >= 0 and y1 < height and boundary[y1][x1] >= 0:
  147.                    t = boundary[y1][x1]
  148.                    if index[t] < 0:
  149.                        index[t] = index[s] + 1
  150.                        q.append(t)

  151.     # TCAS alternative
  152.     #pc0 = '5955FF'
  153.     #pc1 = '55FDFF'
  154.     #pc2 = '9C4E4D'
  155.     indsc = 0.5
  156.     tp0_start = 10 * _end
  157.     tp0_end = 0
  158.     tp0 = []
  159.     for i in range(num):
  160.         t = 10 * (_start + _elapk - 10 + index[i] / indsc + 10 * RandomDouble_Gauss(-0.2, 0.2))
  161.         tp0.append(t)
  162.         if t < tp0_start:    # what we are doing is to create a series of PIXs to conver all the possible durations
  163.             tp0_start = t
  164.         if t > tp0_end:
  165.             tp0_end = t
  166.     tp0_end += 24 * _FD
  167.     dur = tp0_end - tp0_start
  168.     for i in range(0, int(dur), int(_FD)):    # first of all, you should know how many frames we are going to make, then with each frame, what PIX we are going to use
  169.         PIX_li = []    # we need one PIX for each frame
  170.         PIX_li.append(PIX_t[0])
  171.         PIX_li.append(PIX_t[1])
  172.         temp = list(PIX_t[2])
  173.         for j in range(num):    # make the PIX
  174.             pt = text[j]
  175.             off = (pt[1] * width + pt[0]) * 4
  176.             temp[off + 0] = 0xFF
  177.             temp[off + 1] = 0x55
  178.             temp[off + 2] = 0x59
  179.             if tp0_start + i < tp0[j]:    # should be transparent
  180.                 temp[off + 3] = 0
  181.             elif tp0_start + i < tp0[j] + 7 * _FD:
  182.                 temp[off + 3] *= (i + tp0_start - tp0[j] + _FD) / (8 * _FD)
  183.             elif tp0_start + i < tp0[j] + 15 * _FD:
  184.                 temp[off + 0] = 0xFF
  185.                 temp[off + 1] = 0x55 + (0xFD - 0x55) * (i + tp0_start - tp0[j] - 7 * _FD) / (8 * _FD)
  186.                 temp[off + 2] = 0x59 + (0x55 - 0x59) * (i + tp0_start - tp0[j] - 7 * _FD) / (8 * _FD)
  187.             elif tp0_start + i < tp0[j] + 22 * _FD:
  188.                 temp[off + 0] = 0xFF + (0x4D - 0xFF) * (i + tp0_start - tp0[j] - 14 * _FD) / (8 * _FD)
  189.                 temp[off + 1] = 0xFD + (0x4E - 0xFD) * (i + tp0_start - tp0[j] - 14 * _FD) / (8 * _FD)
  190.                 temp[off + 2] = 0x55 + (0x9C - 0x55) * (i + tp0_start - tp0[j] - 14 * _FD) / (8 * _FD)
  191.             else:
  192.                 temp[off + 0] = 0x4D
  193.                 temp[off + 1] = 0x4E
  194.                 temp[off + 2] = 0x9C
  195.         PIX_li.append(tuple(temp))
  196.         PIX = tuple(PIX_li)
  197.         tcas_main(TCAS_BUF, PIX, tp0_start + i, tp0_start + i + _FD, dx, dy, 0)
  198.     tp0_end -= int(dur) % int(_FD)
  199.     if tp0_end < 10 * t2:
  200.         PIX = PixColorRGB(PIX_t, 0x9C4E4D)
  201.         tcas_main(TCAS_BUF, PIX, tp0_end, 10 * t2, dx, dy, 0)

  202.     ##### 将结果返回给tcax进行处理 #####

  203.     return (ASS_BUF, TCAS_BUF)
复制代码
2

查看全部评分

Rank: 4

发表于 2015-9-12 04:15:45 |显示全部楼层
厉害,,,

Rank: 4

发表于 2016-9-11 20:49:46 |显示全部楼层
辛苦了

Rank: 4

发表于 2018-9-10 20:56:29 |显示全部楼层
感谢
您需要登录后才可以回帖 登录 | 新人加入

GitHub|TCAX 主页

GMT+8, 2024-3-28 21:42

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部
RealH