Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

video.py read_video_timestamps calculate pts without storing full frames #2202

Merged
merged 3 commits into from
May 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions torchvision/io/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ def read_video_timestamps(filename, pts_unit="pts"):

_check_av_available()

video_frames = []
video_fps = None
pts = []

try:
container = av.open(filename, metadata_errors="ignore")
Expand All @@ -331,17 +331,13 @@ 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]
pts.sort()

if pts_unit == "sec":
pts = [x * video_time_base for x in pts]
Expand Down