26
26
install PyAV on your system.
27
27
"""
28
28
)
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
29
33
except ImportError :
30
34
av = ImportError (
31
35
"""\
@@ -155,7 +159,13 @@ def write_video(
155
159
156
160
for img in video_array :
157
161
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
+
159
169
for packet in stream .encode (frame ):
160
170
container .mux (packet )
161
171
@@ -215,7 +225,7 @@ def _read_from_stream(
215
225
try :
216
226
# TODO check if stream needs to always be the video stream here or not
217
227
container .seek (seek_offset , any_frame = False , backward = True , stream = stream )
218
- except av . AVError :
228
+ except FFmpegError :
219
229
# TODO add some warnings in this case
220
230
# print("Corrupted file?", container.name)
221
231
return []
@@ -228,7 +238,7 @@ def _read_from_stream(
228
238
buffer_count += 1
229
239
continue
230
240
break
231
- except av . AVError :
241
+ except FFmpegError :
232
242
# TODO add a warning
233
243
pass
234
244
# ensure that the results are sorted wrt the pts
@@ -350,7 +360,7 @@ def read_video(
350
360
)
351
361
info ["audio_fps" ] = container .streams .audio [0 ].rate
352
362
353
- except av . AVError :
363
+ except FFmpegError :
354
364
# TODO raise a warning?
355
365
pass
356
366
@@ -441,10 +451,10 @@ def read_video_timestamps(filename: str, pts_unit: str = "pts") -> Tuple[List[in
441
451
video_time_base = video_stream .time_base
442
452
try :
443
453
pts = _decode_video_timestamps (container )
444
- except av . AVError :
454
+ except FFmpegError :
445
455
warnings .warn (f"Failed decoding frames for file { filename } " )
446
456
video_fps = float (video_stream .average_rate )
447
- except av . AVError as e :
457
+ except FFmpegError as e :
448
458
msg = f"Failed to open container for { filename } ; Caught error: { e } "
449
459
warnings .warn (msg , RuntimeWarning )
450
460
0 commit comments