Skip to content

Commit

Permalink
MultiRecorderImporter: add method to parse frame times
Browse files Browse the repository at this point in the history
  • Loading branch information
sitic committed Feb 9, 2024
1 parent ac69079 commit c1c6459
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions optimap/video/_importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,30 @@ def load_video(self, start_frame=0, frames=None, step=1, use_mmap=False):

return arr

def get_frametimes(self):
"""MultiRecoder can encode the time at which each frame was recorded as a unsigned 64-bit integer.
The exact meaning of value depends on the camera plugin.
Returns
-------
frametimes : np.ndarray
Array of frame times for each frame in the file
"""
if self.version not in ["e", "f"]:
raise ValueError("Frametimes are only available for MultiRecorder file versions 'e' and 'f'.")

bs = 1 if self.is_8bit else 2
bytes_per_frame = self._Nx * self._Ny * bs

frametimes = np.zeros(self._Nt, dtype=np.uint64)
with open(self.filepath, "rb") as f:
f.seek(self._header_size, 0)
for i in range(self._Nt):
f.seek(bytes_per_frame, 1)
frametimes[i], = struct.unpack(f"{self._endian}Q", f.read(8))
return frametimes

def _read_header(self, f: BinaryIO):
"""Read the header."""
self.version = f.read(1).decode("utf-8")
Expand Down

0 comments on commit c1c6459

Please sign in to comment.