'tqdm progressbar for opencv videocapture going beyong 100%

I am processing a video using Opencv in python and using tqdm to show the progressbar. However, the progress goes beyond 100%. Not really sure why is this happening.

I am new to opencv ,so it is possible I am passing wrong params to do what I is intended.

I have tried out a few ways. Listing them down.

cam = cv2.VideoCapture("path")
fps = cam.get(cv2.CAP_PROP_FPS)
total_frame_count = int(cam.get(cv2.CAP_PROP_FRAME_COUNT))
length = total_frame_count/fps

pbar = tqdm(total = total_frame_count)
count = 0
    ret,frame = cam.read()
    # process(frame)
    count += fps*5 
    cam.set(cv2.CAP_PROP_POS_FRAMES, count)

I have a counter called count which is basically to skip the video 5 secs.

Solution 1:[1]

When using tqdm with manual updates you specify the step with which you increment not where you are currently.

From the manual

with tqdm(total=100) as pbar:
    for i in range(10):

So what you should do is simply to have pbar.update(fps*5).


This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 VRehnberg