Skip to content

Commit

Permalink
Workaround for av context closing issue when using AUTO thread_type
Browse files Browse the repository at this point in the history
  • Loading branch information
azhavoro committed Oct 17, 2024
1 parent ffe45fe commit 4ddf0ea
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cvat/apps/engine/media_extractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 4ddf0ea

Please sign in to comment.