-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
98 lines (86 loc) · 2.26 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import pysrt
from cv2 import cv2
import cliptest
import audio
import os
#import re
srt = pysrt.open("input.srt")
video="movie.mp4"
use_effect=True
music=False
def writerpy(msg):
file = open("script.rpy","a",encoding="utf-8")
file.write(str(msg))
file.write("\n")
file.close()
def chack_rpy():
if os.path.exists("script.rpy"):
os.remove("script.rpy")
def get_video_duration(filename):
cap = cv2.VideoCapture(filename)
if cap.isOpened():
rate = cap.get(5)
frame_num =cap.get(7)
duration = frame_num/rate
return duration
return -1
def getallfps(v):
cap=cv2.VideoCapture(video)
return cap.get(7)
def get_f_t(label_t):
timestr=str(label_t)
timel1=timestr.split(",")
timel2=timel1[0]
timel2=timel2.split(":")
timems=int(timel1[1])/1000
time=timems+int(timel2[2])+int(timel2[1])*60+int(timel2[0])*60*60
return time
def get_fps(st,nt,alltime,allfps):
start=get_f_t(st)
end=get_f_t(nt)
belance=(start+end)/2
per=belance/alltime
fps=per*allfps
return int(fps)
def use(t,n):
a=t.split(n)
return "".join(a)
def cn(text):
#a=use(text, "'")
b=use(text, '"')
b=use(b, "\n")
return b
if __name__=="__main__":
chack_rpy()
audio.get_audio(video)
#prepare start
writerpy("label start:")
if music:
writerpy(" "*4+"play music bgm")
#end
ftp=0
L=[]
vl=get_video_duration(video)
vf=getallfps(video)
for i in range(len(srt)):
content = srt.data[i]
#print(content.text_without_tags)
texts=content.text_without_tags
if texts.find("{")==-1:
ftp+=1
audio.cut_audio(ftp, get_f_t(content.start), get_f_t(content.end))
si=get_fps(content.start,content.end,vl,vf)
#print(si)
L.append(si)
if use_effect:
writerpy(" "*4+"show b"+str(ftp)+" with dissolve")
else:
writerpy(" "*4+"show b"+str(ftp))
writerpy(" "*4+"voice '/audio/a"+str(ftp)+".mp3'")
writerpy(" "*4+'"'+cn(texts)+'"')
if ftp!=1:
writerpy(" "*4+"hide b"+str(ftp-1))
print(L)
cliptest.getpic(L,video)
#for i in range(len(L)):
writerpy(" "*4+"return")