-
Notifications
You must be signed in to change notification settings - Fork 7
Description
It is impossible to retrieve movie timestamps due to dlc2nwb.utils.get_movietimestamps
throwing TypeError: object of type 'cv2.VideoCapture' has no len()
Steps to reproduce:
- Download this video: https://photos.app.goo.gl/ddFTw11QWRjVPUmXA
- Navigate to the folder where you downloaded the video in the terminal of your choice
- Open a python interpreter
- Run the following code:
from dlc2nwb.utils import get_movie_timestamps
get_movie_timestamps('VID_20240117_165651.mp4')
Expected behaviour:
The timestamps are returned
Actual behaviour:
TypeError: object of type 'cv2.VideoCapture' has no len()
Environment info:
OS: Windows 10 x64
Conda version: 23.3.1
Python version: 3.9.0
opencv-python version: 4.7.0.72
dlc2nwb version: 0.3
Additional info:
This error might depend on the opencv-python version, in which case pinning the DLC2NWB package to whichever version added the ability to get the len()
of a cv.VideoReader
(or the one before they took it away if it's an old feature) is the simplest solution.
Alternatively, the first return value of reader.read() is a boolean indicating whether a frame was successfully reader, so using this to change the for
loop to a while
loop, like so:
success, _ = reader.read()
while success:
timestamps.append(reader.get(cv2.CAP_PROP_POS_MSEC))
success, _ = reader.read()
fixes the issue. However, (again, possibly depending on your opencv-python version) you then run into an AttributeError
on line 83, since a cv2.VideoReader
has no attribute fps
. This can be fixed by replacing reader.fps
on that line with reader.get(cv2.CAP_PROP_FPS)