Spaces:
Running
Running
ziqiangao
commited on
Commit
·
d782c33
1
Parent(s):
5055ee4
update app.py
Browse files
app.py
CHANGED
@@ -162,14 +162,21 @@ def main(file, name, fps=30, res: tuple=(1280,720), oscres=512, sr=11025, lyrics
|
|
162 |
p = gr.Progress()
|
163 |
if os.path.exists("out.srt"):
|
164 |
os.remove("out.srt")
|
|
|
165 |
if lyrics:
|
166 |
p(0.5,"parsing lyrics")
|
167 |
try:
|
|
|
168 |
sf = open(lyrics, encoding="UTF8").read()
|
169 |
-
if sf[
|
170 |
-
|
171 |
-
|
172 |
-
outf
|
|
|
|
|
|
|
|
|
|
|
173 |
else:
|
174 |
gr.Warning("Lyrics file is invalid, skipping")
|
175 |
except:
|
@@ -223,18 +230,35 @@ def main(file, name, fps=30, res: tuple=(1280,720), oscres=512, sr=11025, lyrics
|
|
223 |
p = gr.Progress()
|
224 |
p(0.5,desc="Compiling video")
|
225 |
print('FFMPEG')
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
238 |
]
|
239 |
subprocess.run(ffmpeg_cmd)
|
240 |
|
|
|
162 |
p = gr.Progress()
|
163 |
if os.path.exists("out.srt"):
|
164 |
os.remove("out.srt")
|
165 |
+
lyrics = False
|
166 |
if lyrics:
|
167 |
p(0.5,"parsing lyrics")
|
168 |
try:
|
169 |
+
outf = open("out.srt",mode="x", encoding="UTF8")
|
170 |
sf = open(lyrics, encoding="UTF8").read()
|
171 |
+
if sf[0] == '[':
|
172 |
+
gr.Info("Lyrics of LRC type was detected, converting to SRT")
|
173 |
+
LRC2SRT.convert_to_srt(sf)
|
174 |
+
outf.write('\n'.join(LRC2SRT.SRT))
|
175 |
+
lyrics = True
|
176 |
+
elif sf[0].isdigit():
|
177 |
+
outf.write(sf)
|
178 |
+
gr.Info("Lyrics of SRT type was detected")
|
179 |
+
lyrics = True
|
180 |
else:
|
181 |
gr.Warning("Lyrics file is invalid, skipping")
|
182 |
except:
|
|
|
230 |
p = gr.Progress()
|
231 |
p(0.5,desc="Compiling video")
|
232 |
print('FFMPEG')
|
233 |
+
if lyrics:
|
234 |
+
ffmpeg_cmd = [
|
235 |
+
"ffmpeg",
|
236 |
+
'-framerate', '30',
|
237 |
+
'-i', path + f'out/{name}/%d.png', # Input PNG images
|
238 |
+
'-i', file, # Input MP3 audio
|
239 |
+
'-i', path + 'out.srt', # Input SRT subtitles
|
240 |
+
'-c:v', 'libx264',
|
241 |
+
'-r', '30',
|
242 |
+
'-pix_fmt', 'yuv420p',
|
243 |
+
'-c:a', 'aac',
|
244 |
+
'-c:s', 'mov_text', # Use mov_text codec for subtitles
|
245 |
+
'-shortest',
|
246 |
+
'-y',
|
247 |
+
path + f'{name}.mp4' # Output MP4 filename
|
248 |
+
]
|
249 |
+
else:
|
250 |
+
ffmpeg_cmd = [
|
251 |
+
"ffmpeg",
|
252 |
+
'-framerate', '30',
|
253 |
+
'-i', path+f'out/{name}/%d.png', # Input PNG images
|
254 |
+
'-i', f'{file}', # Input MP3 audio
|
255 |
+
'-c:v', 'libx264',
|
256 |
+
'-r', '30',
|
257 |
+
'-pix_fmt', 'yuv420p',
|
258 |
+
'-c:a', 'aac',
|
259 |
+
'-shortest',
|
260 |
+
'-y',
|
261 |
+
path+f'{name}.mp4' # Output MP4 filename
|
262 |
]
|
263 |
subprocess.run(ffmpeg_cmd)
|
264 |
|