diff --git a/CHANGELOG.md b/CHANGELOG.md index 528af0fec7c0..1af1255db815 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Duplication of the cuboids when redraw them () - Some code issues in Deep Extreme Cut handler code () - UI fails when inactive user is assigneed to a task/job () +- Calculate precise progress of decoding a video file () - Falsely successful `cvat_ui` image build in case of OOM error that leads to the default nginx welcome page () diff --git a/cvat/apps/engine/media_extractors.py b/cvat/apps/engine/media_extractors.py index d3184e0968d7..109fd7bad861 100644 --- a/cvat/apps/engine/media_extractors.py +++ b/cvat/apps/engine/media_extractors.py @@ -325,16 +325,30 @@ def __iter__(self): return self._decode(container) def get_progress(self, pos): - container = self._get_av_container() - # Not for all containers return real value - stream = container.streams.video[0] - return pos / stream.duration if stream.duration else None + duration = self._get_duration() + return pos / duration if duration else None def _get_av_container(self): if isinstance(self._source_path[0], io.BytesIO): self._source_path[0].seek(0) # required for re-reading return av.open(self._source_path[0]) + def _get_duration(self): + container = self._get_av_container() + stream = container.streams.video[0] + duration = None + if stream.duration: + duration = stream.duration + else: + # may have a DURATION in format like "01:16:45.935000000" + duration_str = stream.metadata.get("DURATION", None) + tb_denominator = stream.time_base.denominator + if duration_str and tb_denominator: + _hour, _min, _sec = duration_str.split(':') + duration_sec = 60*60*float(_hour) + 60*float(_min) + float(_sec) + duration = duration_sec * tb_denominator + return duration + def get_preview(self): container = self._get_av_container() stream = container.streams.video[0]