Ask Your Question
0

OpenCV does not read Logitech C920 .wmv files

asked 2019-11-05 11:25:59 -0500

auesro gravatar image

System used:

OpenCV = 4.1.1 (through opencv-python)
Operating System / Platform => Windows 10 64 Bit and Linux Mint 19.1

Detailed description:

Properties and frame indexes from videos recorded by the Logitech Webcam C920 are not properly read by OpenCV:

cv2.CAP_PROP_POS_MSEC returns 0.0 for a video that lasts 10.14 minutes.

cv2.CAP_PROP_FOURCC returns code 844516695.

cv2.CAP_PROP_FPS returns 1000 fps for videos that were recorded at 30 fps.

cv2.CAP_PROP_FRAME_COUNT returns 614126 frames. When decoding and counting them one by one gives 18416, a value that agrees with expected number of frames for a video of 10 minutes recorded at 30 fps.

Moreover, indexing frames by frame number results in wrong frame: for example, using this code you can display the frame number 60000, which doesnt exist:

import cv2

stream = cv2.VideoCapture('video.wmv')
frame_number = 60000
stream.set(0, frame_number)
ret, frame = stream.read()
cv2.imshow('', frame)
cv2.waitKey()
stream.release()
cv2.destroyAllWindows()

So in summary, apparently metadata from wmv videos recorded by Logitech webcam C920 cannot properly read (if it exists) by OpenCV.

Use following code and file to reproduce:

import cv2

stream = cv2.VideoCapture('video.wmv')
fps = stream.get(cv2.CAP_PROP_FPS)
total_frames = int(stream.get(cv2.CAP_PROP_FRAME_COUNT))
duration = stream.get(cv2.CAP_PROP_POS_MSEC)
fourcc = int(stream.get(cv2.CAP_PROP_FOURCC))

count = 0
while(True):
      ret, frame = stream.read()
        if not ret:
            break
        count += 1

stream.release()
cv2.destroyAllWindows()

Any ideas how to solve this?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2019-11-06 14:00:01 -0500

supra56 gravatar image

updated 2019-11-06 14:04:15 -0500

You wanted to count frame by frame?

#!/usr/bin/python3.7

import cv2
cap = cv2.VideoCapture('video.wmv')
fps = cap.get(cv2.CAP_PROP_FPS)
frames = cap.get(cv2.CAP_PROP_FRAME_COUNT)

frame_counter = 0
frame_by_frame=[] 

while cap.isOpened():
    ret, frame = cap.read()
    frame_by_frame.append(frame_counter)
    print(f'number of frames: ' + str(len(frame_by_frame)))
    cv2.imshow('frame', frame)
    if cv2.waitKey(1) == ord('q'):
        cap.release()
        cv2.destroyAllWindows()
edit flag offensive delete link more
-1

answered 2019-11-08 09:01:21 -0500

auesro gravatar image

What I want to know is why OpenCV does not report properly neither FPS nor total number of frames in a video recorded with a Logitech C920 webcam with the properties described above.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-11-05 11:25:59 -0500

Seen: 45 times

Last updated: Nov 06