Skip to content
Open
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: 10 additions & 2 deletions mediapy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1331,8 +1331,16 @@ def _get_video_metadata(path: _Path) -> VideoMetadata:
if not (match := re.search(r', (\d+)x(\d+)', line)):
raise RuntimeError(f'Unable to parse video dimensions in line {line}')
width, height = int(match.group(1)), int(match.group(2))
if match := re.search(r', ([\d.]+) fps', line):
fps = float(match.group(1))
# Some videos have a 'k' suffix for kiloframes per second. Thus an extra
# `(k?)` is used for this case. This usually happens when we don't know
# the exact framerate. However, in order to not raise an error here, we
# will try to parse the framerate as x1000.
if match := re.search(r', ([\d.]+)(k?) fps', line):
number = float(match.group(1))
if match.group(2) == 'k':
fps = number * 1000
else:
fps = number
elif str(path).endswith('.gif'):
# Some GIF files lack a framerate attribute; use a reasonable default.
fps = 10
Expand Down
Loading