Writing video capture conflicts with fps counter

I am experiencing a conflict between the cv.write() to record the video captioning. The fps method works fine when I am not using cv.write to store each frame as a video file. However when I try save each frame using cv.write to a video file then the fps counter is stuck at zero. How could I resolve this ? I am letting an object detector predict bounding boxes on each frame of a downloaded YouTube video to illustrate its performance. I would like to store the predictions made on each frame in a video, including the frames per second. Please find the code snipped below:

video_path = 'video/yolo_video_1.mp4'
cap = cv.VideoCapture(video_path)

fps = 0
fps_start = 0
prev = 0 
video_rec = cv.VideoWriter('yolov1_watches_youtube_2.avi', 
                         30, (448, 448))
    ret, frame = cap.read()
    if not ret:
    frame = np.array(frame)
    frame = cv.resize(frame, (448, 448))
    fps_end = time.time() 
    time_diff = fps_end - fps_start
    fps = int(1 / (time_diff - prev))
    prev = fps_end
    height, width = frame.shape[:2]
    fps_txt = "FPS: {}".format(fps)
    frame = cv.putText(frame, fps_txt, (width - 80, 40), cv.FONT_HERSHEY_TRIPLEX, 0.5, (255, 255, 255), 1)

    frame = transform(frame)
    frame = frame.unsqueeze(0)
    preds = model(frame)
    get_bboxes = cellboxes_to_boxes(preds)
    frame = frame.squeeze(0)
    frame = frame.permute(1, 2, 0).numpy() * 255
    bboxes = non_max_suppression(get_bboxes[0], iou_threshold = 0.5, threshold = 0.4, boxformat = "midpoints")
    frame = draw_bounding_box(frame, bboxes, test = True)
    cv.imshow('Video', frame)

    if cv.waitKey(1) & 0xFF == ord('q'):


Your fps variable is stuck at zero because it is an integer that you get when you divide an integer one by something…

Hint: You should use a debugger to watch the variables and then figure out if the problem has anything to do with OpenCV, or just #programming

Thank you Matti. This actually helped me resolve the problem. Unlike the mods (break and crackwitz), who were condescending and implying that the mistake is within my ability to code or make “sense”, your response was in fact the only useful one. It was not a programming error, in fact I was debugging on my local machine, which has no CUDA support. Meaning that the torch model was running on cpu. On cpu I am only able to process 1 frame about every 2-3 seconds, meaning that the value is as you suggested rounded to zero.
If the mods read this, please have a look at the opencv fan with some guidelines on how to behave and act. I believe you two can benefit a lot from re-reading it. While I do understand that the original title is misleading as it is not exactly a conflict (i.e., that the opencv modules are somehow interfering with each other), it is a conflict which I seemed to experience as fps counter was working well when I tested it without cv.write. Note that this original test did not include the torch model predictions, which should be run on gpu instead of cpu. This is where the error was. Note that, blaming posters and being condescending is a terrible way to interact with users, especially when what you said was wrong and without any use.