From f5d84be9d49d504fe6e3ec49b6e8c6d81601f8f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Junyent=20Marti=CC=81n?= Date: Mon, 11 May 2020 18:07:24 +0200 Subject: [PATCH 1/3] get pts directly instead of storing full frames to get pts later --- torchvision/io/video.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/torchvision/io/video.py b/torchvision/io/video.py index 40d1cfeed85..9ca2f2a3f62 100644 --- a/torchvision/io/video.py +++ b/torchvision/io/video.py @@ -331,18 +331,12 @@ def read_video_timestamps(filename, pts_unit="pts"): video_time_base = video_stream.time_base if _can_read_timestamps_from_packets(container): # fast path - video_frames = [ - x for x in container.demux(video=0) if x.pts is not None - ] + pts = [x.pts for x in container.demux(video=0) if x.pts is not None] else: - video_frames = _read_from_stream( - container, 0, float("inf"), pts_unit, video_stream, {"video": 0} - ) + pts = [x.pts for x in container.decode(video=0) if x.pts is not None] video_fps = float(video_stream.average_rate) container.close() - pts = [x.pts for x in video_frames] - if pts_unit == "sec": pts = [x * video_time_base for x in pts] From e8465fd24da225547ad85f503310b75930a5096c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Junyent=20Marti=CC=81n?= Date: Mon, 11 May 2020 18:23:14 +0200 Subject: [PATCH 2/3] fix linting --- torchvision/io/video.py | 1 - 1 file changed, 1 deletion(-) diff --git a/torchvision/io/video.py b/torchvision/io/video.py index 9ca2f2a3f62..914555017c7 100644 --- a/torchvision/io/video.py +++ b/torchvision/io/video.py @@ -317,7 +317,6 @@ def read_video_timestamps(filename, pts_unit="pts"): _check_av_available() - video_frames = [] video_fps = None try: From 57380c00b8ac51339812474696e4114258012414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Junyent=20Marti=CC=81n?= Date: Mon, 11 May 2020 19:02:05 +0200 Subject: [PATCH 3/3] add initial pts value sort pts --- torchvision/io/video.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/torchvision/io/video.py b/torchvision/io/video.py index 914555017c7..8e2a78134c4 100644 --- a/torchvision/io/video.py +++ b/torchvision/io/video.py @@ -318,6 +318,7 @@ def read_video_timestamps(filename, pts_unit="pts"): _check_av_available() video_fps = None + pts = [] try: container = av.open(filename, metadata_errors="ignore") @@ -336,6 +337,8 @@ def read_video_timestamps(filename, pts_unit="pts"): video_fps = float(video_stream.average_rate) container.close() + pts.sort() + if pts_unit == "sec": pts = [x * video_time_base for x in pts]