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"): ...@@ -317,8 +317,8 @@ def read_video_timestamps(filename, pts_unit="pts"):
_check_av_available() _check_av_available()
video_frames = []
video_fps = None video_fps = None
pts = []
try: try:
container = av.open(filename, metadata_errors="ignore") container = av.open(filename, metadata_errors="ignore")
...@@ -331,17 +331,13 @@ def read_video_timestamps(filename, pts_unit="pts"): ...@@ -331,17 +331,13 @@ def read_video_timestamps(filename, pts_unit="pts"):
video_time_base = video_stream.time_base video_time_base = video_stream.time_base
if _can_read_timestamps_from_packets(container): if _can_read_timestamps_from_packets(container):
# fast path # fast path
video_frames = [ pts = [x.pts for x in container.demux(video=0) if x.pts is not None]
x for x in container.demux(video=0) if x.pts is not None
]
else: else:
video_frames = _read_from_stream( pts = [x.pts for x in container.decode(video=0) if x.pts is not None]
container, 0, float("inf"), pts_unit, video_stream, {"video": 0}
)
video_fps = float(video_stream.average_rate) video_fps = float(video_stream.average_rate)
container.close() container.close()
pts = [x.pts for x in video_frames] pts.sort()
if pts_unit == "sec": if pts_unit == "sec":
pts = [x * video_time_base for x in pts] 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