From a85f21d2cc5c82416423922e37038520cdbe74cb Mon Sep 17 00:00:00 2001 From: Marc Date: Fri, 29 May 2020 15:53:24 +0200 Subject: [PATCH] video.py read_video_timestamps (follow-up PR #2202) (#2268) * get pts directly instead of storing full frames to get pts later * fix linting * add initial pts value sort pts * catch decoding errors for read_video_timestamp --- torchvision/io/video.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/torchvision/io/video.py b/torchvision/io/video.py index 1022be61d84..f822cbd3343 100644 --- a/torchvision/io/video.py +++ b/torchvision/io/video.py @@ -329,11 +329,16 @@ def read_video_timestamps(filename, pts_unit="pts"): if container.streams.video: video_stream = container.streams.video[0] video_time_base = video_stream.time_base - if _can_read_timestamps_from_packets(container): - # fast path - pts = [x.pts for x in container.demux(video=0) if x.pts is not None] - else: - pts = [x.pts for x in container.decode(video=0) if x.pts is not None] + try: + if _can_read_timestamps_from_packets(container): + # fast path + pts = [x.pts for x in container.demux(video=0) if x.pts is not None] + else: + pts = [ + x.pts for x in container.decode(video=0) if x.pts is not None + ] + except av.AVError: + warnings.warn(f"Failed decoding frames for file {filename}") video_fps = float(video_stream.average_rate) container.close()