Unverified Commit e6b4078e authored by Marc's avatar Marc Committed by GitHub
Browse files

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

* get pts directly instead of storing full frames to get pts later

* fix linting

* add initial pts value
sort pts
parent 8e611cfd
......@@ -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")
......@@ -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]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment