From 548b37e639aaa3dd04ea570bfa0de32fd6bbc21f Mon Sep 17 00:00:00 2001 From: Théo de la Hogue Date: Wed, 7 Sep 2022 22:32:07 +0200 Subject: Adding get frame method. --- src/argaze/TobiiGlassesPro2/TobiiVideo.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/argaze/TobiiGlassesPro2/TobiiVideo.py b/src/argaze/TobiiGlassesPro2/TobiiVideo.py index fb84c04..7625c3c 100644 --- a/src/argaze/TobiiGlassesPro2/TobiiVideo.py +++ b/src/argaze/TobiiGlassesPro2/TobiiVideo.py @@ -63,6 +63,31 @@ class TobiiVideoSegment(): def get_vts_offset(self): return self.__vts_offset + def get_frame(self, i): + """Acces to a frame.""" + + if i < 0: + ValueError('Frame index must be a positive integer.') + + counter = 0 + frame = None + video_ts = 0 + + # position at the given start time + self.__container.seek(self.__start_timestamp) + + # start decoding + self.__container.decode(self.__stream) + + while counter <= i: + + frame = self.__container.decode(self.__stream).__next__() + video_ts = int(frame.time * 1e6) + counter += 1 + + # return micro second timestamp and frame data + return video_ts, TobiiVideoFrame(frame.to_ndarray(format='bgr24'), frame.width, frame.height) + def frames(self): """Access to frame iterator.""" -- cgit v1.1