Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
add new function to determine fps value
Browse files Browse the repository at this point in the history
  • Loading branch information
iLLiCiTiT committed Aug 3, 2022
1 parent e4c1c20 commit 59463a3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions openpype/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
get_ffmpeg_codec_args,
get_ffmpeg_format_args,
convert_ffprobe_fps_value,
convert_ffprobe_fps_to_float,
)
from .avalon_context import (
CURRENT_DOC_SCHEMAS,
Expand Down Expand Up @@ -287,6 +288,7 @@
"get_ffmpeg_codec_args",
"get_ffmpeg_format_args",
"convert_ffprobe_fps_value",
"convert_ffprobe_fps_to_float",

"CURRENT_DOC_SCHEMAS",
"PROJECT_NAME_ALLOWED_SYMBOLS",
Expand Down
37 changes: 37 additions & 0 deletions openpype/lib/transcoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,3 +938,40 @@ def convert_ffprobe_fps_value(str_value):
fps = int(fps)

return str(fps)


def convert_ffprobe_fps_to_float(value):
"""Convert string value of frame rate to float.
Copy of 'convert_ffprobe_fps_value' which raises exceptions on invalid
value, does not convert value to string and does not return "Unknown"
string.
Args:
value (str): Value to be converted.
Returns:
Float: Converted frame rate in float. If divisor in value is '0' then
'0.0' is returned.
Raises:
ValueError: Passed value is invalid for conversion.
"""

if not value:
raise ValueError("Got empty value.")

items = value.split("/")
if len(items) == 1:
return float(items[0])

if len(items) > 2:
raise ValueError((
"FPS expression contains multiple dividers \"{}\"."
).format(value))

dividend = float(items.pop(0))
divisor = float(items.pop(0))
if divisor == 0.0:
return 0.0
return dividend / divisor

0 comments on commit 59463a3

Please sign in to comment.