From 1b4ebca023ef690be9b078d7019c12bc0c3a9a95 Mon Sep 17 00:00:00 2001 From: Kevis-Kokitsi Maninis Date: Wed, 2 Aug 2023 07:24:16 -0700 Subject: [PATCH] Improve finding rotation from metadata. PiperOrigin-RevId: 553137874 --- mediapy/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mediapy/__init__.py b/mediapy/__init__.py index 6a1407f..f0dacbe 100644 --- a/mediapy/__init__.py +++ b/mediapy/__init__.py @@ -1217,7 +1217,7 @@ def _get_video_metadata(path: _Path) -> VideoMetadata: command, stderr=subprocess.PIPE, encoding='utf-8' ) as proc: _, err = proc.communicate() - bps = num_images = width = rotation = None + bps = fps = num_images = width = height = rotation = None for line in err.split('\n'): if match := re.search(r', bitrate: *([0-9.]+) kb/s', line): bps = int(match.group(1)) * 1000 @@ -1234,7 +1234,10 @@ def _get_video_metadata(path: _Path) -> VideoMetadata: fps = 10 else: raise RuntimeError(f'Unable to parse video framerate in line {line}') - if match := re.fullmatch(r'\s*rotate\s*:\s*(\d+)', line): + if ( + (match := re.fullmatch(r'\s*rotate\s*:\s*(\d+)', line)) or + (match:= re.fullmatch(r'\s*.*rotation of -?(\d+)\s*.*\sdegrees', line)) + ): rotation = int(match.group(1)) if not num_images: raise RuntimeError(f'Unable to find frames in video: {err}')