main.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  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. txt_content_seperate_by_dot = ''
  122. for txt in req.text_content:
  123. txt_content_seperate_by_dot += txt+","
  124. txt_content_seperate_by_dot = txt_content_seperate_by_dot[:-1]
  125. img_urls_seperate_by_dot = ''
  126. for iurl in req.image_urls:
  127. img_urls_seperate_by_dot += iurl+","
  128. img_urls_seperate_by_dot[:-1]
  129. time_stamp = datetime.fromtimestamp(time.time())
  130. time_stamp = time_stamp.strftime("%Y-%m-%d %H:%M:%S")
  131. pk = log_table.insert({'name':req.name,'text_content':txt_content_seperate_by_dot,'image_urls':img_urls_seperate_by_dot,'timestamp':time_stamp})
  132. return pk
  133. def notify_group(msg):
  134. headers = {
  135. "Authorization": "Bearer " + "WekCRfnAirSiSxALiD6gcm0B56EejsoK89zFbIaiZQD",
  136. "Content-Type": "application/x-www-form-urlencoded"
  137. }
  138. params = {"message": msg}
  139. r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params=params)
  140. #print(r)
  141. def cKey(r,g,b,fuzz):
  142. col=openshot.Color()
  143. col.red=openshot.Keyframe(r)
  144. col.green=openshot.Keyframe(g)
  145. col.blue=openshot.Keyframe(b)
  146. return openshot.ChromaKey(col, openshot.Keyframe(fuzz))
  147. def video_photo_clip(vid=None,layer=None, position=None, end=None
  148. ,scale_x=1,scale_y=1,location_x=0,location_y=0,ck=None,audio=True):
  149. clip = openshot.Clip(vid)
  150. clip.Layer(layer)
  151. clip.Position(position)
  152. clip.End(end)
  153. clip.scale_x=openshot.Keyframe(scale_x)
  154. clip.scale_y=openshot.Keyframe(scale_y)
  155. clip.location_x=openshot.Keyframe(location_x)
  156. clip.location_y=openshot.Keyframe(location_y)
  157. if ck!=None:
  158. clip.AddEffect(ck)
  159. if audio==True:
  160. clip.has_audio=openshot.Keyframe(1)
  161. else:
  162. clip.has_audio=openshot.Keyframe(0)
  163. return clip
  164. def myunichchar(unicode_char):
  165. mb_string = unicode_char.encode('big5')
  166. try:
  167. unicode_char = unichr(ord(mb_string[0]) << 8 | ord(mb_string[1]))
  168. except NameError:
  169. unicode_char = chr(mb_string[0] << 8 | mb_string[1])
  170. return unicode_char
  171. def file_prepare(name, name_hash,text_content,image_urls):
  172. #save image
  173. try:
  174. os.mkdir(dir_photo+name_hash)
  175. except FileExistsError:
  176. print("Directory " , dir_photo+name_hash , " already exists")
  177. img_num = 1
  178. for imgu in image_urls:
  179. im = Image.open(requests.get(imgu, stream=True).raw)
  180. im.save(dir_photo+name_hash+"/"+str(img_num)+".jpg")
  181. img_num+=1
  182. #save text
  183. text_file = open(dir_text+name_hash+".txt", "w")
  184. text_file.write(text_content)
  185. text_file.close()
  186. print("text file made")
  187. #make mp3
  188. tts = zhtts.TTS()
  189. tts.text2wav(text_content,dir_sound+name_hash+".mp3")
  190. print("mp3 file made")
  191. #make title as image
  192. txt2image(name, dir_title+name_hash+".png")
  193. def get_url_type(url):
  194. req = urllib.request.Request(url, method='HEAD', headers={'User-Agent': 'Mozilla/5.0'})
  195. r = urllib.request.urlopen(req)
  196. contentType = r.getheader('Content-Type')
  197. return contentType
  198. def downloadfile(name,url):
  199. name=name+".mp4"
  200. def make_dir(name_hash):
  201. #save image
  202. try:
  203. os.mkdir(dir_photo+name_hash)
  204. except FileExistsError:
  205. print("~~~~~~Warning~~~~~~~~~Directory " , dir_photo+name_hash , " already exists")
  206. try:
  207. os.mkdir(dir_text+name_hash)
  208. except FileExistsError:
  209. print("~~~~~~Warning~~~~~~~~~Directory " , dir_text+name_hash , " already exists")
  210. try:
  211. os.mkdir(dir_sound+name_hash)
  212. except FileExistsError:
  213. print("~~~~~~Warning~~~~~~~~~Directory " , dir_sound+name_hash , " already exists")
  214. try:
  215. os.mkdir(dir_video+name_hash)
  216. except FileExistsError:
  217. print("~~~~~~Warning~~~~~~~~~Directory " , dir_video+name_hash , " already exists")
  218. try:
  219. os.mkdir(dir_anchor+name_hash)
  220. except FileExistsError:
  221. print("~~~~~~Warning~~~~~~~~~Directory " , dir_anchor+name_hash , " already exists")
  222. try:
  223. os.mkdir(dir_subtitle+name_hash)
  224. except FileExistsError:
  225. print("~~~~~~Warning~~~~~~~~~Directory " , dir_subtitle+name_hash , " already exists")
  226. def file_prepare_v2(name, name_hash,text_content,image_urls):
  227. make_dir(name_hash)
  228. img_num = 1
  229. for imgu in image_urls:
  230. if get_url_type(imgu) =='video/mp4':
  231. r=requests.get(imgu)
  232. f=open(dir_photo+name_hash+"/"+str(img_num)+".mp4",'wb')
  233. for chunk in r.iter_content(chunk_size=255):
  234. if chunk:
  235. f.write(chunk)
  236. f.close()
  237. else:
  238. im = Image.open(requests.get(imgu, stream=True).raw)
  239. im= im.convert("RGB")
  240. im.save(dir_photo+name_hash+"/"+str(img_num)+".jpg")
  241. img_num+=1
  242. #save text
  243. txt_idx=0
  244. for txt in text_content:
  245. text_file = open(dir_text+name_hash+"/"+str(txt_idx)+".txt", "w")
  246. text_file.write(txt)
  247. text_file.close()
  248. txt_idx+=1
  249. print("text file made")
  250. #make mp3
  251. language = 'zh-tw'
  252. txt_idx = 0
  253. for txt in text_content:
  254. tts = zhtts.TTS()
  255. tts.text2wav(txt,dir_sound+name_hash+"/"+str(txt_idx)+".mp3")
  256. txt_idx+=1
  257. print("mp3 file made")
  258. #make title as image
  259. txt2image_title(name, dir_title+name_hash+".png")
  260. def txt2image(content, save_target):
  261. unicode_text = trim_punctuation(content)
  262. font = ImageFont.truetype(font="DFT_B7.ttc", size=38)
  263. text_width, text_height = font.getsize(unicode_text)
  264. canvas = Image.new('RGBA', (700, 500), (255, 0, 0, 0) )
  265. draw = ImageDraw.Draw(canvas)
  266. text= unicode_text
  267. draw.text((5,5), text, (255, 255, 0), font)
  268. canvas.save(save_target, "PNG")
  269. def txt2image_title(content, save_target):
  270. unicode_text = trim_punctuation(content)
  271. font = ImageFont.truetype(font="DFT_B7.ttc", size=28)
  272. text_width, text_height = font.getsize(unicode_text)
  273. canvas = Image.new('RGBA', (510, 500), (255, 0, 0, 0) )
  274. draw = ImageDraw.Draw(canvas)
  275. text= unicode_text
  276. draw.text((5,5), text, (17, 41, 167), font)
  277. canvas.save(save_target, "PNG")
  278. '''
  279. def txt2image_title(content, save_target):
  280. unicode_text =content
  281. font = ImageFont.truetype("font.ttf", 23,encoding='big5')
  282. text_width, text_height = font.getsize(unicode_text)
  283. canvas = Image.new('RGBA', (500, 500), (255, 0, 0, 0) )
  284. draw = ImageDraw.Draw(canvas)
  285. text=''
  286. for c in unicode_text:
  287. if len(re.findall(r'[\u4e00-\u9fff]+', c))>0:
  288. text+=myunichchar(c)
  289. else:
  290. text+=c
  291. draw.text((5,5), text, (17, 41, 167), font)
  292. canvas.save(save_target, "PNG")
  293. '''
  294. def call_achor_video_v2(fileName):
  295. conn = rpyc.classic.connect("192.168.1.105",18812)
  296. ros = conn.modules.os
  297. rsys = conn.modules.sys
  298. fr=open(dir_sound+fileName+".mp3",'rb')# voice
  299. #warning!!! file my be replaced by other process
  300. fw=conn.builtins.open('/tmp/output.mp3','wb')
  301. while True:
  302. b=fr.read(1024)
  303. if b:
  304. fw.write(b)
  305. else:
  306. break
  307. fr.close()
  308. fw.close()
  309. val=random.randint(1000000,9999999)
  310. ros.chdir('/home/jared/to_video')
  311. ros.system('./p6.sh '+str(val)+' &')
  312. while True:
  313. print('waiting...')
  314. if ros.path.exists('/tmp/results/'+str(val)):
  315. break
  316. time.sleep(5)
  317. print('waiting...')
  318. fr=conn.builtins.open('/tmp/results/'+str(val)+'.mp4','rb')
  319. fw=open(dir_anchor+fileName+".mp4",'wb')#peggy1_1
  320. while True:
  321. b=fr.read(1024)
  322. if b:
  323. fw.write(b)
  324. else:
  325. break
  326. fr.close()
  327. fw.close()
  328. def call_achor_video(name):
  329. conn = rpyc.classic.connect("192.168.1.105",18812)
  330. ros = conn.modules.os
  331. rsys = conn.modules.sys
  332. fr=open(dir_sound+name+".mp3",'rb')# voice
  333. #warning!!! file my be replaced by other process
  334. fw=conn.builtins.open('/tmp/output.mp3','wb')
  335. while True:
  336. b=fr.read(1024)
  337. if b:
  338. fw.write(b)
  339. else:
  340. break
  341. fr.close()
  342. fw.close()
  343. val=random.randint(1000000,9999999)
  344. ros.chdir('/home/jared/to_video')
  345. ros.system('./p6.sh '+str(val)+' &')
  346. while True:
  347. print('waiting...')
  348. if ros.path.exists('/tmp/results/'+str(val)):
  349. break
  350. time.sleep(15)
  351. print('waiting...')
  352. fr=conn.builtins.open('/tmp/results/'+str(val)+'.mp4','rb')
  353. fw=open(dir_anchor+name+'.mp4','wb')#peggy1_1
  354. while True:
  355. b=fr.read(1024)
  356. if b:
  357. fw.write(b)
  358. else:
  359. break
  360. fr.close()
  361. fw.close()
  362. print('called..............................................')
  363. def trim_punctuation(s):
  364. pat_block = u'[^\u4e00-\u9fff0-9a-zA-Z]+';
  365. pattern = u'([0-9]+{0}[0-9]+)|{0}'.format(pat_block)
  366. res = re.sub(pattern, lambda x: x.group(1) if x.group(1) else u"" ,s)
  367. return res
  368. def splitter(s):
  369. for sent in re.findall(u'[^!?,。\!\?]+[!?。\!\?]?', s, flags=re.U):
  370. yield sent
  371. def split_by_pun(s):
  372. res = list(splitter(s))
  373. return res
  374. def generate_subtitle_image(name_hash,text_content):
  375. img_list = [None]*len(text_content)
  376. for idx in range(len(text_content)):
  377. img_list[idx]=[]
  378. senList = split_by_pun(text_content[idx])
  379. for inner_idx in range(len(senList)):
  380. sv_path = dir_subtitle + name_hash +'/'+str(idx)+ str(inner_idx) +'.png'
  381. sub = senList[inner_idx]
  382. txt2image(sub,sv_path)
  383. img_list[idx]+=[{"count":len(sub),"path":sv_path}]
  384. return img_list
  385. def anchor_video_v2(name,text_content, image_urls):
  386. ws = create_connection("ws://www.choozmo.com:8888/progress")
  387. progress = 0
  388. m = hashlib.md5()
  389. m.update(name.encode("utf-8"))
  390. name_hash = m.hexdigest()
  391. print('sub image made')
  392. file_prepare_v2(name, name_hash, text_content,image_urls)
  393. progress = 10
  394. ws.send(str(progress))
  395. sub_list=generate_subtitle_image(name_hash,text_content)
  396. progress = 20
  397. ws.send(str(progress))
  398. progress_per_video = int(40/len(text_content))
  399. for fname in range(len(text_content)):
  400. call_achor_video_v2(name_hash+"/"+str(fname))
  401. progress += progress_per_video
  402. ws.send(str(progress))
  403. print('step finish')
  404. print('called............................................')
  405. ck=cKey(0,254,0,150)
  406. ck_anchor=cKey(0,255,1,320)
  407. duration = 0
  408. #average layer level is 3
  409. t = openshot.Timeline(1280, 720, openshot.Fraction(30000, 1000), 44100, 2, openshot.LAYOUT_STEREO)
  410. t.Open()
  411. main_timer = 0
  412. LOGO_OP = openshot.FFmpegReader(dir_video+"LOGO_OP.mp4")
  413. LOGO_OP.Open() # Open the reader
  414. LOGO_OP_clip = video_photo_clip(vid=LOGO_OP,layer=4,position=0,end=LOGO_OP.info.duration
  415. ,location_y=-0.03,scale_x=0.8,scale_y=0.71)
  416. t.AddClip(LOGO_OP_clip)
  417. bg_head = openshot.FFmpegReader(dir_video+"bg_head.avi")
  418. bg_head.Open()
  419. bg_head_clip = video_photo_clip(vid=bg_head,layer=2,position=0,end=LOGO_OP.info.duration,ck=ck)
  420. t.AddClip(bg_head_clip)
  421. main_timer += LOGO_OP.info.duration
  422. head_duration = LOGO_OP.info.duration
  423. bg_head.Close()
  424. LOGO_OP.Close()
  425. progress += 10
  426. clip_duration=0
  427. photo_clip_list = [None]*len(text_content)
  428. img_list = [None]*len(text_content)
  429. anchor_clip_list = [None] * len(text_content)
  430. anchor_list = [None] * len(text_content)
  431. audio_clip_list = [None] * len(text_content)
  432. audio_list = [None] * len(text_content)
  433. sub_clip_list = [None] * len(text_content)
  434. sub_img_list = [None] * len(text_content)
  435. idx = 0
  436. for p in listdir(dir_photo+name_hash):
  437. anchor_list[idx] = openshot.FFmpegReader(dir_anchor+name_hash+"/"+str(idx)+".mp4")
  438. clip_duration = anchor_list[idx].info.duration
  439. anchor_list[idx].Open()
  440. anchor_clip_list[idx] = video_photo_clip(vid=anchor_list[idx],layer=4,scale_x=0.65,scale_y=0.65,
  441. location_x=0.35,location_y=0.25,position=main_timer, end=clip_duration,ck=ck_anchor,audio=False)
  442. t.AddClip(anchor_clip_list[idx])
  443. img_list[idx] = openshot.FFmpegReader(dir_photo+name_hash+'/'+p)
  444. img_list[idx].Open()
  445. photo_clip_list[idx] = video_photo_clip(vid=img_list[idx],layer=3
  446. ,scale_x=0.81,scale_y=0.68,location_y=-0.03,position=main_timer,end=clip_duration,audio=False)
  447. t.AddClip(photo_clip_list[idx])
  448. img_list[idx].Close()
  449. audio_list[idx] = openshot.FFmpegReader(dir_sound+name_hash+"/"+str(idx)+".mp3")
  450. audio_list[idx].Open()
  451. audio_clip_list[idx] = openshot.Clip(audio_list[idx])
  452. audio_clip_list[idx].Position(main_timer)
  453. audio_clip_list[idx].End(clip_duration)
  454. t.AddClip(audio_clip_list[idx])
  455. img_list[idx].Close()
  456. anchor_list[idx].Close()
  457. audio_list[idx].Close()
  458. sub_img_list[idx] = [None] * len(sub_list[idx])
  459. sub_clip_list[idx] = [None] * len(sub_list[idx])
  460. sub_timer = 0
  461. for sub_idx in range(len(sub_list[idx])):
  462. sub_img_list[idx][sub_idx] = openshot.QtImageReader(sub_list[idx][sub_idx]['path'])
  463. sub_img_list[idx][sub_idx].Open()
  464. sub_duration = 0.205*sub_list[idx][sub_idx]['count']
  465. 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)
  466. t.AddClip(sub_clip_list[idx][sub_idx])
  467. sub_img_list[idx][sub_idx].Close()
  468. sub_timer += sub_duration
  469. print(sub_list[idx][sub_idx]['path'])
  470. main_timer += clip_duration
  471. idx+=1
  472. progress+=10
  473. ws.send(str(progress))
  474. LOGO_ED = openshot.FFmpegReader(dir_video+"LOGO_ED.avi")
  475. LOGO_ED.Open()
  476. LOGO_ED_clip = video_photo_clip(vid=LOGO_ED,layer=4,position=main_timer,end=LOGO_ED.info.duration
  477. ,location_y=-0.03,scale_x=0.8,scale_y=0.71)
  478. t.AddClip(LOGO_ED_clip)
  479. ED_duration = LOGO_ED.info.duration
  480. LOGO_ED.Close()
  481. bg = openshot.FFmpegReader(dir_video+"bg.mp4")
  482. bg.Open()
  483. bg_times = math.floor(main_timer+ED_duration/bg.info.duration)
  484. left_time = (main_timer+ED_duration) % bg.info.duration
  485. bg_clip_list = [None] * bg_times
  486. bg_list = [None] * bg_times
  487. bg.Close()
  488. bg_timer = head_duration
  489. for idx in range(bg_times):
  490. bg_list[idx] = openshot.FFmpegReader(dir_video+"bg.mp4")
  491. bg_list[idx].Open()
  492. bg_clip_list[idx] = video_photo_clip(bg_list[idx],layer=2,position=bg_timer
  493. ,end=bg_list[idx].info.duration,ck=ck)
  494. t.AddClip(bg_clip_list[idx])
  495. bg_timer += bg_list[idx].info.duration
  496. bg_list[idx].Close()
  497. bg_left = openshot.FFmpegReader(dir_video+"bg.mp4")
  498. bg_left.Open()
  499. bg_left_clip = video_photo_clip(bg_left,layer=2,position=bg_timer,end=left_time,ck=ck)
  500. t.AddClip(bg_left_clip)
  501. bg_left.Close()
  502. title = openshot.QtImageReader(dir_title+name_hash+".png")
  503. title.Open() # Open the reader
  504. title_clip = video_photo_clip(vid=title, layer=4,location_x=-0.047, location_y=0.801,position=0,end=head_duration+main_timer)
  505. t.AddClip(title_clip)
  506. ####start building
  507. w = openshot.FFmpegWriter("../html/"+name_hash+".mp4")
  508. w.SetAudioOptions(True, "aac", 44100, 2, openshot.LAYOUT_STEREO, 3000000)
  509. w.SetVideoOptions(True, "libx264", openshot.Fraction(30000, 1000), 1280, 720,
  510. openshot.Fraction(1, 1), False, False, 3000000)
  511. w.Open()
  512. #may change duration into t.info.duration
  513. for n in range(int(t.info.fps)*int(head_duration+main_timer+ED_duration)):
  514. f=t.GetFrame(n)
  515. w.WriteFrame(f)
  516. t.Close()
  517. w.Close()
  518. print("Raw Video done")
  519. print("video at : www.choozmo.com:8168/"+name_hash+".mp4")
  520. progress = 100
  521. ws.send(str(progress))
  522. ws.close()
  523. #line notifs
  524. notify_group(name+"的影片已經產生完成囉! www.choozmo.com:8168/"+name_hash+".mp4")