2626install PyAV on your system.
2727"""
2828 )
29+ try :
30+ FFmpegError = av .FFmpegError # from av 14 https://github.com/PyAV-Org/PyAV/blob/main/CHANGELOG.rst
31+ except AttributeError :
32+ FFmpegError = av .AVError
2933except ImportError :
3034 av = ImportError (
3135 """\
@@ -221,7 +225,7 @@ def _read_from_stream(
221225 try :
222226 # TODO check if stream needs to always be the video stream here or not
223227 container .seek (seek_offset , any_frame = False , backward = True , stream = stream )
224- except av . AVError :
228+ except FFmpegError :
225229 # TODO add some warnings in this case
226230 # print("Corrupted file?", container.name)
227231 return []
@@ -234,7 +238,7 @@ def _read_from_stream(
234238 buffer_count += 1
235239 continue
236240 break
237- except av . AVError :
241+ except FFmpegError :
238242 # TODO add a warning
239243 pass
240244 # ensure that the results are sorted wrt the pts
@@ -356,7 +360,7 @@ def read_video(
356360 )
357361 info ["audio_fps" ] = container .streams .audio [0 ].rate
358362
359- except av . AVError :
363+ except FFmpegError :
360364 # TODO raise a warning?
361365 pass
362366
@@ -447,10 +451,10 @@ def read_video_timestamps(filename: str, pts_unit: str = "pts") -> Tuple[List[in
447451 video_time_base = video_stream .time_base
448452 try :
449453 pts = _decode_video_timestamps (container )
450- except av . AVError :
454+ except FFmpegError :
451455 warnings .warn (f"Failed decoding frames for file { filename } " )
452456 video_fps = float (video_stream .average_rate )
453- except av . AVError as e :
457+ except FFmpegError as e :
454458 msg = f"Failed to open container for { filename } ; Caught error: { e } "
455459 warnings .warn (msg , RuntimeWarning )
456460
0 commit comments