From 40c833a72fc314ceba84e52bb89cc3f15b061910 Mon Sep 17 00:00:00 2001 From: Lijun Yu Date: Mon, 21 Dec 2020 13:30:53 -0500 Subject: [PATCH] v1.3.9 --- avi_r/reader.py | 24 ++++++++++++++---------- docs/version.md | 5 +++++ setup.py | 2 +- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/avi_r/reader.py b/avi_r/reader.py index de2490e..8c77f82 100644 --- a/avi_r/reader.py +++ b/avi_r/reader.py @@ -193,7 +193,7 @@ def seek(self, frame_id: int): frame_id, self.num_frames)) self._frame_gen = self._get_frame_gen(frame_id) - def get_at(self, frame_id): + def get_at(self, frame_id: int): """Get a specific frame. Parameters @@ -245,25 +245,29 @@ def _del(self): del self.reorder_buffer def _get_frame_gen(self, start_frame_id=0, retry=5, retry_step=120): + start_frame_id = int(start_frame_id) seek_frame_id = start_frame_id retry = min(retry, start_frame_id // retry_step + 1) - for _ in range(retry): - if seek_frame_id != start_frame_id: - self._logger.info( - 'Failed to seek to frame %d, retrying with frame %d', - start_frame_id, seek_frame_id) + for retry_i in range(1, retry + 1): try: self._container.seek(seek_frame_id, stream=self._stream) frame_gen = self._fix_missing(start_frame_id) frame = next(frame_gen) break except: - seek_frame_id = max(0, seek_frame_id - retry_step) + if retry_i < retry: + new_seek_frame_id = max(0, seek_frame_id - retry_step) + self._logger.info( + 'Failed to seek to frame %d, retrying with frame %d', + seek_frame_id, new_seek_frame_id, exc_info=True) + seek_frame_id = new_seek_frame_id + continue + self._logger.info('Failed to seek to frame %d', seek_frame_id) + self._logger.warn( + 'Failed to seek for frame %d after %d retries, iterating ' + 'from the begining', start_frame_id, retry, exc_info=True) else: seek_frame_id = 0 - self._logger.warn( - 'Failed to seek to frame %d, iterating from the beginning', - start_frame_id) try: self._container.seek(seek_frame_id, stream=self._stream) except: diff --git a/docs/version.md b/docs/version.md index bf37151..4ead528 100644 --- a/docs/version.md +++ b/docs/version.md @@ -1,5 +1,10 @@ # Version History +## AVI-R v1.3.9 + +* Ensure seeking frame_ids are Python integers. +* Optimize logs of seeking error. + ## AVI-R v1.3.8 * Add back timeout. diff --git a/setup.py b/setup.py index 02ddf11..7062632 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setuptools.setup( name='avi-r', - version='1.3.8', + version='1.3.9', author='Lijun Yu', author_email='lijun@lj-y.com', description='A robust reader for avi videos.',