main.py 20 KB

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