- UID
- 2546
- 积分
- 159
- 帖子
- 30
- 主题
- 5
- 论坛币
- 868
- 威望
- 0
- EP值
- 134
- MP值
- 0
- 阅读权限
- 50
- 注册时间
- 2015-5-9
- 在线时间
- 52 小时
- 最后登录
- 2024-10-20
|
本帖最后由 Seekladoom 于 2022-2-1 03:31 编辑
反复试错试了半天才注意到,sai大的脚本应该是能跑的,不过本人用的是TCAX 1.2.0,直接使用sai大的代码去跑时TCAX半天没有出现任何运行提示,等了很多次都是大概等待3分钟左右,TCAX就崩溃了。
拆解了各分区代码运行测试后发现,tcVideo模块的相关代码写在def tcaxPy_Main下无法正常运行,极其容易出现等待3分钟左右,TCAX就崩溃的现象。不知道sai大用的是哪个版本的TCAX?
1.非tcVideo部分(可直接运行)
- from tcaxPy import *
- def tcaxPy_Init():
- global _Fs
- global Font
- global fx_fps
- global _FD
- _Fs = GetVal(val_FontSize)
- Font = InitFont(GetVal(val_FontFileName), GetVal(val_FaceID), _Fs, GetVal(val_Spacing), GetVal(val_SpaceScale), 0xFFFFFF, 0, 0)
- fx_fps = GetVal(val_FXFPS)
- _FD = 1000 / GetVal(val_FXFPS)
- def tcaxPy_Fin():
- FinFont(Font)
- def tcaxPy_Main(_i, _j, _n, _BT, _ET, _SK, _KT, _X, _Y, _A, _TXT):
- ASS_BUF = [] # 保存ASS特效
- dx = _X - int(_A / 2 + 0.5)
- dy = _Y - int(_Fs / 2 + 0.5)
- outline = TextOutlineDraw(Font, _TXT, dx, dy)
- t0 = _BT - 15 + _j * 7
- t1 = t0 + 50
- t2 = _BT + _SK - 5
- t3 = _BT + _SK + _KT
- t4 = _ET - 60 + _j * 7
- t5 = t4 + 15
- scol = 'FFFFFF'
-
- T = 120
- if _KT > 120:
- T = _KT
-
- ass_main(ASS_BUF, SubL(t2, t2+T, 11, Pix_Style), pos(0, 0) + fad(0, 900) + alpha1(0) + alpha3(HexToDec('77')) + blur(5) + bord(5) + t(bord(0)) + p(7), outline)
- ass_main(ASS_BUF, SubL(t0, t5, 5, Pix_Style), pos(1, 1) + fad(500, 500) + alpha1(0) + blur(1.3) + color1('000000') + p(7), outline)
- # 這下面就沒什麼好講的了 無視
- lastptx0 = 0
- lastpty0 = 0
- first = True
- ti = t0 - 100 + randint(-30, 30)
- while ti <= t5 - 150:
- ptt0 = ti
- ptt1 = ptt0 + 300
- ptx0 = randint(_X - 20, _X + 20)
- pty0 = randint(_Y - 20, _Y + 20)
- if not first:
- for i in range(2):
- ptx0_tmp = randint(_X - 20, _X + 20)
- pty0_tmp = randint(_Y - 20, _Y + 20)
- if GetDistance(lastptx0, lastpty0, ptx0, pty0) < GetDistance(lastptx0, lastpty0, ptx0_tmp, pty0_tmp):
- ptx0 = ptx0_tmp
- pty0 = pty0_tmp
- first = False
- lastptx0 = ptx0
- lastpty0 = pty0
- ptcol = 'FFFFFF'
- lumsz = 15 + GetDistance(_X, _Y, ptx0, pty0) * 0.5
- if ptt0 >= t2:
- ptcol = scol
- ts0 = ''
- if ptt0 < t2 and ptt1 > t2:
- ts0 = t(10 * (t2 - ptt0) - 10, 10 * (t2 - ptt0), color1(scol) + color3(scol))
- dup = 1
- if _j >= 4:
- dup = 2
- while dup > 0:
- ass_main(ASS_BUF, SubL(ptt0, ptt1, 10, Pix_Style), pos(ptx0, pty0) + clip(7, outline) + org(_X, _Y) + t(frz(RandSign() * randint(80, 120))) + \
- fad(800, 800) + t(0, 10 * (ptt1 - ptt0), bord(lumsz) + blur(lumsz)) + alpha1(HexToDec('44')) + alpha3(HexToDec('44')) + color1(ptcol) + color3(ptcol) + \
- ts0 + t((ptt1 - ptt0) * 700, ptt1, color1('000000') + color3('000000')), PixPt())
- dup -= 1
- ti += randint(120, 165)
- return (ASS_BUF, None)
复制代码
2.写在def tcaxPy_Init和def tcaxPy_Main下无法正常运行的【文字跟色部分】
- from tcaxPy import *
- from util.tcVideo import *
- def tcaxPy_Init():
- global _FD
- global _Fs
- global Font
- global fx_fps
- global light
- _FD = 1000 / GetVal(val_FXFPS)
- _Fs = GetVal(val_FontSize)
- Font = InitFont(GetVal(val_FontFileName), GetVal(val_FaceID), _Fs, GetVal(val_Spacing), GetVal(val_SpaceScale), 0xFFFFFF, 0, 0)
- fx_fps = GetVal(val_FXFPS)
- light = []
- global video
- tcVideoInit() # tcvideo初始化
- video = tcVideoOpen('test.mp4') #打開媒體文件
- r_o = 65
- l_o = 0
- for i in range (2200):
- PIX = tcVideoGetFrame(video, int((getBT(0)*10/_FD)+0.5)+i) # 獲取int((getBT(0)*10/_FD)+0.5)+i幀的畫面像素信息
- cc = 30 #這邊沒什麼用 只是在調整 畫面黑白的計算容差
- if int((getBT(0)*10/_FD)+0.5)+i > 30200:
- cc = 15
- if int((getBT(0)*10/_FD)+0.5)+i > 30840:
- cc = 30
- if int((getBT(0)*10/_FD)+0.5)+i > 31040:
- cc = 15
- if int((getBT(0)*10/_FD)+0.5)+i > 31810:
- cc = 5
-
- h = 265 #像素Y坐標
- w = 618 #像素X坐標
- idx = 4 * (h * PIX[1][0] + w) #list腳標
- r = PIX[2][idx + 0] # RGB顏色 R值
- #print(r) #debug用
- if r - r_o > cc:
- l = 1
- elif r_o - r > cc:
- l = 0
- else:
- l=l_o
- light.append(l)
-
- r_o = r
- l_o = l
- def tcaxPy_Fin():
- FinFont(Font)
- tcVideoClose(video) #關閉
- tcVideoFin()
- def tcaxPy_Main(_i, _j, _n, _BT, _ET, _SK, _KT, _X, _Y, _A, _TXT):
- ASS_BUF = [] # 保存ASS特效
- DY = _Y - 13
- dx = _X - int(_A / 2 + 0.5)
- dy = DY - int(_Fs / 2 + 0.5)
- outline = TextOutlineDraw(Font, _TXT, dx, dy)
- t0 = _BT - 15 + _j * 7
- t1 = t0 + 50
- t2 = _BT + _SK - 5
- t3 = _BT + _SK + _KT
- t4 = _ET - 60 + _j * 7
- t5 = t4 + 15
- scol = 'FFFFFF'
-
- T = 120
- if _KT > 120:
- T = _KT
-
- ass_main(ASS_BUF, SubL(t2, t2+T, 11, Pix_Style), pos(0, 0) + fad(0, 900) + alpha1(0) + alpha3(HexToDec('77')) + blur(5) + bord(5) + t(bord(0)) + p(7), outline)
- ass_main(ASS_BUF, SubL(t0, t5, 5, Pix_Style), pos(1, 1) + fad(500, 500) + alpha1(0) + blur(1.3) + color1('000000') + p(7), outline)
- bframe = int((t0-getBT(0))*10/_FD)
- if light[bframe] == 1:
- ass_main(ASS_BUF, SubL(t0, t1, 6, Pix_Style), pos(0, 0) + fad(500, 0) + alpha1(150) + color1('FFFFFF') + p(7), outline)
- else:
- ass_main(ASS_BUF, SubL(t0,t1, 6, Pix_Style), pos(0, 0) + fad(500, 0) + alpha1(120) + color1('000000') + p(7), outline)
-
- frames = int((_ET - 60-t1)*10 / _FD + 0.5) #總幀數
- bframe = int((t1-getBT(0))*10/_FD) #開始幀
- ts = t1
- te = t1
- ll = light[bframe]
- ll_o = light[bframe]
- for i in range(frames): #逐幀
- te += _FD / 10
- ll = light[bframe+i]
- if ll != ll_o:
- ll_o = ll
- if te < _ET - 60:
- if ll!=1:
- ass_main(ASS_BUF, SubL(ts, te - _FD / 10, 6, Pix_Style), pos(0, 0) +fad(30,30) + alpha1(150) + color1('FFFFFF'),'{\\p7}' + outline + '{\\p0}')
- else:
- ass_main(ASS_BUF, SubL(ts,te - _FD / 10, 6, Pix_Style), pos(0, 0) +fad(30,30) + alpha1(120) + color1('000000'),'{\\p7}' + outline + '{\\p0}')
- ts = te - _FD / 10
- return (ASS_BUF, None)
复制代码
脚本目前还在改造中,能直接跑的完整版本改好以后会贴在下面(请先将楼主提供的tcVideo模块解压到TCAX安装目录下的util文件夹以后,再使用如下脚本,否则无法正常运行):
TCAX Karaoke Effect mekaku_ed.rar
(19.56 KB, 下载次数: 2900)
- from tcaxPy import *
- from util.tcVideo import *
- def tcaxPy_Init():
- global _FD
- global _Fs
- global Font
- _FD = 1000 / GetVal(val_FXFPS)
- _Fs = GetVal(val_FontSize)
- Font = InitFont(GetVal(val_FontFileName), GetVal(val_FaceID), _Fs, GetVal(val_Spacing), GetVal(val_SpaceScale), 0xFFFFFF, 0, 0)
- # tcVideo
- global video
- tcVideoInit() # tcvideo初始化
- video = tcVideoOpen('mekakucityactors_NCED.mp4') #打开媒体文件
-
- # light 列表
- global light
- light = []
- rgb_o = 65
- l_o = 0
- for i in range (200):
- PIX = tcVideoGetFrame(video, int((getBT(0) * 10 / _FD) + 0.5) + i) # 逐帧获取int((getBT(0) * 10/_FD) + 0.5) + i帧的画面像素信息,此脚本运行的主要耗时就在这里
- cc = 30 #这边没什麽用 只是在调整 画面黑白的计算容差
- if int((getBT(0) * 10/_FD) + 0.5) + i > 30200:
- cc = 15
- if int((getBT(0) * 10/_FD) + 0.5) + i > 30840:
- cc = 30
- if int((getBT(0) * 10/_FD) + 0.5) + i > 31040:
- cc = 15
- if int((getBT(0) * 10/_FD) + 0.5) + i > 31810:
- cc = 5
-
- h = 265 #像素Y坐标
- w = 618 #像素X坐标
- idx = 4 * (h * PIX[1][0] + w) #list脚标
- rgb = PIX[2][idx + 0] # RGB颜色 R值
-
- #print(rgb) #debug用
- if rgb - rgb_o > cc:
- l = 1
- elif rgb_o - rgb > cc:
- l = 0
- else:
- l = l_o
- light.append(l) #输出l的列表light
- rgb_o = rgb
- l_o = l
- progress(i + 1, 200)
- def tcaxPy_Fin():
- FinFont(Font)
- tcVideoClose(video) #关闭
- tcVideoFin()
- def tcaxPy_Main(_i, _j, _n, _BT, _ET, _SK, _KT, _X, _Y, _A, _TXT):
- ASS_BUF = [] # 保存ASS特效
- DY = _Y - 13
- dx = _X - int(_A / 2 + 0.5)
- dy = DY - int(_Fs / 2 + 0.5)
- outline = TextOutlineDraw(Font, _TXT, dx, dy)
- t0 = _BT - 15 + _j * 7
- t1 = t0 + 50
- t2 = _BT + _SK - 5
- t3 = _BT + _SK + _KT
- t4 = _ET - 60 + _j * 7
- t5 = t4 + 15
- scol = 'FFFFFF'
-
- T = 120
- if _KT > 120:
- T = _KT
-
- ass_main(ASS_BUF, SubL(t2, t2 + T, 11, Pix_Style), pos(0, 0) + fad(0, 900) + alpha1(0) + alpha3(HexToDec('77')) + blur(5) + bord(5) + t(bord(0)) + p(7), outline)
- ass_main(ASS_BUF, SubL(t0, t5, 5, Pix_Style), pos(1, 1) + fad(500, 500) + alpha1(0) + blur(1.3) + color1('000000') + p(7), outline)
- # 根据背景亮度变化闪烁的文字
- bframe = int((t0 - getBT(0)) * 10 / _FD)
- if light[bframe] == 1:
- ass_main(ASS_BUF, SubL(t0, t1, 6, Pix_Style), pos(0, 0) + fad(500, 0) + alpha1(150) + color1('FFFFFF') + p(7), outline)
- else:
- ass_main(ASS_BUF, SubL(t0, t1, 6, Pix_Style), pos(0, 0) + fad(500, 0) + alpha1(120) + color1('000000') + p(7), outline)
-
- frames = int((_ET - 60 - t1) * 10 / _FD + 0.5) #总帧数
- bframe = int((t1 - getBT(0)) * 10/_FD) #开始帧
- ts = t1
- te = t1
- ll = light[bframe]
- ll_o = light[bframe]
- for i in range(frames):#逐帧判断并改变文字的透明度
- te += _FD / 10
- ll = light[bframe+i]
- if ll != ll_o:
- ll_o = ll
- if te < _ET - 60:
- if ll!=1:#改变文字的透明度
- ass_main(ASS_BUF, SubL(ts, te - _FD / 10, 6, Pix_Style), pos(0, 0) + fad(30,30) + alpha1(150) + color1('FFFFFF') + p(7), outline)
- else:
- ass_main(ASS_BUF, SubL(ts, te - _FD / 10, 6, Pix_Style), pos(0, 0) + fad(30,30) + alpha1(120) + color1('000000') + p(7), outline)
- ts = te - _FD / 10
- progress(i + 1, frames)
- # 像素文字部分
- lastptx0 = 0
- lastpty0 = 0
- first = True
- ti = t0 - 100 + randint(-30, 30)
- while ti <= t5 - 150:
- ptt0 = ti
- ptt1 = ptt0 + 300
- ptx0 = randint(_X - 20, _X + 20)
- pty0 = randint(DY - 20, DY + 20)
- if not first:
- for i in range(2):
- ptx0_tmp = randint(_X - 20, _X + 20)
- pty0_tmp = randint(DY - 20, DY + 20)
- if GetDistance(lastptx0, lastpty0, ptx0, pty0) < GetDistance(lastptx0, lastpty0, ptx0_tmp, pty0_tmp):
- ptx0 = ptx0_tmp
- pty0 = pty0_tmp
- first = False
- lastptx0 = ptx0
- lastpty0 = pty0
- ptcol = 'FFFFFF'
- lumsz = 15 + GetDistance(_X, DY, ptx0, pty0) * 0.5
- if ptt0 >= t2:
- ptcol = scol
- ts0 = ''
- if ptt0 < t2 and ptt1 > t2:
- ts0 = t(10 * (t2 - ptt0) - 10, 10 * (t2 - ptt0), color1(scol) + color3(scol))
- dup = 1
- if _j >= 4:
- dup = 2
- while dup > 0:
- ass_main(ASS_BUF, SubL(ptt0, ptt1, 10, Pix_Style), pos(ptx0, pty0) + clip(7, outline) + org(_X, DY) + t(frz(RandSign() * randint(80, 120))) + \
- fad(800, 800) + t(0, 10 * (ptt1 - ptt0), bord(lumsz) + blur(lumsz)) + alpha1(HexToDec('44')) + alpha3(HexToDec('44')) + color1(ptcol) + color3(ptcol) + \
- ts0 + t((ptt1 - ptt0) * 700, ptt1, color1('000000') + color3('000000')), PixPt())
- dup -= 1
- ti += randint(120, 165)
- return (ASS_BUF, None)
复制代码
检查测试后发现必须要在有tcVideo的for循环下添加progress以后才能更方便地观察TCAX的工作进度,因此凡是涉及tcVideo的TCAX特效脚本,最好都在相应位置添加progress函数跟踪运行进度。
|
|