main.py 20 KB

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