Skip to content

Commit e326b4f

Browse files
committed
Catch exceptions while decoding partly-corrupted files
1 parent cd91360 commit e326b4f

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

torchvision/io/video.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,17 @@ def _read_from_stream(container, start_offset, end_offset, pts_unit, stream, str
124124
# print("Corrupted file?", container.name)
125125
return []
126126
buffer_count = 0
127-
for idx, frame in enumerate(container.decode(**stream_name)):
128-
frames[frame.pts] = frame
129-
if frame.pts >= end_offset:
130-
if should_buffer and buffer_count < max_buffer_size:
131-
buffer_count += 1
132-
continue
133-
break
127+
try:
128+
for idx, frame in enumerate(container.decode(**stream_name)):
129+
frames[frame.pts] = frame
130+
if frame.pts >= end_offset:
131+
if should_buffer and buffer_count < max_buffer_size:
132+
buffer_count += 1
133+
continue
134+
break
135+
except av.AVError:
136+
# TODO add a warning
137+
pass
134138
# ensure that the results are sorted wrt the pts
135139
result = [frames[i] for i in sorted(frames) if start_offset <= frames[i].pts <= end_offset]
136140
if start_offset > 0 and start_offset not in frames:

0 commit comments

Comments
 (0)