添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account I am getting different frame count for the same video on different machines.
Code used to find frame count:

import cv2
cap= cv2.VideoCapture("2653582916.mp4")
while(cap.isOpened()):
    ret, frame = cap.read()
    if ret == False:
        break
print(i)

Output on machine 1

Output on machine 2

System Information
Machine 1
OpenCV = 4.1.1.26
OS = Ubuntu 18.04.4 LTS
16 Core / 32GB RAM
Machine 2
OpenCV = 4.1.1.26
OS = Ubuntu 18.04.3 LTS
8 Core /16GB RAM

frame count will vary depends on machines? please help me out.

Please collect more information using videoio debug flags: https://docs.opencv.org/4.1.1/de/db1/group__videoio__registry.html

If you want to report a bug provide complete reproducer (including input data).

Usage questions should go to Users OpenCV Q/A forum: http://answers.opencv.org

Video used
http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4

Output on machine 1
14300

Output on machine 2
14308

System Information
Machine 1
OpenCV = 4.1.1.26
OS = Ubuntu 18.04.4 LTS
16 Core / 32GB RAM
[cv2.videoio_registry.getBackendName(b) for b in cv2.videoio_registry.getBackends()]
['FFMPEG', 'GSTREAMER', 'INTEL_MFX', 'V4L2', 'CV_IMAGES', 'CV_MJPEG']
cap.getBackendName()
FFMPEG

Machine 2
OpenCV = 4.1.1.26
OS = Ubuntu 18.04.3 LTS
8 Core /16GB RAM
[cv2.videoio_registry.getBackendName(b) for b in cv2.videoio_registry.getBackends()]
['FFMPEG', 'GSTREAMER', 'INTEL_MFX', 'V4L2', 'CV_IMAGES', 'CV_MJPEG']
cap.getBackendName()
FFMPEG

Both numbers seems incorrect - ffprobe returns 14315 in nb_frames:

$ ffprobe -show_streams /home/alalek/Downloads/BigBuckBunny.mp4

BTW, on my machine I see 14308 (i7-6700K - 4 cores/8 threads)

@alalek so do you say like the number of frames that we get on different machines are different ?

if so,
why / what is making the particular change in the number of frames produced?

Thanks and Regards,

Do you have different versions of FFmpeg installed on these machines? Looks like duplicate of #15352

Package Machine 1 Machine 2
ffmpeg-python 0.2.0 0.2.0
opencv-python 4.1.1.26 4.1.1.26

ffmpeg-python 0.2.0 0.2.0

opencv-python package uses builtin FFmpeg. So this extra ffmpeg package is not necessarry (or more worse - they may conflict).

More experiments:

  • i5-6600 (4 cores / 4 threads) + opencv-python==4.1.1.26 ===> 14312
  • taskset -c 0 or taskset -c 0,1 doesn't change final result (14312)
  • Hi @alalek,

    actual FPS of video which I used to find frame count, is 24FPS.
    But when I read it using VideoCapture,

    In Machine 1 :
    it is returning FPS as 23.2376 and elapsed time 615.380.

    In Machine 2:
    FPS 26.157557
    elapsed time 546.992977976

    can you please clear that depends on hardware even FPS will get a change in VideoCapture?? because of that am I getting the different number of frames in different machines?

    Thanks

    I have the same problem but in different OpenCV versions
    In 4.4.0.42 I got more frames than 4.5.4.58
    ffmpeg-python==0.2.0

    on Windows with the latest version of OpenCV i tested used
    http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4

    import cv2
    cap= cv2.VideoCapture("d:/test/BigBuckBunny.mp4")
    frame_count = cap.get(cv2.CAP_PROP_FRAME_COUNT)
    pos_frames = 14000
    cap.set(cv2.CAP_PROP_POS_FRAMES, pos_frames)
    while(cap.isOpened()):
        ret, frame = cap.read()
        if ret == False:
            break
    print("frame_count:", frame_count)
    print("starting frame:", pos_frames)
    print("read frame_count:", i)
    print("result is:", frame_count - pos_frames - i == 0)
    

    result:

    frame_count: 14315.0
    starting frame: 14000
    read frame_count: 315
    result is: True

    tested changing pos_frames and always result is: True

    Same here. I did not see any problem until I upgrade opencv to version 4.5.5.64.
    I built it for Windows and for Linux and the problem appears only on Windows. I have a video containing 609 frames and cap.get(cv2.CAP_PROP_FRAME_COUNT) returns 611 on Windows, whereas it correctly returns 609 frames on Linux. Before upgrading both returned 609 frames.

    Is there any progress on this issue?

    I was experiencing incorrect frame counts with MP4 videos specifically. People having having trouble with MP4 videos in specific seems like a common trend in this thread. For what it's worth, here are some outputs counting the frames of the same video only difference being the video format (one more frame for mov is odd):