mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-25 05:14:40 +01:00
add new function to determine fps value
This commit is contained in:
parent
e4c1c204d1
commit
59463a3457
2 changed files with 39 additions and 0 deletions
|
|
@ -115,6 +115,7 @@ from .transcoding import (
|
|||
get_ffmpeg_codec_args,
|
||||
get_ffmpeg_format_args,
|
||||
convert_ffprobe_fps_value,
|
||||
convert_ffprobe_fps_to_float,
|
||||
)
|
||||
from .avalon_context import (
|
||||
CURRENT_DOC_SCHEMAS,
|
||||
|
|
@ -287,6 +288,7 @@ __all__ = [
|
|||
"get_ffmpeg_codec_args",
|
||||
"get_ffmpeg_format_args",
|
||||
"convert_ffprobe_fps_value",
|
||||
"convert_ffprobe_fps_to_float",
|
||||
|
||||
"CURRENT_DOC_SCHEMAS",
|
||||
"PROJECT_NAME_ALLOWED_SYMBOLS",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue