ziqiangao commited on
Commit
12bad8b
·
verified ·
1 Parent(s): e50325c

update console progress

Browse files
Files changed (1) hide show
  1. app.py +12 -16
app.py CHANGED
@@ -194,28 +194,22 @@ def stripinvisibles(s):
194
 
195
  def start_progress(title):
196
  global progress_x
197
- sys.stdout.write(title + ": [" + "-"*40 + "] 0%")
198
- sys.stdout.write(chr(8) * 44) # Move the cursor back to the start of the progress bar
199
  sys.stdout.flush()
200
  progress_x = 0
201
 
202
  def progress(x):
203
  global progress_x
204
- x = int(x * 40 // 100)
205
- percent_complete = int(x / 40 * 100)
206
- sys.stdout.write("#" * (x - progress_x))
207
- sys.stdout.write(" " * (40 - x) + "] " + f"{percent_complete}%")
208
- sys.stdout.write(chr(8) * (44 + len(str(percent_complete)) + 1)) # Move the cursor back to the start of the progress bar
209
  sys.stdout.flush()
210
  progress_x = x
211
 
212
  def end_progress():
213
- global progress_x
214
- sys.stdout.write("#" * (40 - progress_x) + "] 100%\n")
215
  sys.stdout.flush()
216
 
217
 
218
-
219
  haslyrics = False
220
 
221
 
@@ -294,7 +288,7 @@ def main(file, name, fps=30, res: tuple = (1280, 720), oscres=512, sr=11025, lyr
294
  # Prepare parameters for each frame
295
  params = [(n, samples_array, cover_img, title, artist, dominant_color,
296
  width, height, fps, name, oscres, sr) for n in range(num_frames)]
297
- print('---------------------------------------------------------')
298
  print('Info:' + "External" if img else "ID3")
299
  print("Title: " + title)
300
  print("Artist: " + artist)
@@ -303,7 +297,7 @@ def main(file, name, fps=30, res: tuple = (1280, 720), oscres=512, sr=11025, lyr
303
  print('Framerate: ' + str(fps))
304
  print('Frame Count: ' + str(num_frames))
305
  print('Segments per frame: ' + str(oscres))
306
- print('---------------------------------------------------------')
307
  start_progress("Rendering:")
308
  try:
309
  with Pool(cpu_count()-1) as pool:
@@ -312,7 +306,7 @@ def main(file, name, fps=30, res: tuple = (1280, 720), oscres=512, sr=11025, lyr
312
  for _ in pool.imap_unordered(render_frame, params):
313
  iii += 1 # Increment frame count for progress
314
  p((iii, num_frames), desc="Rendering Frames")
315
- progress(iii/num_frames*100)
316
 
317
  except Exception as e:
318
  raise gr.Error("Something went wrong whilst rendering")
@@ -321,7 +315,7 @@ def main(file, name, fps=30, res: tuple = (1280, 720), oscres=512, sr=11025, lyr
321
 
322
  p = gr.Progress()
323
  p(0, desc="Compiling video")
324
- print('---------------------------------------------------------')
325
  print('FFMPEG')
326
  if haslyrics:
327
  ffmpeg_cmd = [
@@ -355,6 +349,7 @@ def main(file, name, fps=30, res: tuple = (1280, 720), oscres=512, sr=11025, lyr
355
  # Regular expression to match frame information
356
  frame_re = re.compile(r"frame=\s*(\d+)")
357
  p = gr.Progress()
 
358
  while True:
359
  output = process.stderr.readline()
360
  if output == '' and process.poll() is not None:
@@ -365,11 +360,12 @@ def main(file, name, fps=30, res: tuple = (1280, 720), oscres=512, sr=11025, lyr
365
  if match:
366
  frame = match.group(1)
367
  p((int(frame), num_frames), desc="Compiling Video")
368
- print(f"Frame: {frame}")
369
 
370
  # Wait for the process to complete
371
  process.wait()
372
- print('---------------------------------------------------------')
 
373
  return f"{name}.mp4", haslyrics
374
 
375
 
 
194
 
195
  def start_progress(title):
196
  global progress_x
197
+ sys.stdout.write(f"{title}:\n")
198
+ sys.stdout.write(f"[{'-'*60}] 0%\r")
199
  sys.stdout.flush()
200
  progress_x = 0
201
 
202
  def progress(x):
203
  global progress_x
204
+ sys.stdout.write(f"[{'#'*round(60*x)}{'-'*(60-round(60*x))}] {x:.2%}\r")
 
 
 
 
205
  sys.stdout.flush()
206
  progress_x = x
207
 
208
  def end_progress():
209
+ sys.stdout.write(f"[{'#'*60}] 100.00%\r\n")
 
210
  sys.stdout.flush()
211
 
212
 
 
213
  haslyrics = False
214
 
215
 
 
288
  # Prepare parameters for each frame
289
  params = [(n, samples_array, cover_img, title, artist, dominant_color,
290
  width, height, fps, name, oscres, sr) for n in range(num_frames)]
291
+ print('-'*50)
292
  print('Info:' + "External" if img else "ID3")
293
  print("Title: " + title)
294
  print("Artist: " + artist)
 
297
  print('Framerate: ' + str(fps))
298
  print('Frame Count: ' + str(num_frames))
299
  print('Segments per frame: ' + str(oscres))
300
+ print('-'*50)
301
  start_progress("Rendering:")
302
  try:
303
  with Pool(cpu_count()-1) as pool:
 
306
  for _ in pool.imap_unordered(render_frame, params):
307
  iii += 1 # Increment frame count for progress
308
  p((iii, num_frames), desc="Rendering Frames")
309
+ progress(iii/num_frames)
310
 
311
  except Exception as e:
312
  raise gr.Error("Something went wrong whilst rendering")
 
315
 
316
  p = gr.Progress()
317
  p(0, desc="Compiling video")
318
+ print('-'*50)
319
  print('FFMPEG')
320
  if haslyrics:
321
  ffmpeg_cmd = [
 
349
  # Regular expression to match frame information
350
  frame_re = re.compile(r"frame=\s*(\d+)")
351
  p = gr.Progress()
352
+ start_progress('Compliling video')
353
  while True:
354
  output = process.stderr.readline()
355
  if output == '' and process.poll() is not None:
 
360
  if match:
361
  frame = match.group(1)
362
  p((int(frame), num_frames), desc="Compiling Video")
363
+ progress(int(frame)/num_frames)
364
 
365
  # Wait for the process to complete
366
  process.wait()
367
+ end_progress()
368
+ print('-'*50)
369
  return f"{name}.mp4", haslyrics
370
 
371