Skip to content

Commit d2c7739

Browse files
ThatwhoNikita Manovich
and
Nikita Manovich
authored
Make function get_progress be compatible with more video format (#3381)
* Make function get_progress be compatible with more video format Co-authored-by: Nikita Manovich <[email protected]>
1 parent 7f4b185 commit d2c7739

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4242
- Duplication of the cuboids when redraw them (<https://github.com/openvinotoolkit/cvat/pull/3308>)
4343
- Some code issues in Deep Extreme Cut handler code (<https://github.com/openvinotoolkit/cvat/pull/3325>)
4444
- UI fails when inactive user is assigneed to a task/job (<https://github.com/openvinotoolkit/cvat/pull/3343>)
45+
- Calculate precise progress of decoding a video file (<https://github.com/openvinotoolkit/cvat/pull/3381>)
4546
- Falsely successful `cvat_ui` image build in case of OOM error that leads to the default nginx welcome page
4647
(<https://github.com/openvinotoolkit/cvat/pull/3379>)
4748

cvat/apps/engine/media_extractors.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -325,16 +325,30 @@ def __iter__(self):
325325
return self._decode(container)
326326

327327
def get_progress(self, pos):
328-
container = self._get_av_container()
329-
# Not for all containers return real value
330-
stream = container.streams.video[0]
331-
return pos / stream.duration if stream.duration else None
328+
duration = self._get_duration()
329+
return pos / duration if duration else None
332330

333331
def _get_av_container(self):
334332
if isinstance(self._source_path[0], io.BytesIO):
335333
self._source_path[0].seek(0) # required for re-reading
336334
return av.open(self._source_path[0])
337335

336+
def _get_duration(self):
337+
container = self._get_av_container()
338+
stream = container.streams.video[0]
339+
duration = None
340+
if stream.duration:
341+
duration = stream.duration
342+
else:
343+
# may have a DURATION in format like "01:16:45.935000000"
344+
duration_str = stream.metadata.get("DURATION", None)
345+
tb_denominator = stream.time_base.denominator
346+
if duration_str and tb_denominator:
347+
_hour, _min, _sec = duration_str.split(':')
348+
duration_sec = 60*60*float(_hour) + 60*float(_min) + float(_sec)
349+
duration = duration_sec * tb_denominator
350+
return duration
351+
338352
def get_preview(self):
339353
container = self._get_av_container()
340354
stream = container.streams.video[0]

0 commit comments

Comments
 (0)