Repository: opencv
Issue: cv2.VideoCapture() dropping 2 frames per second
Labels: category: videoio


##### System information (version)

- OpenCV => 4.5.1-dirty
- Operating System / Platform => Linux 64 Bit
- Compiler => CMake 

[openCV.config.txt](https://drive.google.com/file/d/1s9opaEa1-FJLTgkNv79g9gAQDvdpqdDT/view?usp=sharing) *from system install, rather than enviroment*

##### Detailed description

cv2.VideoCapture() is missing 2 frames per second  

5 second video @ 23.98 fps
- `ffmpeg -i c.mp4 ffmpeg.%03d.png`
   - 120 images out
- cv2.VideoCapture()
   - 110 images out
- cap.get(cv2.CAP_PROP_FRAME_COUNT)
   - 135

**Image 110 from VideoCapture appears to be the same as image 120 from ffmpeg**

Tested with {1..5} seconds, **2 frames missing per second**

Crashes with a None frame error as no more frames arrive.

##### Steps to reproduce

    audio, fps, width, height = getVideoMetaData(in_file)
    print(audio, fps, width, height)

    cap = cv2.VideoCapture(in_file)
    frame_num = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
    fourcc = cv2.VideoWriter_fourcc(*'mp4v')
    out = cv2.VideoWriter('out.mp4',fourcc,fps,(1280,720))
    
    i = 0
    while(cap.isOpened()):
        ret, frame = cap.read()

        out_frame = processFrame(frame) 
        i = i + 1
        print(i,"/",frame_num)

        out.write(out_frame)
        cv2.imwrite('output/' + str(i) + ".png", out_frame)
        if cv2.waitKey(25) & 0xFF == ord('q'):
            break

    cap.release()
    out.release()
    
Same results with 

- conda opencv 4.51
- conda opencv 4.3
- system install opencv 4.51 (CV model gutted for testing)

Video : 
- [demo 5 sec vid](https://drive.google.com/file/d/18q7hibAYQy27nhUmZKPre3PAcx8_GRaU/view?usp=sharing)


##### Issue submission checklist

 - [x] I report the issue, it's not a question
   <!--
   OpenCV team works with forum.opencv.org, Stack Overflow and other communities
   to discuss problems. Tickets with question without real issue statement will be
   closed.
   -->
 - [x] I checked the problem with documentation, FAQ, open issues,
       forum.opencv.org, Stack Overflow, etc and have not found solution
   <!--
   Places to check:
   * OpenCV documentation: https://docs.opencv.org
   * FAQ page: https://github.com/opencv/opencv/wiki/FAQ
   * OpenCV forum: https://forum.opencv.org
   * OpenCV issue tracker: https://github.com/opencv/opencv/issues?q=is%3Aissue
   * Stack Overflow branch: https://stackoverflow.com/questions/tagged/opencv
   -->
 - [x] I updated to latest OpenCV version and the issue is still there
   <!--
   master branch for OpenCV 4.x and 3.4 branch for OpenCV 3.x releases.
   OpenCV team supports only latest release for each branch.
   The ticket is closed, if the problem is not reproduced with modern version.
   -->
 - [x] There is reproducer code and related data files: videos, images, onnx, etc
   <!--
   The best reproducer -- test case for OpenCV that we can add to the library.
   Recommendations for media files and binary files:
   * Try to reproduce the issue with images and videos in opencv_extra repository
     to reduce attachment size
   * Use PNG for images, if you report some CV related bug, but not image reader
     issue
   * Attach the image as archive to the ticket, if you report some reader issue.
     Image hosting services compress images and it breaks the repro code.
   * Provide ONNX file for some public model or ONNX file with with random weights,
     if you report ONNX parsing or handling issue. Architecture details diagram
     from netron tool can be very useful too. See https://lutzroeder.github.io/netron/
   -->