Skip to content

Commit

Permalink
video.py read_video_timestamps (follow-up PR #2202) (#2268)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mjunyent authored May 29, 2020
1 parent 3e69462 commit a85f21d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions torchvision/io/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit a85f21d

Please sign in to comment.