|
@@ -18,6 +18,10 @@ import zipfile
|
|
|
import csv
|
|
|
from datetime import datetime
|
|
|
import rarfile
|
|
|
+import gspread
|
|
|
+from oauth2client.service_account import ServiceAccountCredentials
|
|
|
+import fire
|
|
|
+
|
|
|
def cKey(r,g,b,fuzz):
|
|
|
col=openshot.Color()
|
|
|
col.red=openshot.Keyframe(r)
|
|
@@ -97,7 +101,7 @@ def download_mp4(url):
|
|
|
|
|
|
|
|
|
|
|
|
-def text_to_short_vedio_create(read_csv_use="導盲犬協會.csv",pwd_use="導盲犬協會影片素材2/",op="input_self/LOGO_OP_4.mp4",ed="input_self/LOGO_ED.mp4",bg="input_self/xchoozmo_long.mp4",input_zip="input/input_data.zip"):
|
|
|
+def text_to_short_vedio_create(op="input_self/LOGO_OP_4.mp4",ed="input_self/LOGO_ED.mp4",bg="input_self/xchoozmo_long.mp4",input_zip="input/input_data.zip",save_type="excel"):
|
|
|
|
|
|
|
|
|
files=os.listdir("input/")
|
|
@@ -280,8 +284,12 @@ def text_to_short_vedio_create(read_csv_use="導盲犬協會.csv",pwd_use="導
|
|
|
locals()['anchor_music'+str(i)].Close()
|
|
|
|
|
|
if str(csv_use.loc[i,['是否要場景']].values[0])=="是":
|
|
|
- scale_x_use = 0.59
|
|
|
- scale_y_use = 0.59
|
|
|
+ # scale_x_use = 0.59
|
|
|
+ # scale_y_use = 0.59
|
|
|
+ scale_x_use = 0.8
|
|
|
+ scale_y_use = 0.82
|
|
|
+ location_x_choose=0
|
|
|
+ location_y_choose=-0.039
|
|
|
|
|
|
else:
|
|
|
scale_x_use = 1
|
|
@@ -332,6 +340,10 @@ def text_to_short_vedio_create(read_csv_use="導盲犬協會.csv",pwd_use="導
|
|
|
t.AddClip(locals()['anchor_clip_bg'])
|
|
|
locals()['anchor_bg'].Close()
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ # locals()['anchor_ad'] = openshot.FFmpegReader('input_self/puuet主播_long.mp4')
|
|
|
locals()['anchor_ad'] = openshot.FFmpegReader('input_self/AI_girl/ai_spokesgirl.mp4')
|
|
|
locals()['anchor_ad'].Open()
|
|
|
locals()['anchor_clip_ad'] = video_photo_clip(video=locals()['anchor_ad'],layer=6,scale_x=0.8,scale_y=0.8,
|
|
@@ -387,6 +399,11 @@ def text_to_short_vedio_create(read_csv_use="導盲犬協會.csv",pwd_use="導
|
|
|
os.mkdir('input')
|
|
|
shutil.rmtree('input_self/AI_girl')
|
|
|
os.mkdir('input_self/AI_girl')
|
|
|
+ if save_type=="excel":
|
|
|
+ vedio_to_csv()
|
|
|
+ elif save_type=="sheet":
|
|
|
+ vedio_to_sheet()
|
|
|
+
|
|
|
return True
|
|
|
#文字轉圖片
|
|
|
def txt2image(content, save_target,lang='zh',size=26,fon="input_self/font/DFT_B7.ttc"):
|
|
@@ -434,12 +451,12 @@ def text_border(draw,x,y,text,font,shadowcolor,fillcolor):
|
|
|
# now draw the text over it
|
|
|
draw.text((x, y), text, font=font, fill=fillcolor)
|
|
|
|
|
|
-def srt_to_csv(srt_file):
|
|
|
+def srt_to_csv(srt_file,sound_file="output/csv_produce/test.csv"):
|
|
|
subs = pysrt.open(srt_file)
|
|
|
|
|
|
|
|
|
# csv_file = srt_file.split('.')[0] + ".csv"
|
|
|
- with open("output/csv_produce/test.csv", 'w', newline='',encoding="big5") as csvfile:
|
|
|
+ with open(sound_file, 'w', newline='',encoding="big5") as csvfile:
|
|
|
# 建立 CSV 檔寫入器
|
|
|
writer = csv.writer(csvfile)
|
|
|
writer.writerow(["序號","開始時間","結束時間","字幕內容"])
|
|
@@ -528,16 +545,66 @@ def text_to_short_vedio(mp4_file ,sound_file,output_filename,text_font):
|
|
|
# os.mkdir('input_self/tmp')
|
|
|
# shutil.rmtree('input_self/tmp1')
|
|
|
# os.mkdir('input_self/tmp1')
|
|
|
-def vedio_to_csv(sound_file):
|
|
|
+def auth_gss_client(path, scopes):
|
|
|
+ credentials = ServiceAccountCredentials.from_json_keyfile_name(path, scopes)
|
|
|
+ return gspread.authorize(credentials)
|
|
|
+
|
|
|
+
|
|
|
+auth_json_path = 'noted-tesla-348011-74f70c9caeda.json' #由剛剛建立出的憑證,放置相同目錄以供引入
|
|
|
+gss_scopes = ['https://spreadsheets.google.com/feeds'] #我們想要取用的範圍
|
|
|
+gss_client = auth_gss_client(auth_json_path, gss_scopes) #呼叫我們的函式
|
|
|
+
|
|
|
+#從剛剛建立的sheet,把網址中 https://docs.google.com/spreadsheets/d/〔key〕/edit 的 〔key〕的值代入
|
|
|
+spreadsheet_key_path = '1LU5O8-oAotIFGPI9STPbElO0NHGA6eynuv9sYz81aOw'
|
|
|
+wks = gss_client.open_by_key(spreadsheet_key_path).sheet1
|
|
|
+
|
|
|
+def srt_to_sheet(srt_file):
|
|
|
+ subs = pysrt.open(srt_file)
|
|
|
+ wks.clear()
|
|
|
+
|
|
|
+ index = 0
|
|
|
+ for context in subs:
|
|
|
+ index = context.index
|
|
|
+
|
|
|
+ cell_list = wks.range('A1:C'+str(index))
|
|
|
+
|
|
|
+ number = 0
|
|
|
+ for context in subs:
|
|
|
+ #print(context.start.minutes*60+context.start.seconds+ 0.001*context.start.milliseconds)
|
|
|
+ index = context.index
|
|
|
+ end = context.end
|
|
|
+ start = context.start
|
|
|
+ #print('A'+str(index))
|
|
|
+ cell_list[number].value = str(start)
|
|
|
+ cell_list[number+1].value = str(end)
|
|
|
+ cell_list[number+2].value = str(context.text)
|
|
|
+ number = number+3
|
|
|
+
|
|
|
+ wks.update_cells(cell_list)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+def vedio_to_csv(sound_file = "output/no_captions/test.mp4"):
|
|
|
+ cmd = "autosub -S zh-TW -D zh-TW " + sound_file
|
|
|
+ os.system(cmd)
|
|
|
+ sound_srt_file = sound_file.split('.')[0] + ".srt"
|
|
|
+ srt_to_csv(sound_srt_file,sound_file)
|
|
|
+
|
|
|
+def vedio_to_sheet():
|
|
|
cmd = "autosub -S zh-TW -D zh-TW " + sound_file
|
|
|
os.system(cmd)
|
|
|
sound_srt_file = sound_file.split('.')[0] + ".srt"
|
|
|
- srt_to_csv(sound_srt_file)
|
|
|
+ srt_to_sheet(sound_srt_file)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
- # down=text_to_short_vedio_create()
|
|
|
- # if down:
|
|
|
- # vedio_to_csv("output/no_captions/test.mp4")
|
|
|
- vedio_to_csv("output/no_captions/test.mp4")
|
|
|
+ # fire.Fire()
|
|
|
+ fire.Fire(text_to_short_vedio_create(
|
|
|
+ op="input_self/LOGO_OP_4.mp4",
|
|
|
+ ed="input_self/LOGO_ED.mp4",
|
|
|
+ bg="input_self/xchoozmo_long.mp4",
|
|
|
+ input_zip="input/input_data.zip",
|
|
|
+ save_type="excel"))
|
|
|
+
|
|
|
+ # vedio_to_csv("output/no_captions/test.mp4")
|
|
|
|
|
|
|