Spaces:
Runtime error
Runtime error
update temp folder path
Browse files- wav2lip/inference.py +8 -6
wav2lip/inference.py
CHANGED
@@ -25,7 +25,7 @@ parser.add_argument('--static', type=bool,
|
|
25 |
parser.add_argument('--fps', type=float, help='Can be specified only if input is a static image (default: 25)',
|
26 |
default=25., required=False)
|
27 |
|
28 |
-
parser.add_argument('--pads', nargs='+', type=int, default=[0,
|
29 |
help='Padding (top, bottom, left, right). Please adjust to include chin at least')
|
30 |
|
31 |
parser.add_argument('--face_det_batch_size', type=int,
|
@@ -56,6 +56,8 @@ args.img_size = 96
|
|
56 |
if os.path.isfile(args.face) and args.face.split('.')[1] in ['jpg', 'png', 'jpeg']:
|
57 |
args.static = True
|
58 |
|
|
|
|
|
59 |
|
60 |
def get_smoothened_boxes(boxes, T):
|
61 |
for i in range(len(boxes)):
|
@@ -91,7 +93,7 @@ def face_detect(images):
|
|
91 |
pady1, pady2, padx1, padx2 = args.pads
|
92 |
for rect, image in zip(predictions, images):
|
93 |
if rect is None:
|
94 |
-
cv2.imwrite('
|
95 |
raise ValueError('Face not detected! Ensure the video contains a face in all the frames.')
|
96 |
|
97 |
y1 = max(0, rect[1] - pady1)
|
@@ -224,10 +226,10 @@ def main():
|
|
224 |
|
225 |
if not args.audio.endswith('.wav'):
|
226 |
print('Extracting raw audio...')
|
227 |
-
command = 'ffmpeg -y -i {} -strict -2 {}'.format(args.audio, '
|
228 |
|
229 |
subprocess.call(command, shell=True)
|
230 |
-
args.audio = '
|
231 |
|
232 |
wav = audio.load_wav(args.audio, 16000)
|
233 |
mel = audio.melspectrogram(wav)
|
@@ -262,7 +264,7 @@ def main():
|
|
262 |
print("Model loaded")
|
263 |
|
264 |
frame_h, frame_w = full_frames[0].shape[:-1]
|
265 |
-
out = cv2.VideoWriter('/
|
266 |
cv2.VideoWriter_fourcc(*'DIVX'), fps, (frame_w, frame_h))
|
267 |
|
268 |
img_batch = torch.FloatTensor(np.transpose(img_batch, (0, 3, 1, 2))).to(device)
|
@@ -282,7 +284,7 @@ def main():
|
|
282 |
|
283 |
out.release()
|
284 |
|
285 |
-
command = 'ffmpeg -y -i {} -i {} -strict -2 -q:v 1 {}'.format(args.audio, '/
|
286 |
subprocess.call(command, shell=platform.system() != 'Windows')
|
287 |
|
288 |
|
|
|
25 |
parser.add_argument('--fps', type=float, help='Can be specified only if input is a static image (default: 25)',
|
26 |
default=25., required=False)
|
27 |
|
28 |
+
parser.add_argument('--pads', nargs='+', type=int, default=[0, 20, 0, 0],
|
29 |
help='Padding (top, bottom, left, right). Please adjust to include chin at least')
|
30 |
|
31 |
parser.add_argument('--face_det_batch_size', type=int,
|
|
|
56 |
if os.path.isfile(args.face) and args.face.split('.')[1] in ['jpg', 'png', 'jpeg']:
|
57 |
args.static = True
|
58 |
|
59 |
+
folder_path = os.path.dirname(args.outfile)
|
60 |
+
|
61 |
|
62 |
def get_smoothened_boxes(boxes, T):
|
63 |
for i in range(len(boxes)):
|
|
|
93 |
pady1, pady2, padx1, padx2 = args.pads
|
94 |
for rect, image in zip(predictions, images):
|
95 |
if rect is None:
|
96 |
+
cv2.imwrite(f'{folder_path}/faulty_frame.jpg', image) # check this frame where the face was not detected.
|
97 |
raise ValueError('Face not detected! Ensure the video contains a face in all the frames.')
|
98 |
|
99 |
y1 = max(0, rect[1] - pady1)
|
|
|
226 |
|
227 |
if not args.audio.endswith('.wav'):
|
228 |
print('Extracting raw audio...')
|
229 |
+
command = 'ffmpeg -y -i {} -strict -2 {}'.format(args.audio, f'{folder_path}/temp.wav')
|
230 |
|
231 |
subprocess.call(command, shell=True)
|
232 |
+
args.audio = f'{folder_path}/temp.wav'
|
233 |
|
234 |
wav = audio.load_wav(args.audio, 16000)
|
235 |
mel = audio.melspectrogram(wav)
|
|
|
264 |
print("Model loaded")
|
265 |
|
266 |
frame_h, frame_w = full_frames[0].shape[:-1]
|
267 |
+
out = cv2.VideoWriter(f'{folder_path}/result.avi',
|
268 |
cv2.VideoWriter_fourcc(*'DIVX'), fps, (frame_w, frame_h))
|
269 |
|
270 |
img_batch = torch.FloatTensor(np.transpose(img_batch, (0, 3, 1, 2))).to(device)
|
|
|
284 |
|
285 |
out.release()
|
286 |
|
287 |
+
command = 'ffmpeg -y -i {} -i {} -strict -2 -q:v 1 {}'.format(args.audio, f'{folder_path}/result.avi', args.outfile)
|
288 |
subprocess.call(command, shell=platform.system() != 'Windows')
|
289 |
|
290 |
|