'Opencv CAP_PROP_FRAME_COUNT return negative large number with h264 video

I have two identical videos. One is "video.h264" the other one is "video.avi"

When I do this

cap = cv2.VideoCapture(fn)

if not cap.isOpened(): 
    print("could not open :",fn)
    exit
    
length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
width  = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fps    = cap.get(cv2.CAP_PROP_FPS)

print("Length is ",length," Widht and Height (",width,",",height,") FPS ",fps)

cap = cv2.VideoCapture(fn)
property_id = int(cv2.CAP_PROP_FRAME_COUNT) 
length = int(cv2.VideoCapture.get(cap, property_id))
print( length )

If fn is the avi file I get

Length is  600  Widht and Height ( 3840 , 1920 ) FPS  10.0
600

But with the h264 file I get

Length is  -76861433640456  Widht and Height ( 3840 , 1920 ) FPS  10.0
-76861433640456

As you can see the length is a very large negative number. Why this could be happening? Is this a matter of typing?



Sources

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

Source: Stack Overflow

Solution Source