main.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. from fastapi import FastAPI,Cookie, Depends, FastAPI, Query, WebSocket, status, WebSocketDisconnect
  2. import openshot
  3. from os import listdir
  4. from os.path import isfile, isdir, join
  5. import threading
  6. import zhtts
  7. import os
  8. import urllib
  9. from typing import List
  10. import requests
  11. from pydantic import BaseModel
  12. from bs4 import BeautifulSoup
  13. import time
  14. from PIL import Image,ImageDraw,ImageFont
  15. import pyttsx3
  16. import rpyc
  17. import random
  18. import time
  19. import math
  20. import hashlib
  21. import re
  22. import urllib.request
  23. from fastapi.responses import FileResponse
  24. from websocket import create_connection
  25. from fastapi.middleware.cors import CORSMiddleware
  26. import dataset
  27. #service nginx restart
  28. #uvicorn main:app --host="0.0.0.0" --reload --port 8888
  29. app = FastAPI()
  30. origins = [
  31. "https://hhh.com.tw"
  32. "http://172.105.205.52",
  33. "http://172.105.205.52:8001",
  34. "http://172.104.93.163",
  35. ]
  36. app.add_middleware(
  37. CORSMiddleware,
  38. # allow_origins=origins,
  39. allow_origins=["*"],
  40. allow_credentials=True,
  41. allow_methods=["*"],
  42. allow_headers=["*"],
  43. )
  44. dir_sound = 'mp3_track/'
  45. dir_photo = 'photo/'
  46. dir_text = 'text_file/'
  47. dir_video = 'video_material/'
  48. dir_title = 'title/'
  49. dir_subtitle = 'subtitle/'
  50. dir_anchor = 'anchor_raw/'
  51. class request(BaseModel):
  52. name: str
  53. text_content: str
  54. image_urls: List[str]
  55. class QQ(BaseModel):
  56. n1: str
  57. n2: str
  58. class request2(BaseModel):
  59. name: str
  60. text_content: List[str]
  61. image_urls: List[str]
  62. class anchor_request(BaseModel):
  63. name: str
  64. text_content: str
  65. image_urls: List[str]
  66. class ConnectionManager:
  67. def __init__(self):
  68. self.active_connections: List[WebSocket] = []
  69. async def connect(self, websocket: WebSocket):
  70. await websocket.accept()
  71. self.active_connections.append(websocket)
  72. def disconnect(self, websocket: WebSocket):
  73. self.active_connections.remove(websocket)
  74. async def send_personal_message(self, message: str, websocket: WebSocket):
  75. await websocket.send_text(message)
  76. async def broadcast(self, message: str):
  77. for connection in self.active_connections:
  78. await connection.send_text(message)
  79. manager = ConnectionManager()
  80. @app.get("/")
  81. async def root():
  82. return {"message": "Hello, this is index"}
  83. @app.get("/index2")
  84. async def index2():
  85. return FileResponse('index2.html')
  86. @app.get("/script_msg.js")
  87. async def index2():
  88. return FileResponse('script_msg.js')
  89. @app.get("/style.css")
  90. async def index2():
  91. return FileResponse('style.css')
  92. @app.get("/progress_page")
  93. async def progress_page():
  94. return FileResponse('progress.html')
  95. @app.post("/make_anchor_video_v2")
  96. async def make_anchor_video_v2(req:request2):
  97. x = threading.Thread(target=anchor_video_v2, args=(req.name, req.text_content, req.image_urls))
  98. x.start()
  99. return {"msg":"製作影片需要時間,請您耐心等候 稍後可以在www.choozmo.com:8168/"+req.name+".mp4 中觀看"}
  100. @app.websocket("/progress")
  101. async def websocket_endpoint(websocket: WebSocket):
  102. await manager.connect(websocket)
  103. try:
  104. while True:
  105. data = await websocket.receive_text()
  106. await manager.broadcast(data)
  107. except WebSocketDisconnect:
  108. manager.disconnect(websocket)
  109. @app.get("/history_input")
  110. async def history_input():
  111. db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
  112. statement = 'SELECT * FROM history_input ORDER BY timestamp DESC'
  113. logs = []
  114. for row in db.query(statement):
  115. logs.append({'id':row['id'],'name':row['name'],'text_content':row['text_content'],'image_urls':row['image_urls']})
  116. return logs
  117. @app.post("/log_test")
  118. async def log_test(req:request2):
  119. db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
  120. log_table = db['history_input']
  121. pk = log_table.insert({'name':req.name,'text_content':req.text_content,'image_urls':req.image_urls})
  122. return pk
  123. def notify_group(msg):
  124. headers = {
  125. "Authorization": "Bearer " + "WekCRfnAirSiSxALiD6gcm0B56EejsoK89zFbIaiZQD",
  126. "Content-Type": "application/x-www-form-urlencoded"
  127. }
  128. params = {"message": msg}
  129. r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params=params)
  130. #print(r)
  131. def cKey(r,g,b,fuzz):
  132. col=openshot.Color()
  133. col.red=openshot.Keyframe(r)
  134. col.green=openshot.Keyframe(g)
  135. col.blue=openshot.Keyframe(b)
  136. return openshot.ChromaKey(col, openshot.Keyframe(fuzz))
  137. def video_photo_clip(vid=None,layer=None, position=None, end=None
  138. ,scale_x=1,scale_y=1,location_x=0,location_y=0,ck=None,audio=True):
  139. clip = openshot.Clip(vid)
  140. clip.Layer(layer)
  141. clip.Position(position)
  142. clip.End(end)
  143. clip.scale_x=openshot.Keyframe(scale_x)
  144. clip.scale_y=openshot.Keyframe(scale_y)
  145. clip.location_x=openshot.Keyframe(location_x)
  146. clip.location_y=openshot.Keyframe(location_y)
  147. if ck!=None:
  148. clip.AddEffect(ck)
  149. if audio==True:
  150. clip.has_audio=openshot.Keyframe(1)
  151. else:
  152. clip.has_audio=openshot.Keyframe(0)
  153. return clip
  154. def myunichchar(unicode_char):
  155. mb_string = unicode_char.encode('big5')
  156. try:
  157. unicode_char = unichr(ord(mb_string[0]) << 8 | ord(mb_string[1]))
  158. except NameError:
  159. unicode_char = chr(mb_string[0] << 8 | mb_string[1])
  160. return unicode_char
  161. def file_prepare(name, name_hash,text_content,image_urls):
  162. #save image
  163. try:
  164. os.mkdir(dir_photo+name_hash)
  165. except FileExistsError:
  166. print("Directory " , dir_photo+name_hash , " already exists")
  167. img_num = 1
  168. for imgu in image_urls:
  169. im = Image.open(requests.get(imgu, stream=True).raw)
  170. im.save(dir_photo+name_hash+"/"+str(img_num)+".jpg")
  171. img_num+=1
  172. #save text
  173. text_file = open(dir_text+name_hash+".txt", "w")
  174. text_file.write(text_content)
  175. text_file.close()
  176. print("text file made")
  177. #make mp3
  178. tts = zhtts.TTS()
  179. tts.text2wav(text_content,dir_sound+name_hash+".mp3")
  180. print("mp3 file made")
  181. #make title as image
  182. txt2image(name, dir_title+name_hash+".png")
  183. def get_url_type(url):
  184. req = urllib.request.Request(url, method='HEAD', headers={'User-Agent': 'Mozilla/5.0'})
  185. r = urllib.request.urlopen(req)
  186. contentType = r.getheader('Content-Type')
  187. return contentType
  188. def downloadfile(name,url):
  189. name=name+".mp4"
  190. def make_dir(name_hash):
  191. #save image
  192. try:
  193. os.mkdir(dir_photo+name_hash)
  194. except FileExistsError:
  195. print("~~~~~~Warning~~~~~~~~~Directory " , dir_photo+name_hash , " already exists")
  196. try:
  197. os.mkdir(dir_text+name_hash)
  198. except FileExistsError:
  199. print("~~~~~~Warning~~~~~~~~~Directory " , dir_text+name_hash , " already exists")
  200. try:
  201. os.mkdir(dir_sound+name_hash)
  202. except FileExistsError:
  203. print("~~~~~~Warning~~~~~~~~~Directory " , dir_sound+name_hash , " already exists")
  204. try:
  205. os.mkdir(dir_video+name_hash)
  206. except FileExistsError:
  207. print("~~~~~~Warning~~~~~~~~~Directory " , dir_video+name_hash , " already exists")
  208. try:
  209. os.mkdir(dir_anchor+name_hash)
  210. except FileExistsError:
  211. print("~~~~~~Warning~~~~~~~~~Directory " , dir_anchor+name_hash , " already exists")
  212. try:
  213. os.mkdir(dir_subtitle+name_hash)
  214. except FileExistsError:
  215. print("~~~~~~Warning~~~~~~~~~Directory " , dir_subtitle+name_hash , " already exists")
  216. def file_prepare_v2(name, name_hash,text_content,image_urls):
  217. make_dir(name_hash)
  218. img_num = 1
  219. for imgu in image_urls:
  220. if get_url_type(imgu) =='video/mp4':
  221. r=requests.get(imgu)
  222. f=open(dir_photo+name_hash+"/"+str(img_num)+".mp4",'wb')
  223. for chunk in r.iter_content(chunk_size=255):
  224. if chunk:
  225. f.write(chunk)
  226. f.close()
  227. else:
  228. im = Image.open(requests.get(imgu, stream=True).raw)
  229. im= im.convert("RGB")
  230. im.save(dir_photo+name_hash+"/"+str(img_num)+".jpg")
  231. img_num+=1
  232. #save text
  233. txt_idx=0
  234. for txt in text_content:
  235. text_file = open(dir_text+name_hash+"/"+str(txt_idx)+".txt", "w")
  236. text_file.write(txt)
  237. text_file.close()
  238. txt_idx+=1
  239. print("text file made")
  240. #make mp3
  241. language = 'zh-tw'
  242. txt_idx = 0
  243. for txt in text_content:
  244. tts = zhtts.TTS()
  245. tts.text2wav(txt,dir_sound+name_hash+"/"+str(txt_idx)+".mp3")
  246. txt_idx+=1
  247. print("mp3 file made")
  248. #make title as image
  249. txt2image_title(name, dir_title+name_hash+".png")
  250. def txt2image(content, save_target):
  251. unicode_text = trim_punctuation(content)
  252. font = ImageFont.truetype(font="DFT_B7.ttc", size=38)
  253. text_width, text_height = font.getsize(unicode_text)
  254. canvas = Image.new('RGBA', (700, 500), (255, 0, 0, 0) )
  255. draw = ImageDraw.Draw(canvas)
  256. text= unicode_text
  257. draw.text((5,5), text, (255, 255, 0), font)
  258. canvas.save(save_target, "PNG")
  259. def txt2image_title(content, save_target):
  260. unicode_text = trim_punctuation(content)
  261. font = ImageFont.truetype(font="DFT_B7.ttc", size=28)
  262. text_width, text_height = font.getsize(unicode_text)
  263. canvas = Image.new('RGBA', (510, 500), (255, 0, 0, 0) )
  264. draw = ImageDraw.Draw(canvas)
  265. text= unicode_text
  266. draw.text((5,5), text, (17, 41, 167), font)
  267. canvas.save(save_target, "PNG")
  268. '''
  269. def txt2image_title(content, save_target):
  270. unicode_text =content
  271. font = ImageFont.truetype("font.ttf", 23,encoding='big5')
  272. text_width, text_height = font.getsize(unicode_text)
  273. canvas = Image.new('RGBA', (500, 500), (255, 0, 0, 0) )
  274. draw = ImageDraw.Draw(canvas)
  275. text=''
  276. for c in unicode_text:
  277. if len(re.findall(r'[\u4e00-\u9fff]+', c))>0:
  278. text+=myunichchar(c)
  279. else:
  280. text+=c
  281. draw.text((5,5), text, (17, 41, 167), font)
  282. canvas.save(save_target, "PNG")
  283. '''
  284. def call_achor_video_v2(fileName):
  285. conn = rpyc.classic.connect("192.168.1.105",18812)
  286. ros = conn.modules.os
  287. rsys = conn.modules.sys
  288. fr=open(dir_sound+fileName+".mp3",'rb')# voice
  289. #warning!!! file my be replaced by other process
  290. fw=conn.builtins.open('/tmp/output.mp3','wb')
  291. while True:
  292. b=fr.read(1024)
  293. if b:
  294. fw.write(b)
  295. else:
  296. break
  297. fr.close()
  298. fw.close()
  299. val=random.randint(1000000,9999999)
  300. ros.chdir('/home/jared/to_video')
  301. ros.system('./p6.sh '+str(val)+' &')
  302. while True:
  303. print('waiting...')
  304. if ros.path.exists('/tmp/results/'+str(val)):
  305. break
  306. time.sleep(5)
  307. print('waiting...')
  308. fr=conn.builtins.open('/tmp/results/'+str(val)+'.mp4','rb')
  309. fw=open(dir_anchor+fileName+".mp4",'wb')#peggy1_1
  310. while True:
  311. b=fr.read(1024)
  312. if b:
  313. fw.write(b)
  314. else:
  315. break
  316. fr.close()
  317. fw.close()
  318. def call_achor_video(name):
  319. conn = rpyc.classic.connect("192.168.1.105",18812)
  320. ros = conn.modules.os
  321. rsys = conn.modules.sys
  322. fr=open(dir_sound+name+".mp3",'rb')# voice
  323. #warning!!! file my be replaced by other process
  324. fw=conn.builtins.open('/tmp/output.mp3','wb')
  325. while True:
  326. b=fr.read(1024)
  327. if b:
  328. fw.write(b)
  329. else:
  330. break
  331. fr.close()
  332. fw.close()
  333. val=random.randint(1000000,9999999)
  334. ros.chdir('/home/jared/to_video')
  335. ros.system('./p6.sh '+str(val)+' &')
  336. while True:
  337. print('waiting...')
  338. if ros.path.exists('/tmp/results/'+str(val)):
  339. break
  340. time.sleep(15)
  341. print('waiting...')
  342. fr=conn.builtins.open('/tmp/results/'+str(val)+'.mp4','rb')
  343. fw=open(dir_anchor+name+'.mp4','wb')#peggy1_1
  344. while True:
  345. b=fr.read(1024)
  346. if b:
  347. fw.write(b)
  348. else:
  349. break
  350. fr.close()
  351. fw.close()
  352. print('called..............................................')
  353. def trim_punctuation(s):
  354. pat_block = u'[^\u4e00-\u9fff0-9a-zA-Z]+';
  355. pattern = u'([0-9]+{0}[0-9]+)|{0}'.format(pat_block)
  356. res = re.sub(pattern, lambda x: x.group(1) if x.group(1) else u"" ,s)
  357. return res
  358. def splitter(s):
  359. for sent in re.findall(u'[^!?,。\!\?]+[!?。\!\?]?', s, flags=re.U):
  360. yield sent
  361. def split_by_pun(s):
  362. res = list(splitter(s))
  363. return res
  364. def generate_subtitle_image(name_hash,text_content):
  365. img_list = [None]*len(text_content)
  366. for idx in range(len(text_content)):
  367. img_list[idx]=[]
  368. senList = split_by_pun(text_content[idx])
  369. for inner_idx in range(len(senList)):
  370. sv_path = dir_subtitle + name_hash +'/'+str(idx)+ str(inner_idx) +'.png'
  371. sub = senList[inner_idx]
  372. txt2image(sub,sv_path)
  373. img_list[idx]+=[{"count":len(sub),"path":sv_path}]
  374. return img_list
  375. def anchor_video_v2(name,text_content, image_urls):
  376. ws = create_connection("ws://www.choozmo.com:8888/progress")
  377. progress = 0
  378. m = hashlib.md5()
  379. m.update(name.encode("utf-8"))
  380. name_hash = m.hexdigest()
  381. print('sub image made')
  382. file_prepare_v2(name, name_hash, text_content,image_urls)
  383. progress = 10
  384. ws.send(str(progress))
  385. sub_list=generate_subtitle_image(name_hash,text_content)
  386. progress = 20
  387. ws.send(str(progress))
  388. progress_per_video = int(40/len(text_content))
  389. for fname in range(len(text_content)):
  390. call_achor_video_v2(name_hash+"/"+str(fname))
  391. progress += progress_per_video
  392. ws.send(str(progress))
  393. print('step finish')
  394. print('called............................................')
  395. ck=cKey(0,254,0,150)
  396. ck_anchor=cKey(0,255,1,320)
  397. duration = 0
  398. #average layer level is 3
  399. t = openshot.Timeline(1280, 720, openshot.Fraction(30000, 1000), 44100, 2, openshot.LAYOUT_STEREO)
  400. t.Open()
  401. main_timer = 0
  402. LOGO_OP = openshot.FFmpegReader(dir_video+"LOGO_OP.mp4")
  403. LOGO_OP.Open() # Open the reader
  404. LOGO_OP_clip = video_photo_clip(vid=LOGO_OP,layer=4,position=0,end=LOGO_OP.info.duration
  405. ,location_y=-0.03,scale_x=0.8,scale_y=0.71)
  406. t.AddClip(LOGO_OP_clip)
  407. bg_head = openshot.FFmpegReader(dir_video+"bg_head.avi")
  408. bg_head.Open()
  409. bg_head_clip = video_photo_clip(vid=bg_head,layer=2,position=0,end=LOGO_OP.info.duration,ck=ck)
  410. t.AddClip(bg_head_clip)
  411. main_timer += LOGO_OP.info.duration
  412. head_duration = LOGO_OP.info.duration
  413. bg_head.Close()
  414. LOGO_OP.Close()
  415. progress += 10
  416. clip_duration=0
  417. photo_clip_list = [None]*len(text_content)
  418. img_list = [None]*len(text_content)
  419. anchor_clip_list = [None] * len(text_content)
  420. anchor_list = [None] * len(text_content)
  421. audio_clip_list = [None] * len(text_content)
  422. audio_list = [None] * len(text_content)
  423. sub_clip_list = [None] * len(text_content)
  424. sub_img_list = [None] * len(text_content)
  425. idx = 0
  426. for p in listdir(dir_photo+name_hash):
  427. anchor_list[idx] = openshot.FFmpegReader(dir_anchor+name_hash+"/"+str(idx)+".mp4")
  428. clip_duration = anchor_list[idx].info.duration
  429. anchor_list[idx].Open()
  430. anchor_clip_list[idx] = video_photo_clip(vid=anchor_list[idx],layer=4,scale_x=0.65,scale_y=0.65,
  431. location_x=0.35,location_y=0.25,position=main_timer, end=clip_duration,ck=ck_anchor,audio=False)
  432. t.AddClip(anchor_clip_list[idx])
  433. img_list[idx] = openshot.FFmpegReader(dir_photo+name_hash+'/'+p)
  434. img_list[idx].Open()
  435. photo_clip_list[idx] = video_photo_clip(vid=img_list[idx],layer=3
  436. ,scale_x=0.81,scale_y=0.68,location_y=-0.03,position=main_timer,end=clip_duration,audio=False)
  437. t.AddClip(photo_clip_list[idx])
  438. img_list[idx].Close()
  439. audio_list[idx] = openshot.FFmpegReader(dir_sound+name_hash+"/"+str(idx)+".mp3")
  440. audio_list[idx].Open()
  441. audio_clip_list[idx] = openshot.Clip(audio_list[idx])
  442. audio_clip_list[idx].Position(main_timer)
  443. audio_clip_list[idx].End(clip_duration)
  444. t.AddClip(audio_clip_list[idx])
  445. img_list[idx].Close()
  446. anchor_list[idx].Close()
  447. audio_list[idx].Close()
  448. sub_img_list[idx] = [None] * len(sub_list[idx])
  449. sub_clip_list[idx] = [None] * len(sub_list[idx])
  450. sub_timer = 0
  451. for sub_idx in range(len(sub_list[idx])):
  452. sub_img_list[idx][sub_idx] = openshot.QtImageReader(sub_list[idx][sub_idx]['path'])
  453. sub_img_list[idx][sub_idx].Open()
  454. sub_duration = 0.205*sub_list[idx][sub_idx]['count']
  455. sub_clip_list[idx][sub_idx] = video_photo_clip(vid=sub_img_list[idx][sub_idx], layer=6,location_x=0.069, location_y=0.89,position=main_timer+sub_timer,end=sub_duration)
  456. t.AddClip(sub_clip_list[idx][sub_idx])
  457. sub_img_list[idx][sub_idx].Close()
  458. sub_timer += sub_duration
  459. print(sub_list[idx][sub_idx]['path'])
  460. main_timer += clip_duration
  461. idx+=1
  462. progress+=10
  463. ws.send(str(progress))
  464. LOGO_ED = openshot.FFmpegReader(dir_video+"LOGO_ED.avi")
  465. LOGO_ED.Open()
  466. LOGO_ED_clip = video_photo_clip(vid=LOGO_ED,layer=4,position=main_timer,end=LOGO_ED.info.duration
  467. ,location_y=-0.03,scale_x=0.8,scale_y=0.71)
  468. t.AddClip(LOGO_ED_clip)
  469. ED_duration = LOGO_ED.info.duration
  470. LOGO_ED.Close()
  471. bg = openshot.FFmpegReader(dir_video+"bg.mp4")
  472. bg.Open()
  473. bg_times = math.floor(main_timer+ED_duration/bg.info.duration)
  474. left_time = (main_timer+ED_duration) % bg.info.duration
  475. bg_clip_list = [None] * bg_times
  476. bg_list = [None] * bg_times
  477. bg.Close()
  478. bg_timer = head_duration
  479. for idx in range(bg_times):
  480. bg_list[idx] = openshot.FFmpegReader(dir_video+"bg.mp4")
  481. bg_list[idx].Open()
  482. bg_clip_list[idx] = video_photo_clip(bg_list[idx],layer=2,position=bg_timer
  483. ,end=bg_list[idx].info.duration,ck=ck)
  484. t.AddClip(bg_clip_list[idx])
  485. bg_timer += bg_list[idx].info.duration
  486. bg_list[idx].Close()
  487. bg_left = openshot.FFmpegReader(dir_video+"bg.mp4")
  488. bg_left.Open()
  489. bg_left_clip = video_photo_clip(bg_left,layer=2,position=bg_timer,end=left_time,ck=ck)
  490. t.AddClip(bg_left_clip)
  491. bg_left.Close()
  492. title = openshot.QtImageReader(dir_title+name_hash+".png")
  493. title.Open() # Open the reader
  494. title_clip = video_photo_clip(vid=title, layer=4,location_x=-0.047, location_y=0.801,position=0,end=head_duration+main_timer)
  495. t.AddClip(title_clip)
  496. ####start building
  497. w = openshot.FFmpegWriter("../html/"+name_hash+".mp4")
  498. w.SetAudioOptions(True, "aac", 44100, 2, openshot.LAYOUT_STEREO, 3000000)
  499. w.SetVideoOptions(True, "libx264", openshot.Fraction(30000, 1000), 1280, 720,
  500. openshot.Fraction(1, 1), False, False, 3000000)
  501. w.Open()
  502. #may change duration into t.info.duration
  503. for n in range(int(t.info.fps)*int(head_duration+main_timer+ED_duration)):
  504. f=t.GetFrame(n)
  505. w.WriteFrame(f)
  506. t.Close()
  507. w.Close()
  508. print("Raw Video done")
  509. print("video at : www.choozmo.com:8168/"+name_hash+".mp4")
  510. progress = 100
  511. ws.send(str(progress))
  512. ws.close()
  513. #line notifs
  514. notify_group(name+"的影片已經產生完成囉! www.choozmo.com:8168/"+name_hash+".mp4")