Coverage for ibllib/oneibl/stream.py: 0%
21 statements
« prev ^ index » next coverage.py v7.5.4, created at 2024-07-08 17:16 +0100
« prev ^ index » next coverage.py v7.5.4, created at 2024-07-08 17:16 +0100
1import re
3import cv2
4import one.params
7class VideoStreamer(object):
8 """
9 Provides a wrapper to stream a video from a password protected HTTP server using opencv
10 """
12 def __init__(self, url_vid):
13 """
14 :param url_vid: full url of the video or dataset dictionary as output by alyx rest datasets
15 :returns cv2.VideoCapture object
16 """
17 import warnings
18 warnings.warn('Please use ibllib.io.video.VideoStreamer instead', FutureWarning)
20 # pop the data url from the dataset record if the input is a dictionary
21 if isinstance(url_vid, dict):
22 url_vid = next(fr['data_url'] for fr in url_vid['file_records'] if fr['data_url'])
23 self.url = url_vid
24 self._par = one.params.get(silent=True)
25 self.cap = cv2.VideoCapture(self._url)
26 self.total_frames = int(self.cap.get(cv2.CAP_PROP_FRAME_COUNT))
28 @property
29 def _url(self):
30 username = self._par.HTTP_DATA_SERVER_LOGIN
31 password = self._par.HTTP_DATA_SERVER_PWD
32 return re.sub(r'(^https?://)', r'\1' + f'{username}:{password}@', self.url)
34 def get_frame(self, frame_index):
35 self.cap.set(cv2.CAP_PROP_POS_FRAMES, frame_index)
36 return self.cap.read()