Skip to content

Commit

Permalink
Improve finding rotation from metadata.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 553137874
  • Loading branch information
kmaninis authored and The mediapy Authors committed Aug 2, 2023
1 parent 863fdd7 commit 1b4ebca
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions mediapy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}')
Expand Down

0 comments on commit 1b4ebca

Please sign in to comment.