From 4ddf0ea4b94f1648744398609794f552f0628f2f Mon Sep 17 00:00:00 2001 From: Andrey Zhavoronkov Date: Thu, 17 Oct 2024 15:55:41 +0300 Subject: [PATCH] Workaround for av context closing issue when using AUTO thread_type --- cvat/apps/engine/media_extractors.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cvat/apps/engine/media_extractors.py b/cvat/apps/engine/media_extractors.py index 9c1d2deca189..a64637359ff5 100644 --- a/cvat/apps/engine/media_extractors.py +++ b/cvat/apps/engine/media_extractors.py @@ -552,6 +552,8 @@ def read_av_container(self, source: Union[str, io.BytesIO]) -> av.container.Inpu for stream in container.streams: context = stream.codec_context if context and context.is_open: + # Currently, context closing may get stuck on some videos for an unknown reason, + # so the thread_type == 'AUTO' setting is disabled for future investigation context.close() if container.open_files: @@ -583,7 +585,7 @@ def __init__( stop: Optional[int] = None, dimension: DimensionType = DimensionType.DIM_2D, *, - allow_threading: bool = True, + allow_threading: bool = False, ): super().__init__( source_path=source_path, @@ -635,6 +637,8 @@ def iterate_frames( if self.allow_threading: video_stream.thread_type = 'AUTO' + else: + video_stream.thread_type = 'NONE' frame_counter = itertools.count() with closing(self._decode_stream(container, video_stream)) as stream_decoder: @@ -795,6 +799,8 @@ def iterate_frames(self, *, frame_filter: Iterable[int]) -> Iterable[av.VideoFra video_stream = container.streams.video[0] if self.allow_threading: video_stream.thread_type = 'AUTO' + else: + video_stream.thread_type = 'NONE' container.seek(offset=start_decode_timestamp, stream=video_stream)