From aca7474bf7adf03c0cf52de3267a4553a708caff Mon Sep 17 00:00:00 2001 From: The mediapy Authors Date: Mon, 18 May 2026 05:26:43 -0700 Subject: [PATCH] Handle 'k' suffix in video framerate parsing. The regex for parsing FPS from video metadata is updated to support a potential 'k' suffix after the numerical value. When a 'k' is present, the parsed number is multiplied by 1000 to correctly interpret kiloframes per second. PiperOrigin-RevId: 917171651 --- mediapy/__init__.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mediapy/__init__.py b/mediapy/__init__.py index 266ad2d..1388612 100644 --- a/mediapy/__init__.py +++ b/mediapy/__init__.py @@ -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