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

video.py read_video_timestamps (follow-up PR #2202) (#2268)

* 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
parent 3e69462f
...@@ -329,11 +329,16 @@ def read_video_timestamps(filename, pts_unit="pts"): ...@@ -329,11 +329,16 @@ def read_video_timestamps(filename, pts_unit="pts"):
if container.streams.video: if container.streams.video:
video_stream = container.streams.video[0] video_stream = container.streams.video[0]
video_time_base = video_stream.time_base video_time_base = video_stream.time_base
if _can_read_timestamps_from_packets(container): try:
# fast path if _can_read_timestamps_from_packets(container):
pts = [x.pts for x in container.demux(video=0) if x.pts is not None] # fast path
else: pts = [x.pts for x in container.demux(video=0) if x.pts is not None]
pts = [x.pts for x in container.decode(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) video_fps = float(video_stream.average_rate)
container.close() container.close()
......
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