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 """\
@@ -155,7 +159,13 @@ def write_video(
155159
156160 for img in video_array :
157161 frame = av .VideoFrame .from_ndarray (img , format = "rgb24" )
158- frame .pict_type = "NONE"
162+ try :
163+ frame .pict_type = "NONE"
164+ except TypeError :
165+ from av .video .frame import PictureType # noqa
166+
167+ frame .pict_type = PictureType .NONE
168+
159169 for packet in stream .encode (frame ):
160170 container .mux (packet )
161171
@@ -215,7 +225,7 @@ def _read_from_stream(
215225 try :
216226 # TODO check if stream needs to always be the video stream here or not
217227 container .seek (seek_offset , any_frame = False , backward = True , stream = stream )
218- except av . AVError :
228+ except FFmpegError :
219229 # TODO add some warnings in this case
220230 # print("Corrupted file?", container.name)
221231 return []
@@ -228,7 +238,7 @@ def _read_from_stream(
228238 buffer_count += 1
229239 continue
230240 break
231- except av . AVError :
241+ except FFmpegError :
232242 # TODO add a warning
233243 pass
234244 # ensure that the results are sorted wrt the pts
@@ -350,7 +360,7 @@ def read_video(
350360 )
351361 info ["audio_fps" ] = container .streams .audio [0 ].rate
352362
353- except av . AVError :
363+ except FFmpegError :
354364 # TODO raise a warning?
355365 pass
356366
@@ -441,10 +451,10 @@ def read_video_timestamps(filename: str, pts_unit: str = "pts") -> Tuple[List[in
441451 video_time_base = video_stream .time_base
442452 try :
443453 pts = _decode_video_timestamps (container )
444- except av . AVError :
454+ except FFmpegError :
445455 warnings .warn (f"Failed decoding frames for file { filename } " )
446456 video_fps = float (video_stream .average_rate )
447- except av . AVError as e :
457+ except FFmpegError as e :
448458 msg = f"Failed to open container for { filename } ; Caught error: { e } "
449459 warnings .warn (msg , RuntimeWarning )
450460
0 commit comments