Fixed errors in tqdm implementation for progress tracking

This commit is contained in:
Xavi Vinaixa
2023-06-05 09:31:55 +02:00
parent 1c03fe3f1b
commit 101691ca95

View File

@@ -60,6 +60,10 @@ class Refacer:
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
print(f"Total frames: {total_frames}") print(f"Total frames: {total_frames}")
#probe = ffmpeg.probe(video_path)
#video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None)
#print(video_stream)
fps = cap.get(cv2.CAP_PROP_FPS) fps = cap.get(cv2.CAP_PROP_FPS)
frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
@@ -67,13 +71,12 @@ class Refacer:
fourcc = cv2.VideoWriter_fourcc(*'mp4v') fourcc = cv2.VideoWriter_fourcc(*'mp4v')
output = cv2.VideoWriter(output_video_path, fourcc, fps, (frame_width, frame_height)) output = cv2.VideoWriter(output_video_path, fourcc, fps, (frame_width, frame_height))
pbar = tqdm(total=total_frames) with tqdm(total=total_frames) as pbar:
while cap.isOpened(): while cap.isOpened():
flag, frame = cap.read() flag, frame = cap.read()
if flag and len(frame)>0: if flag and len(frame)>0:
pos_frame = int(cap.get(cv2.CAP_PROP_POS_FRAMES)) #pos_frame = int(cap.get(cv2.CAP_PROP_POS_FRAMES))
pbar.update(1)
pbar.update(pos_frame)
faces = self.face_app.get(frame) faces = self.face_app.get(frame)
res = frame.copy() res = frame.copy()