Uniaff commited on
Commit
1b46b89
·
verified ·
1 Parent(s): 8aca7f6

Update inference.py

Browse files
Files changed (1) hide show
  1. inference.py +14 -11
inference.py CHANGED
@@ -268,7 +268,7 @@ def main():
268
 
269
  if not args.audio.endswith('.wav'):
270
  print('Extracting raw audio...')
271
- temp_wav = 'temp/temp.wav'
272
  command = f'ffmpeg -y -i "{args.audio}" -strict -2 "{temp_wav}"'
273
  subprocess.call(command, shell=True)
274
  args.audio = temp_wav
@@ -307,11 +307,13 @@ def main():
307
  if args.save_as_video:
308
  frame_sample = next(reader)
309
  frame_h, frame_w = frame_sample.shape[:2]
310
- out = cv2.VideoWriter('temp/result.avi',
 
 
311
  cv2.VideoWriter_fourcc(*'DIVX'), fps, (frame_w, frame_h))
312
  if args.save_frames:
313
- gt_out = cv2.VideoWriter("temp/gt.avi", cv2.VideoWriter_fourcc(*'DIVX'), fps, (384, 384))
314
- pred_out = cv2.VideoWriter("temp/pred.avi", cv2.VideoWriter_fourcc(*'DIVX'), fps, (96, 96))
315
  else:
316
  out = None
317
  gt_out = None
@@ -327,7 +329,7 @@ def main():
327
  pred = model(mel_batch, img_batch)
328
 
329
  pred = pred.cpu().numpy().transpose(0, 2, 3, 1) * 255.0
330
-
331
  for p, f, c in zip(pred, frames, coords):
332
  y1, y2, x1, x2 = c
333
 
@@ -364,16 +366,17 @@ def main():
364
  if out:
365
  out.release()
366
 
367
- # Объединение аудио и видео
368
- final_command = f'ffmpeg -y -i "{args.audio}" -i "temp/result.avi" -strict -2 -q:v 1 "{args.outfile}"'
369
- subprocess.call(final_command, shell=(platform.system() != 'Windows'))
370
-
 
371
  if args.save_frames and args.save_as_video:
372
  gt_out.release()
373
  pred_out.release()
374
 
375
- gt_video_cmd = f'ffmpeg -y -i "temp/gt.avi" -i "{args.audio}" -strict -2 -q:v 1 "{args.gt_path}"'
376
- pred_video_cmd = f'ffmpeg -y -i "temp/pred.avi" -i "{args.audio}" -strict -2 -q:v 1 "{args.pred_path}"'
377
 
378
  subprocess.call(gt_video_cmd, shell=(platform.system() != 'Windows'))
379
  subprocess.call(pred_video_cmd, shell=(platform.system() != 'Windows'))
 
268
 
269
  if not args.audio.endswith('.wav'):
270
  print('Extracting raw audio...')
271
+ temp_wav = os.path.join(os.path.dirname(args.outfile), 'temp.wav')
272
  command = f'ffmpeg -y -i "{args.audio}" -strict -2 "{temp_wav}"'
273
  subprocess.call(command, shell=True)
274
  args.audio = temp_wav
 
307
  if args.save_as_video:
308
  frame_sample = next(reader)
309
  frame_h, frame_w = frame_sample.shape[:2]
310
+ # Определяем путь для result.avi в той же директории, что и outfile
311
+ result_avi = os.path.join(os.path.dirname(args.outfile), "result.avi")
312
+ out = cv2.VideoWriter(result_avi,
313
  cv2.VideoWriter_fourcc(*'DIVX'), fps, (frame_w, frame_h))
314
  if args.save_frames:
315
+ gt_out = cv2.VideoWriter(os.path.join(os.path.dirname(args.outfile), "gt.avi"), cv2.VideoWriter_fourcc(*'DIVX'), fps, (384, 384))
316
+ pred_out = cv2.VideoWriter(os.path.join(os.path.dirname(args.outfile), "pred.avi"), cv2.VideoWriter_fourcc(*'DIVX'), fps, (96, 96))
317
  else:
318
  out = None
319
  gt_out = None
 
329
  pred = model(mel_batch, img_batch)
330
 
331
  pred = pred.cpu().numpy().transpose(0, 2, 3, 1) * 255.0
332
+
333
  for p, f, c in zip(pred, frames, coords):
334
  y1, y2, x1, x2 = c
335
 
 
366
  if out:
367
  out.release()
368
 
369
+ # Определение пути к result.avi
370
+ if args.save_as_video:
371
+ final_command = f'ffmpeg -y -i "{args.audio}" -i "{result_avi}" -strict -2 -q:v 1 "{args.outfile}"'
372
+ subprocess.call(final_command, shell=(platform.system() != 'Windows'))
373
+
374
  if args.save_frames and args.save_as_video:
375
  gt_out.release()
376
  pred_out.release()
377
 
378
+ gt_video_cmd = f'ffmpeg -y -i "{os.path.join(os.path.dirname(args.outfile), "gt.avi")}" -i "{args.audio}" -strict -2 -q:v 1 "{args.gt_path}"'
379
+ pred_video_cmd = f'ffmpeg -y -i "{os.path.join(os.path.dirname(args.outfile), "pred.avi")}" -i "{args.audio}" -strict -2 -q:v 1 "{args.pred_path}"'
380
 
381
  subprocess.call(gt_video_cmd, shell=(platform.system() != 'Windows'))
382
  subprocess.call(pred_video_cmd, shell=(platform.system() != 'Windows'))