conformtools 0.6.5 → 0.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/account-HDXVTS5T.js +3 -0
- package/dist/arriraw-YIJ3BYNN.js +525 -0
- package/dist/avid-panel/MANIFEST.json +11 -0
- package/dist/avid-panel/avid-manifest.json +46 -0
- package/dist/avid-panel/icon.svg +4 -0
- package/dist/avid-panel/icons/conformtools.svg +4 -0
- package/dist/avid-panel/index.html +26 -0
- package/dist/avid-panel/panel.css +12 -0
- package/dist/avid-panel/panel.js +7 -0
- package/dist/bridge-D5KPIUSY.js +3 -0
- package/dist/browser/timeline_core_bg.wasm +0 -0
- package/dist/chunk-3OCQA33E.js +3 -0
- package/dist/chunk-3XD6NC4G.js +10 -0
- package/dist/chunk-5JBUCVRI.js +20 -0
- package/dist/chunk-5RSNFPED.js +8 -0
- package/dist/chunk-5SUGU2YR.js +3 -0
- package/dist/chunk-6ML26TIK.js +3 -0
- package/dist/chunk-7D7H6VFW.js +3 -0
- package/dist/chunk-7MC7M2Y5.js +3 -0
- package/dist/chunk-AACY2V3L.js +3 -0
- package/dist/chunk-AS7IXHYM.js +19 -0
- package/dist/chunk-BL6L5ZBP.js +39 -0
- package/dist/chunk-C2ESM27Z.js +3 -0
- package/dist/chunk-C5IX63YF.js +3 -0
- package/dist/chunk-D6YDLKSA.js +3 -0
- package/dist/chunk-DKGGJM6Z.js +3 -0
- package/dist/chunk-EJGVNQ3E.js +8 -0
- package/dist/chunk-HGDO3OED.js +3 -0
- package/dist/chunk-JV7TZDKJ.js +3 -0
- package/dist/chunk-LFJLRLEP.js +3 -0
- package/dist/chunk-NFJHWZJX.js +3 -0
- package/dist/chunk-NQHQKEP5.js +3 -0
- package/dist/chunk-NU3X7P4N.js +3 -0
- package/dist/chunk-OJWIBQK4.js +376 -0
- package/dist/chunk-OVUCL3YY.js +5 -0
- package/dist/chunk-P7OVDUA5.js +3 -0
- package/dist/chunk-PFISREY4.js +3 -0
- package/dist/chunk-PFZVET7S.js +3 -0
- package/dist/chunk-PLRB2YXJ.js +3 -0
- package/dist/chunk-PSANHDZM.js +3 -0
- package/dist/chunk-RFIPLBQ4.js +5 -0
- package/dist/chunk-SZD4C5MB.js +6 -0
- package/dist/chunk-TK55FA56.js +3 -0
- package/dist/chunk-TXQR2HI2.js +4 -0
- package/dist/chunk-UCMNH6Q6.js +3 -0
- package/dist/chunk-UKKRZ574.js +7 -0
- package/dist/chunk-VS3MKKJ5.js +3 -0
- package/dist/chunk-X53BNWNV.js +3 -0
- package/dist/chunk-XNR7M4VX.js +3 -0
- package/dist/claude-setup-IIWUB4CE.js +5 -0
- package/dist/cli.js +17 -0
- package/dist/clip-state-B6JOX3JE.js +3 -0
- package/dist/conformtools-analyze +0 -0
- package/dist/conformtools-decode +0 -0
- package/dist/cr3-wasm-L2LFY3LM.js +3 -0
- package/dist/dng-wasm-U6NC3MDK.js +3 -0
- package/dist/dpx-wasm-RMKEUKED.js +3 -0
- package/dist/engine-P6H5P6HP.js +5 -0
- package/dist/esm-SFFBP7PS.js +3 -0
- package/dist/exr-wasm-LBAOMOZD.js +3 -0
- package/dist/flame/hook/conformtools_flame/__init__.py +10 -0
- package/dist/flame/hook/conformtools_flame/building.py +191 -0
- package/dist/flame/hook/conformtools_flame/hook.py +177 -0
- package/dist/flame/hook/conformtools_flame/render.py +622 -0
- package/dist/flame/hook/conformtools_flame/util.py +33 -0
- package/dist/flame/hook/conformtools_flame/verbs.py +1037 -0
- package/dist/flame/hook/conformtools_flame_hook.py +42 -0
- package/dist/fonts/gfx/BarlowCondensed-Bold.ttf +0 -0
- package/dist/fonts/gfx/BarlowCondensed-Regular.ttf +0 -0
- package/dist/fonts/gfx/InstrumentSerif-Regular.ttf +0 -0
- package/dist/fonts/gfx/Inter-Bold.ttf +0 -0
- package/dist/fonts/gfx/Inter-Regular.ttf +0 -0
- package/dist/fonts/gfx/JetBrainsMono-Bold.ttf +0 -0
- package/dist/fonts/gfx/JetBrainsMono-Regular.ttf +0 -0
- package/dist/fonts/gfx/OFL.txt +100 -0
- package/dist/framing-SRCJKAYO.js +3 -0
- package/dist/gfx-worker.js +3 -0
- package/dist/h264-3ESGVT6G.js +3 -0
- package/dist/h264-mxf-NPFS7NGH.js +3 -0
- package/dist/host-relink-D6CB2VOQ.js +10 -0
- package/dist/hosts-W4AD2MYH.js +3 -0
- package/dist/http.js +5 -0
- package/dist/i2o-transfer +0 -0
- package/dist/inspect-7ASUPU73.js +68 -0
- package/dist/isobmff-SIOE67WL.js +3 -0
- package/dist/mcp.js +13 -0
- package/dist/media-7AUNRKHF.js +3 -0
- package/dist/media_core-Q2PIEV7D.js +9 -0
- package/dist/media_core_bg-FDL7GJZP.js +3 -0
- package/dist/media_core_bg-XRBVKQZH.js +3 -0
- package/dist/mxf-74TTDICM.js +3 -0
- package/dist/nuke/panel/python/Startup/conformtools_nuke_startup.py +44 -0
- package/dist/nuke/panel/python/conformtools_nuke/__init__.py +10 -0
- package/dist/nuke/panel/python/conformtools_nuke/panel.py +217 -0
- package/dist/nuke/panel/python/conformtools_nuke/verbs.py +837 -0
- package/dist/ops-FSOOBXMV.js +3 -0
- package/dist/peer-kit/ctpeer/__init__.py +21 -0
- package/dist/peer-kit/ctpeer/client.py +247 -0
- package/dist/peer-kit/ctpeer/neutral.py +178 -0
- package/dist/peer-kit/ctpeer/pairing.py +139 -0
- package/dist/peer-kit/ctpeer/protocol.py +209 -0
- package/dist/peer-kit/ctpeer/websocket.py +289 -0
- package/dist/premiere-uxp/icons/panel.png +0 -0
- package/dist/premiere-uxp/icons/panel@2x.png +0 -0
- package/dist/premiere-uxp/icons/plugin.png +0 -0
- package/dist/premiere-uxp/icons/plugin@2x.png +0 -0
- package/dist/premiere-uxp/index.html +38 -0
- package/dist/premiere-uxp/index.js +93 -0
- package/dist/premiere-uxp/lib/clipmeta.js +170 -0
- package/dist/premiere-uxp/lib/ctx.js +68 -0
- package/dist/premiere-uxp/lib/edit.js +516 -0
- package/dist/premiere-uxp/lib/handles.js +57 -0
- package/dist/premiere-uxp/lib/markers.js +198 -0
- package/dist/premiere-uxp/lib/pairing.js +67 -0
- package/dist/premiere-uxp/lib/premiere.js +91 -0
- package/dist/premiere-uxp/lib/probe.js +241 -0
- package/dist/premiere-uxp/lib/protocol.js +165 -0
- package/dist/premiere-uxp/lib/render.js +45 -0
- package/dist/premiere-uxp/lib/session.js +85 -0
- package/dist/premiere-uxp/lib/sizing.js +325 -0
- package/dist/premiere-uxp/lib/time.js +88 -0
- package/dist/premiere-uxp/lib/timeline.js +336 -0
- package/dist/premiere-uxp/lib/verbs.js +21 -0
- package/dist/premiere-uxp/lib/write.js +97 -0
- package/dist/premiere-uxp/manifest.json +102 -0
- package/dist/probe-F7WQHMIA.js +3 -0
- package/dist/prores-RIG37OIH.js +526 -0
- package/dist/r3d-YTLOMC7C.js +3 -0
- package/dist/r3d-ZDJ3WURS.js +1025 -0
- package/dist/resolve-bridge.py +2286 -0
- package/dist/resolve-presets/conform.tools.xml +127 -0
- package/dist/source-BDJAUQVR.js +3 -0
- package/dist/statusline-GMMCFMOA.js +4 -0
- package/dist/statusline.js +3 -0
- package/dist/still-ZG2RUQAL.js +3 -0
- package/dist/store-ZHXLQCGN.js +3 -0
- package/dist/tiff-wasm-D2FJ3L56.js +3 -0
- package/dist/timeline-6DYFDVEH.js +3 -0
- package/dist/timeline_core-IOENXK4Z.js +3 -0
- package/dist/timeline_core_bg-JW42YM3G.js +3 -0
- package/dist/udf_bg-B37GKRIH.js +3 -0
- package/dist/wasm/media_core_bg.wasm +0 -0
- package/dist/wasm/udf_bg.wasm +0 -0
- package/dist/wasm-threads/media_core_bg.wasm +0 -0
- package/dist/wav-OWMUGQMM.js +3 -0
- package/package.json +6 -4
|
@@ -0,0 +1,622 @@
|
|
|
1
|
+
"""The render queue over Flame's `PyExporter` (the `render` capability).
|
|
2
|
+
|
|
3
|
+
Flame has no render queue: `PyExporter.export(sources, preset_path,
|
|
4
|
+
output_directory)` renders one thing NOW. So the queue lives here, and a job
|
|
5
|
+
moves queued -> rendering -> done | failed (| cancelled before it started):
|
|
6
|
+
|
|
7
|
+
* `submit` (main thread) checks the job against the sequence (range inside
|
|
8
|
+
it, track exists, a preset for the format) and files it - nothing renders.
|
|
9
|
+
* `start` (main thread) schedules ONE idle event per job and returns at
|
|
10
|
+
once: the RPC must answer inside the bridge's 30 s, and a render takes as
|
|
11
|
+
long as it takes.
|
|
12
|
+
* the idle event runs a FOREGROUND export (`foreground = True`, as Stefan's
|
|
13
|
+
render oracle and Autodesk's own scripts do; Flame renders straight to the
|
|
14
|
+
files, no framestore, no Backburner) with every `warn_on_*` dialog off.
|
|
15
|
+
It holds Flame's main thread for the whole render.
|
|
16
|
+
* `status`, `cancel`, `remove`, `jobs`, `is_rendering` and `current_output`
|
|
17
|
+
touch no Flame API (`ctpeer.off_main`): they answer from the job table and
|
|
18
|
+
the file system on the bridge worker WHILE the export holds the main
|
|
19
|
+
thread. Progress of an image sequence = distinct frame files seen / frames
|
|
20
|
+
expected (the analyzer deletes frames as it reads them, so frames are
|
|
21
|
+
remembered, not recounted).
|
|
22
|
+
|
|
23
|
+
A RANGE (`[first, last]`, absolute, inclusive) becomes the sequence's in /
|
|
24
|
+
out marks with `export_between_marks`: in = first, out = last + 1. Autodesk's
|
|
25
|
+
help says "sequences are exported between the In and Out marks: the marked
|
|
26
|
+
frames are not exported"; the hook reads that as an EXCLUSIVE out mark (in
|
|
27
|
+
frame rendered, out frame not). Unverified live - it is the first item of
|
|
28
|
+
the render checklist, and a delivery image sequence whose frame count does
|
|
29
|
+
not match fails loudly instead of passing silently. A TRACK renders that
|
|
30
|
+
video track alone: the other video tracks are hidden for the export (and
|
|
31
|
+
restored), with `use_top_video_track` on, so what renders is what the
|
|
32
|
+
Timeline shows. Marks and track states are put back whatever happens.
|
|
33
|
+
|
|
34
|
+
Formats: the analyzer's `tiff` (16-bit), `exr` (16-bit half float) and `dpx`
|
|
35
|
+
(10-bit) are Autodesk's own image-sequence presets, found by reading each
|
|
36
|
+
preset's XML (`type` image, `video/fileType`, `resize/bitsPerChannel`,
|
|
37
|
+
`floatingPoint`); `wav` an Audio preset; `preset` any export preset by name.
|
|
38
|
+
A preset's codec is named by the text in parentheses at the end of its file
|
|
39
|
+
name (Autodesk's own convention, "QuickTime (Apple ProRes 422 HQ)"): the XML
|
|
40
|
+
names codecs by number. Each job renders through a COPY of its preset with the name pattern set to
|
|
41
|
+
the job's name (and, for image sequences, numbered from the range's first
|
|
42
|
+
frame without timecode), so files land as `<target_dir>/<name>.<frame>.<ext>`.
|
|
43
|
+
No `qc_plugin`: the CONFORM.TOOLS QC codec is a Resolve IO plugin.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
from __future__ import annotations
|
|
47
|
+
|
|
48
|
+
import os
|
|
49
|
+
import re
|
|
50
|
+
import shutil
|
|
51
|
+
import tempfile
|
|
52
|
+
import threading
|
|
53
|
+
import time
|
|
54
|
+
import xml.etree.ElementTree as ET
|
|
55
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
56
|
+
|
|
57
|
+
from ctpeer import PeerError, off_main
|
|
58
|
+
|
|
59
|
+
from .util import _s, _v
|
|
60
|
+
|
|
61
|
+
#: How an absolute inclusive range [first, last] becomes marks: the out mark
|
|
62
|
+
#: sits on the frame AFTER the last one (see the module docstring).
|
|
63
|
+
OUT_MARK_AFTER_LAST = 1
|
|
64
|
+
|
|
65
|
+
#: `video/fileType` (lower case) -> the file extension Flame writes.
|
|
66
|
+
FILE_TYPE_EXT = {
|
|
67
|
+
"openexr": "exr", "exr": "exr", "tiff": "tif", "tif": "tif", "dpx": "dpx", "cineon": "cin", "jpeg": "jpg",
|
|
68
|
+
"jpg": "jpg", "png": "png", "targa": "tga", "sgi": "sgi", "quicktime": "mov", "mxf": "mxf", "mp4": "mp4",
|
|
69
|
+
"wave": "wav", "wav": "wav", "aiff": "aif", "broadcast wave": "wav",
|
|
70
|
+
}
|
|
71
|
+
#: The analyzer formats: (file type, bits per channel, floating point).
|
|
72
|
+
ANALYSIS_PRESETS = {"tiff": ("tif", 16, False), "exr": ("exr", 16, True), "dpx": ("dpx", 10, False)}
|
|
73
|
+
IMAGE_FORMATS = tuple(ANALYSIS_PRESETS)
|
|
74
|
+
WARNINGS_OFF = ("warn_on_unlinked", "warn_on_no_media", "warn_on_pending_render", "warn_on_unrendered",
|
|
75
|
+
"warn_on_mixed_colour_space", "warn_on_reimport_unsupported", "warn_on_link_unsupported")
|
|
76
|
+
_FRAME = re.compile(r"(\d+)\.[A-Za-z0-9]+$")
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def parse_preset(path: str) -> Dict[str, Any]:
|
|
80
|
+
"""What an export preset XML renders: `{kind, file_type, extension,
|
|
81
|
+
bits, float, width, height}` (`kind` image | movie | audio | sequence)."""
|
|
82
|
+
try:
|
|
83
|
+
root = ET.parse(path).getroot()
|
|
84
|
+
except (OSError, ET.ParseError):
|
|
85
|
+
return {}
|
|
86
|
+
kind = (root.findtext("type") or "").strip().lower()
|
|
87
|
+
file_type = ""
|
|
88
|
+
for tag in ("video", "movie", "audio"):
|
|
89
|
+
el = root.find(tag)
|
|
90
|
+
if el is not None and el.findtext("fileType"):
|
|
91
|
+
file_type = el.findtext("fileType").strip()
|
|
92
|
+
break
|
|
93
|
+
bits = root.findtext("video/resize/bitsPerChannel")
|
|
94
|
+
width, height = root.findtext("video/resize/width"), root.findtext("video/resize/height")
|
|
95
|
+
|
|
96
|
+
def _int(x: Optional[str]) -> Optional[int]:
|
|
97
|
+
try:
|
|
98
|
+
return int(str(x).strip())
|
|
99
|
+
except (TypeError, ValueError):
|
|
100
|
+
return None
|
|
101
|
+
|
|
102
|
+
stem = os.path.splitext(os.path.basename(path))[0]
|
|
103
|
+
m = re.search(r"\(([^()]+)\)\s*$", stem)
|
|
104
|
+
return {"kind": kind, "file_type": file_type, "codec_name": (m.group(1).strip() if m else file_type) or file_type, "extension": FILE_TYPE_EXT.get(file_type.lower(), file_type.lower()),
|
|
105
|
+
"bits": _int(bits), "float": (root.findtext("video/resize/floatingPoint") or "").strip().lower() == "true",
|
|
106
|
+
"width": _int(width) or None, "height": _int(height) or None}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def job_preset(path: str, name: str, first_frame: Optional[int], width: Optional[int] = None,
|
|
110
|
+
height: Optional[int] = None) -> str:
|
|
111
|
+
"""A copy of the preset at `path` that names the files `name` (every
|
|
112
|
+
`namePattern` of the movie / video / audio sections), numbers an image
|
|
113
|
+
sequence from `first_frame` without timecode and, when given, resizes to
|
|
114
|
+
`width` x `height` (`video/resize`; 0 = the source's). Returns the
|
|
115
|
+
copy's path."""
|
|
116
|
+
tree = ET.parse(path)
|
|
117
|
+
root = tree.getroot()
|
|
118
|
+
stem = re.sub(r"[<>]", "_", str(name or "render"))
|
|
119
|
+
kind = (root.findtext("type") or "").strip().lower()
|
|
120
|
+
for tag in ("movie", "video", "audio"):
|
|
121
|
+
el = root.find(tag)
|
|
122
|
+
if el is None:
|
|
123
|
+
continue
|
|
124
|
+
pat = el.find("namePattern")
|
|
125
|
+
if pat is None:
|
|
126
|
+
pat = ET.SubElement(el, "namePattern")
|
|
127
|
+
pat.text = stem + ("." if kind == "image" else "")
|
|
128
|
+
if kind == "image" and first_frame is not None:
|
|
129
|
+
name_el = root.find("name")
|
|
130
|
+
if name_el is None:
|
|
131
|
+
name_el = ET.SubElement(root, "name")
|
|
132
|
+
for tag, value in (("startFrame", str(int(first_frame))), ("useTimecode", "False")):
|
|
133
|
+
el = name_el.find(tag)
|
|
134
|
+
if el is None:
|
|
135
|
+
el = ET.SubElement(name_el, tag)
|
|
136
|
+
el.text = value
|
|
137
|
+
resize = root.find("video/resize")
|
|
138
|
+
if resize is not None:
|
|
139
|
+
for tag, value in (("width", width), ("height", height)):
|
|
140
|
+
if value:
|
|
141
|
+
el = resize.find(tag)
|
|
142
|
+
if el is None:
|
|
143
|
+
el = ET.SubElement(resize, tag)
|
|
144
|
+
el.text = str(int(value))
|
|
145
|
+
# Never in the target folder: the analyzer reads every numbered file there.
|
|
146
|
+
fd, copy = tempfile.mkstemp(prefix="ct_flame_preset_", suffix=".xml")
|
|
147
|
+
os.close(fd)
|
|
148
|
+
tree.write(copy, encoding="utf-8", xml_declaration=True)
|
|
149
|
+
return copy
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def _dim(value: Any) -> Optional[int]:
|
|
153
|
+
try:
|
|
154
|
+
n = int(value)
|
|
155
|
+
except (TypeError, ValueError):
|
|
156
|
+
return None
|
|
157
|
+
return n if n > 0 else None
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
class RenderVerbs:
|
|
161
|
+
"""Mixed into `verbs.FlamePeer` (which provides `flame`, `handles`,
|
|
162
|
+
`_seq`, `_rate`, `_start`, `_video_tracks`, `_track_segments`,
|
|
163
|
+
`_seg_times`)."""
|
|
164
|
+
|
|
165
|
+
def __init__(self) -> None:
|
|
166
|
+
self._render_lock = threading.Lock()
|
|
167
|
+
self._render_jobs: Dict[str, Dict[str, Any]] = {}
|
|
168
|
+
self._render_n = 0
|
|
169
|
+
self._prepared: Dict[str, Any] = {}
|
|
170
|
+
|
|
171
|
+
# ── presets ─────────────────────────────────────────────────────────
|
|
172
|
+
def _preset_roots(self) -> List[Tuple[str, str, str]]:
|
|
173
|
+
"""`(label, visibility label, directory)` for every preset folder
|
|
174
|
+
Flame reports (Autodesk / Shared / User / Project x Image Sequence /
|
|
175
|
+
Movie / Audio)."""
|
|
176
|
+
ex = getattr(self.flame, "PyExporter", None)
|
|
177
|
+
if ex is None:
|
|
178
|
+
return []
|
|
179
|
+
out = []
|
|
180
|
+
for vis in ("Autodesk", "Shared", "User", "Project"):
|
|
181
|
+
for ptype, label in (("Image_Sequence", "Image Sequence"), ("Movie", "Movie"), ("Audio", "Audio")):
|
|
182
|
+
try:
|
|
183
|
+
d = ex.get_presets_dir(getattr(ex.PresetVisibility, vis), getattr(ex.PresetType, ptype))
|
|
184
|
+
except Exception:
|
|
185
|
+
continue
|
|
186
|
+
if d and os.path.isdir(str(d)):
|
|
187
|
+
out.append((label, vis, str(d)))
|
|
188
|
+
return out
|
|
189
|
+
|
|
190
|
+
def _preset_table(self) -> Dict[str, str]:
|
|
191
|
+
"""`{name: path}`: `"<type>/<folder>/<preset>"` without `.xml`; a
|
|
192
|
+
name another visibility already took gets ` (<visibility>)`."""
|
|
193
|
+
table: Dict[str, str] = {}
|
|
194
|
+
for label, vis, root in self._preset_roots():
|
|
195
|
+
for dirpath, _dirs, files in os.walk(root):
|
|
196
|
+
for f in sorted(files):
|
|
197
|
+
if not f.lower().endswith(".xml"):
|
|
198
|
+
continue
|
|
199
|
+
path = os.path.join(dirpath, f)
|
|
200
|
+
rel = os.path.relpath(path, root)[:-4].replace(os.sep, "/")
|
|
201
|
+
name = f"{label}/{rel}"
|
|
202
|
+
if name in table:
|
|
203
|
+
name = f"{name} ({vis})"
|
|
204
|
+
table.setdefault(name, path)
|
|
205
|
+
return table
|
|
206
|
+
|
|
207
|
+
def _resolve_preset(self, name: Any) -> Optional[str]:
|
|
208
|
+
"""A preset by table name, by its last path part, or an existing XML path."""
|
|
209
|
+
text = str(name or "").strip()
|
|
210
|
+
if not text:
|
|
211
|
+
return None
|
|
212
|
+
if text.lower().endswith(".xml") and os.path.isfile(text):
|
|
213
|
+
return text
|
|
214
|
+
table = self._preset_table()
|
|
215
|
+
if text in table:
|
|
216
|
+
return table[text]
|
|
217
|
+
for key, path in table.items():
|
|
218
|
+
if key.rsplit("/", 1)[-1] == text or key.endswith("/" + text):
|
|
219
|
+
return path
|
|
220
|
+
return None
|
|
221
|
+
|
|
222
|
+
def _analysis_preset(self, fmt: str) -> Optional[str]:
|
|
223
|
+
"""The Autodesk-shipped image-sequence (or audio) preset for an
|
|
224
|
+
analyzer format: the exact bit depth first, any depth of the type next."""
|
|
225
|
+
exact, loose = None, None
|
|
226
|
+
for name, path in sorted(self._preset_table().items()):
|
|
227
|
+
info = parse_preset(path)
|
|
228
|
+
if fmt == "wav":
|
|
229
|
+
if info.get("kind") == "audio" and info.get("extension") == "wav":
|
|
230
|
+
return path
|
|
231
|
+
continue
|
|
232
|
+
want_ext, bits, fp = ANALYSIS_PRESETS[fmt]
|
|
233
|
+
if info.get("kind") != "image" or info.get("extension") != want_ext:
|
|
234
|
+
continue
|
|
235
|
+
if info.get("bits") == bits and bool(info.get("float")) == fp:
|
|
236
|
+
exact = exact or path
|
|
237
|
+
loose = loose or path
|
|
238
|
+
return exact or loose
|
|
239
|
+
|
|
240
|
+
# ── the capability ──────────────────────────────────────────────────
|
|
241
|
+
def v_render__outputs(self) -> List[str]:
|
|
242
|
+
out = ["preset"] if self._preset_table() else []
|
|
243
|
+
for fmt in IMAGE_FORMATS + ("wav",):
|
|
244
|
+
if self._analysis_preset(fmt):
|
|
245
|
+
out.append(fmt)
|
|
246
|
+
return out
|
|
247
|
+
|
|
248
|
+
def v_render__prepare(self, purpose: str = "deliver", hints: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
|
249
|
+
hints = dict(hints or {})
|
|
250
|
+
fmt = str(hints.get("format") or "").lower()
|
|
251
|
+
if fmt == "qc_plugin":
|
|
252
|
+
return {"ok": False, "error": "Flame has no CONFORM.TOOLS QC plugin: analyse an image sequence (tiff / exr / dpx)"}
|
|
253
|
+
if fmt in IMAGE_FORMATS or fmt == "wav":
|
|
254
|
+
path = self._analysis_preset(fmt)
|
|
255
|
+
if not path:
|
|
256
|
+
return {"ok": False, "error": f"Flame has no {fmt} export preset in its preset folders"}
|
|
257
|
+
elif hints.get("preset"):
|
|
258
|
+
path = self._resolve_preset(hints.get("preset"))
|
|
259
|
+
if not path:
|
|
260
|
+
return {"ok": False, "error": f"no Flame export preset called '{hints.get('preset')}'"}
|
|
261
|
+
else:
|
|
262
|
+
return {"ok": False, "error": "say which preset (or analysis format) to render with"}
|
|
263
|
+
info = parse_preset(path)
|
|
264
|
+
with self._render_lock:
|
|
265
|
+
self._prepared = {"purpose": str(purpose or "deliver"), "path": path, "format": info.get("extension", ""),
|
|
266
|
+
"codec": info.get("codec_name", ""), "preset": os.path.splitext(os.path.basename(path))[0]}
|
|
267
|
+
return {"ok": True, "preset": self._prepared["preset"], "format": self._prepared["format"], "codec": self._prepared["codec"]}
|
|
268
|
+
|
|
269
|
+
def v_render__submit(self, timeline: Any, job: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
|
270
|
+
job = dict(job or {})
|
|
271
|
+
seq = self._seq(timeline)
|
|
272
|
+
purpose = str(job.get("purpose") or "deliver")
|
|
273
|
+
fmt = str(job.get("format") or "preset").lower()
|
|
274
|
+
|
|
275
|
+
def refuse(stage: str, why: str) -> Dict[str, Any]:
|
|
276
|
+
return {"id": None, "stage": stage, "error": why}
|
|
277
|
+
|
|
278
|
+
if fmt == "qc_plugin":
|
|
279
|
+
return refuse("settings", "Flame has no CONFORM.TOOLS QC plugin: analyse an image sequence (tiff / exr / dpx)")
|
|
280
|
+
if fmt in IMAGE_FORMATS or fmt == "wav":
|
|
281
|
+
path = self._analysis_preset(fmt)
|
|
282
|
+
elif fmt == "preset":
|
|
283
|
+
path = self._resolve_preset(job.get("preset")) if job.get("preset") else self._prepared.get("path")
|
|
284
|
+
else:
|
|
285
|
+
return refuse("settings", f"Flame cannot render '{fmt}'")
|
|
286
|
+
if not path:
|
|
287
|
+
return refuse("settings", f"no Flame export preset for '{job.get('preset') or fmt}' - prepare one first")
|
|
288
|
+
target = str(job.get("target_dir") or "")
|
|
289
|
+
if not target:
|
|
290
|
+
return refuse("settings", "a render needs a target folder")
|
|
291
|
+
start = self._start(seq)
|
|
292
|
+
fps, _ = self._rate(seq)
|
|
293
|
+
end = start + self._count(getattr(seq, "duration", None), fps)
|
|
294
|
+
rng = job.get("range")
|
|
295
|
+
if rng is not None:
|
|
296
|
+
try:
|
|
297
|
+
first, last = int(rng[0]), int(rng[1])
|
|
298
|
+
except (TypeError, ValueError, IndexError):
|
|
299
|
+
return refuse("settings", f"not a frame range: {rng!r}")
|
|
300
|
+
if not (start <= first <= last < max(end, start + 1)):
|
|
301
|
+
return refuse("settings", f"frames {first}-{last} are outside the sequence ({start}-{end - 1})")
|
|
302
|
+
rng = [first, last]
|
|
303
|
+
track = job.get("track")
|
|
304
|
+
if track is not None:
|
|
305
|
+
n = len(self._video_tracks(seq))
|
|
306
|
+
if not 1 <= int(track) <= n:
|
|
307
|
+
return refuse("settings", f"the sequence has no video track {track} (it has {n})")
|
|
308
|
+
track = int(track)
|
|
309
|
+
try:
|
|
310
|
+
os.makedirs(target, exist_ok=True)
|
|
311
|
+
except OSError as e:
|
|
312
|
+
return refuse("settings", f"cannot use the target folder: {e}")
|
|
313
|
+
info = parse_preset(path)
|
|
314
|
+
with self._render_lock:
|
|
315
|
+
self._render_n += 1
|
|
316
|
+
job_id = f"flame-render-{self._render_n}"
|
|
317
|
+
self._render_jobs[job_id] = {
|
|
318
|
+
"id": job_id, "name": str(job.get("name") or _s(getattr(seq, "name", "")) or job_id),
|
|
319
|
+
"timeline": _s(getattr(seq, "name", "")), "seq": timeline, "target_dir": target, "purpose": purpose,
|
|
320
|
+
"format": fmt, "preset_path": path, "kind": info.get("kind", ""), "extension": info.get("extension", ""),
|
|
321
|
+
"range": rng, "track": track, "width": _dim(job.get("width")), "height": _dim(job.get("height")),
|
|
322
|
+
"state": "queued", "progress": None, "error": "",
|
|
323
|
+
"expected": (rng[1] - rng[0] + 1) if rng else (end - start if end > start else None),
|
|
324
|
+
"seen": set(), "files": [], "started": None,
|
|
325
|
+
}
|
|
326
|
+
return {"id": job_id}
|
|
327
|
+
|
|
328
|
+
def v_render__start(self, job_ids: Optional[List[str]] = None) -> bool:
|
|
329
|
+
scheduled = False
|
|
330
|
+
for job_id in [str(j) for j in (job_ids or [])]:
|
|
331
|
+
with self._render_lock:
|
|
332
|
+
job = self._render_jobs.get(job_id)
|
|
333
|
+
if job is None or job["state"] not in ("queued", "failed", "cancelled"):
|
|
334
|
+
continue
|
|
335
|
+
job.update(state="queued", error="", progress=None, scheduled=True)
|
|
336
|
+
self.flame.schedule_idle_event(lambda job_id=job_id: self._run_job(job_id))
|
|
337
|
+
scheduled = True
|
|
338
|
+
return scheduled
|
|
339
|
+
|
|
340
|
+
@off_main
|
|
341
|
+
def v_render__status(self, job_id: str = "") -> Optional[Dict[str, Any]]:
|
|
342
|
+
with self._render_lock:
|
|
343
|
+
job = self._render_jobs.get(str(job_id))
|
|
344
|
+
if job is None:
|
|
345
|
+
return None
|
|
346
|
+
state, error = job["state"], job["error"]
|
|
347
|
+
progress: Optional[float]
|
|
348
|
+
if state == "done":
|
|
349
|
+
progress = 100.0
|
|
350
|
+
elif state == "rendering":
|
|
351
|
+
progress = self._progress(job)
|
|
352
|
+
elif state == "queued":
|
|
353
|
+
progress = 0.0
|
|
354
|
+
else:
|
|
355
|
+
progress = None
|
|
356
|
+
return {"state": state, "progress": progress, "error": error}
|
|
357
|
+
|
|
358
|
+
@off_main
|
|
359
|
+
def v_render__cancel(self, job_id: str = "") -> bool:
|
|
360
|
+
"""A queued job never starts. A RUNNING foreground export cannot be
|
|
361
|
+
stopped from Python (Flame's own progress dialog can): False."""
|
|
362
|
+
with self._render_lock:
|
|
363
|
+
job = self._render_jobs.get(str(job_id))
|
|
364
|
+
if job is None or job["state"] != "queued":
|
|
365
|
+
return False
|
|
366
|
+
job["state"] = "cancelled"
|
|
367
|
+
return True
|
|
368
|
+
|
|
369
|
+
@off_main
|
|
370
|
+
def v_render__remove(self, job_id: str = "") -> bool:
|
|
371
|
+
"""Forget the job (never its files). Not while it renders."""
|
|
372
|
+
with self._render_lock:
|
|
373
|
+
job = self._render_jobs.get(str(job_id))
|
|
374
|
+
if job is None or job["state"] == "rendering":
|
|
375
|
+
return False
|
|
376
|
+
del self._render_jobs[str(job_id)]
|
|
377
|
+
return True
|
|
378
|
+
|
|
379
|
+
@off_main
|
|
380
|
+
def v_render__jobs(self) -> List[Dict[str, Any]]:
|
|
381
|
+
with self._render_lock:
|
|
382
|
+
return [{"id": j["id"], "name": j["name"], "timeline": j["timeline"], "target_dir": j["target_dir"]}
|
|
383
|
+
for j in self._render_jobs.values()]
|
|
384
|
+
|
|
385
|
+
@off_main
|
|
386
|
+
def v_render__remove_all(self) -> bool:
|
|
387
|
+
with self._render_lock:
|
|
388
|
+
keep = {k: v for k, v in self._render_jobs.items() if v["state"] == "rendering"}
|
|
389
|
+
self._render_jobs = keep
|
|
390
|
+
return not keep
|
|
391
|
+
|
|
392
|
+
@off_main
|
|
393
|
+
def v_render__is_rendering(self) -> bool:
|
|
394
|
+
with self._render_lock:
|
|
395
|
+
return any(j["state"] == "rendering" for j in self._render_jobs.values())
|
|
396
|
+
|
|
397
|
+
def v_render__presets(self) -> List[str]:
|
|
398
|
+
return sorted(self._preset_table())
|
|
399
|
+
|
|
400
|
+
def v_render__preset_info(self, name: str = "") -> Dict[str, Any]:
|
|
401
|
+
path = self._resolve_preset(name)
|
|
402
|
+
if not path:
|
|
403
|
+
return {}
|
|
404
|
+
info = parse_preset(path)
|
|
405
|
+
out = {"format": info.get("extension", ""), "extension": info.get("extension", ""), "codec": info.get("codec_name", ""),
|
|
406
|
+
"codec_description": info.get("codec_name", ""), "file_type": info.get("file_type", ""), "kind": info.get("kind", ""), "path": path}
|
|
407
|
+
if info.get("width"):
|
|
408
|
+
out["width"] = info["width"]
|
|
409
|
+
if info.get("height"):
|
|
410
|
+
out["height"] = info["height"]
|
|
411
|
+
if info.get("bits"):
|
|
412
|
+
out["bit_depth"] = info["bits"]
|
|
413
|
+
return out
|
|
414
|
+
|
|
415
|
+
def v_render__formats(self) -> Dict[str, str]:
|
|
416
|
+
"""`{file type: extension}` of every preset Flame has."""
|
|
417
|
+
out: Dict[str, str] = {}
|
|
418
|
+
for path in self._preset_table().values():
|
|
419
|
+
info = parse_preset(path)
|
|
420
|
+
if info.get("file_type"):
|
|
421
|
+
out.setdefault(info["file_type"], info.get("extension", ""))
|
|
422
|
+
return out
|
|
423
|
+
|
|
424
|
+
def v_render__codecs(self, fmt: str = "") -> Dict[str, str]:
|
|
425
|
+
"""`{codec: codec}` of the presets writing `fmt` (a file type or an
|
|
426
|
+
extension). Flame's preset XML names its codec by number; the
|
|
427
|
+
preset's own name carries it in parentheses ("QuickTime (Apple
|
|
428
|
+
ProRes 422 HQ)"), which is what this answers."""
|
|
429
|
+
want = str(fmt or "").lower()
|
|
430
|
+
out: Dict[str, str] = {}
|
|
431
|
+
for path in self._preset_table().values():
|
|
432
|
+
info = parse_preset(path)
|
|
433
|
+
if want in (str(info.get("extension", "")).lower(), str(info.get("file_type", "")).lower()):
|
|
434
|
+
out.setdefault(info["codec_name"], info["codec_name"])
|
|
435
|
+
return out
|
|
436
|
+
|
|
437
|
+
@off_main
|
|
438
|
+
def v_render__current_output(self) -> Dict[str, Any]:
|
|
439
|
+
with self._render_lock:
|
|
440
|
+
p = dict(self._prepared)
|
|
441
|
+
return {"format": p.get("format", ""), "codec": p.get("codec", ""), "preset": p.get("preset", "")} if p else {}
|
|
442
|
+
|
|
443
|
+
# ── running one job (an idle event on the main thread) ──────────────
|
|
444
|
+
def _frames_on_disk(self, job: Dict[str, Any]) -> List[str]:
|
|
445
|
+
prefix = job["name"] + "."
|
|
446
|
+
try:
|
|
447
|
+
names = os.listdir(job["target_dir"])
|
|
448
|
+
except OSError:
|
|
449
|
+
return []
|
|
450
|
+
return sorted(n for n in names if n.startswith(prefix))
|
|
451
|
+
|
|
452
|
+
def _progress(self, job: Dict[str, Any]) -> Optional[float]:
|
|
453
|
+
if job["kind"] != "image" or not job.get("expected"):
|
|
454
|
+
return None
|
|
455
|
+
for n in self._frames_on_disk(job):
|
|
456
|
+
m = _FRAME.search(n)
|
|
457
|
+
if m:
|
|
458
|
+
job["seen"].add(int(m.group(1)))
|
|
459
|
+
return round(min(99.0, 100.0 * len(job["seen"]) / float(job["expected"])), 1)
|
|
460
|
+
|
|
461
|
+
def _set_marks(self, seq: Any, rng: Optional[List[int]]) -> Tuple[Any, Any]:
|
|
462
|
+
old = (_v(getattr(seq, "in_mark", None)), _v(getattr(seq, "out_mark", None)))
|
|
463
|
+
if rng:
|
|
464
|
+
rate = _s(getattr(seq, "frame_rate", "")) or "24 fps"
|
|
465
|
+
seq.in_mark = self.flame.PyTime(int(rng[0]), rate)
|
|
466
|
+
seq.out_mark = self.flame.PyTime(int(rng[1]) + OUT_MARK_AFTER_LAST, rate)
|
|
467
|
+
return old
|
|
468
|
+
|
|
469
|
+
def _restore_marks(self, seq: Any, old: Tuple[Any, Any]) -> None:
|
|
470
|
+
for attr, value in zip(("in_mark", "out_mark"), old):
|
|
471
|
+
try:
|
|
472
|
+
setattr(seq, attr, value)
|
|
473
|
+
except Exception:
|
|
474
|
+
pass
|
|
475
|
+
|
|
476
|
+
def _solo(self, seq: Any, track: Optional[int]) -> List[Tuple[Any, Any]]:
|
|
477
|
+
saved: List[Tuple[Any, Any]] = []
|
|
478
|
+
if not track:
|
|
479
|
+
return saved
|
|
480
|
+
for i, t in enumerate(self._video_tracks(seq), 1):
|
|
481
|
+
saved.append((t, _v(getattr(t, "hidden", False))))
|
|
482
|
+
t.hidden = i != track
|
|
483
|
+
return saved
|
|
484
|
+
|
|
485
|
+
def _exporter(self, between_marks: bool) -> Any:
|
|
486
|
+
"""A FOREGROUND `PyExporter` with every warning dialog off, rendering
|
|
487
|
+
what the Timeline shows (`use_top_video_track`)."""
|
|
488
|
+
exporter = self.flame.PyExporter()
|
|
489
|
+
exporter.foreground = True
|
|
490
|
+
for warn in WARNINGS_OFF:
|
|
491
|
+
try:
|
|
492
|
+
setattr(exporter, warn, False)
|
|
493
|
+
except (AttributeError, TypeError):
|
|
494
|
+
pass
|
|
495
|
+
exporter.use_top_video_track = True
|
|
496
|
+
exporter.export_between_marks = bool(between_marks)
|
|
497
|
+
return exporter
|
|
498
|
+
|
|
499
|
+
def _run_job(self, job_id: str) -> None:
|
|
500
|
+
with self._render_lock:
|
|
501
|
+
job = self._render_jobs.get(job_id)
|
|
502
|
+
if job is None or job["state"] != "queued":
|
|
503
|
+
return # cancelled or removed before its turn
|
|
504
|
+
job.update(state="rendering", started=time.time(), progress=0.0)
|
|
505
|
+
error, files = "", []
|
|
506
|
+
seq = None
|
|
507
|
+
marks: Tuple[Any, Any] = (None, None)
|
|
508
|
+
solo: List[Tuple[Any, Any]] = []
|
|
509
|
+
preset_copy = ""
|
|
510
|
+
try:
|
|
511
|
+
try:
|
|
512
|
+
seq = self._seq(job["seq"])
|
|
513
|
+
except PeerError:
|
|
514
|
+
raise RuntimeError("the sequence is gone (the project changed?)")
|
|
515
|
+
preset_copy = job_preset(job["preset_path"], job["name"], job["range"][0] if job["range"] else None,
|
|
516
|
+
job.get("width"), job.get("height"))
|
|
517
|
+
exporter = self._exporter(between_marks=bool(job["range"]))
|
|
518
|
+
marks = self._set_marks(seq, job["range"])
|
|
519
|
+
solo = self._solo(seq, job["track"])
|
|
520
|
+
exporter.export(seq, preset_copy, job["target_dir"])
|
|
521
|
+
files = [os.path.join(job["target_dir"], n) for n in self._frames_on_disk(job)]
|
|
522
|
+
if job["kind"] == "image" and job["purpose"] == "deliver" and job.get("expected") and len(files) != job["expected"]:
|
|
523
|
+
error = f"Flame wrote {len(files)} frame(s), {job['expected']} expected"
|
|
524
|
+
elif job["kind"] != "image" and not files:
|
|
525
|
+
error = "Flame reported no error but wrote no file"
|
|
526
|
+
except Exception as e:
|
|
527
|
+
error = f"{type(e).__name__}: {e}" if str(e) else type(e).__name__
|
|
528
|
+
finally:
|
|
529
|
+
if seq is not None:
|
|
530
|
+
self._restore_marks(seq, marks)
|
|
531
|
+
for t, hidden in solo:
|
|
532
|
+
try:
|
|
533
|
+
t.hidden = bool(hidden)
|
|
534
|
+
except Exception:
|
|
535
|
+
pass
|
|
536
|
+
if preset_copy:
|
|
537
|
+
try:
|
|
538
|
+
os.remove(preset_copy)
|
|
539
|
+
except OSError:
|
|
540
|
+
pass
|
|
541
|
+
with self._render_lock:
|
|
542
|
+
if job_id in self._render_jobs:
|
|
543
|
+
job["files"] = files
|
|
544
|
+
job.update(state="failed" if error else "done", error=error, progress=None if error else 100.0)
|
|
545
|
+
if job["kind"] == "image":
|
|
546
|
+
self._progress(job)
|
|
547
|
+
log = getattr(self, "_log_console", None)
|
|
548
|
+
if callable(log):
|
|
549
|
+
log(f"render '{job['name']}': {'failed - ' + error if error else 'done'}")
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
class FrameVerbs:
|
|
554
|
+
"""`frames.grab`: ONE frame of a sequence as the analyzer's 16-bit TIFF
|
|
555
|
+
(else half EXR / 10-bit DPX), through the same foreground export as a
|
|
556
|
+
render job - in / out marks around the frame, the asked track solo -
|
|
557
|
+
but run NOW, inside the verb (it is already on Flame's main thread; one
|
|
558
|
+
frame renders well inside the bridge's call timeout). Mixed into
|
|
559
|
+
`verbs.FlamePeer` after `RenderVerbs`, whose plumbing it uses.
|
|
560
|
+
|
|
561
|
+
`frame` None = the frame under the playhead; a frame moves the playhead
|
|
562
|
+
there first (as Resolve's grab does). The file lands beside the asked
|
|
563
|
+
`path`, with the extension Flame really wrote (`.tif`); the desktop
|
|
564
|
+
accepts only that folder. Marks, track states and the playhead's frame
|
|
565
|
+
are put back whatever happens."""
|
|
566
|
+
|
|
567
|
+
STILL_NAME = "ct_still"
|
|
568
|
+
|
|
569
|
+
def v_frames__can_grab_track(self) -> bool:
|
|
570
|
+
return True
|
|
571
|
+
|
|
572
|
+
def v_frames__grab(self, timeline: Any = None, frame: Optional[int] = None, path: str = "",
|
|
573
|
+
track: Optional[int] = None) -> Dict[str, Any]:
|
|
574
|
+
if not str(path or ""):
|
|
575
|
+
raise PeerError("bad_params", "a grab needs a path")
|
|
576
|
+
seq = self._seq(timeline)
|
|
577
|
+
start = self._start(seq)
|
|
578
|
+
fps, _ = self._rate(seq)
|
|
579
|
+
end = start + self._count(getattr(seq, "duration", None), fps)
|
|
580
|
+
if frame is None:
|
|
581
|
+
ph = self._playhead(seq)
|
|
582
|
+
frame = ph if ph is not None else start
|
|
583
|
+
else:
|
|
584
|
+
self._set_playhead(seq, int(frame))
|
|
585
|
+
frame = int(frame)
|
|
586
|
+
if not start <= frame < max(end, start + 1):
|
|
587
|
+
return {}
|
|
588
|
+
if track is not None and not 1 <= int(track) <= len(self._video_tracks(seq)):
|
|
589
|
+
return {}
|
|
590
|
+
preset = next((p for p in (self._analysis_preset(f) for f in IMAGE_FORMATS) if p), None)
|
|
591
|
+
if not preset:
|
|
592
|
+
return {}
|
|
593
|
+
work = tempfile.mkdtemp(prefix="ct_flame_still_")
|
|
594
|
+
copy = ""
|
|
595
|
+
marks: Tuple[Any, Any] = (None, None)
|
|
596
|
+
solo: List[Tuple[Any, Any]] = []
|
|
597
|
+
try:
|
|
598
|
+
copy = job_preset(preset, self.STILL_NAME, frame)
|
|
599
|
+
exporter = self._exporter(between_marks=True)
|
|
600
|
+
marks = self._set_marks(seq, [frame, frame])
|
|
601
|
+
solo = self._solo(seq, int(track) if track is not None else None)
|
|
602
|
+
exporter.export(seq, copy, work)
|
|
603
|
+
files = sorted(n for n in os.listdir(work) if n.startswith(self.STILL_NAME + "."))
|
|
604
|
+
if not files:
|
|
605
|
+
return {}
|
|
606
|
+
final = os.path.splitext(str(path))[0] + os.path.splitext(files[0])[1]
|
|
607
|
+
os.makedirs(os.path.dirname(final) or ".", exist_ok=True)
|
|
608
|
+
shutil.move(os.path.join(work, files[0]), final)
|
|
609
|
+
return {"path": final}
|
|
610
|
+
finally:
|
|
611
|
+
self._restore_marks(seq, marks)
|
|
612
|
+
for t, hidden in solo:
|
|
613
|
+
try:
|
|
614
|
+
t.hidden = bool(hidden)
|
|
615
|
+
except Exception:
|
|
616
|
+
pass
|
|
617
|
+
if copy:
|
|
618
|
+
try:
|
|
619
|
+
os.remove(copy)
|
|
620
|
+
except OSError:
|
|
621
|
+
pass
|
|
622
|
+
shutil.rmtree(work, ignore_errors=True)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""Small helpers every verb module shares (no Flame calls here)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from typing import Any, Tuple
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _v(x: Any) -> Any:
|
|
10
|
+
"""A PyAttribute's value (Flame wraps every dynamic attribute)."""
|
|
11
|
+
get = getattr(x, "get_value", None)
|
|
12
|
+
if callable(get):
|
|
13
|
+
try:
|
|
14
|
+
return get()
|
|
15
|
+
except Exception:
|
|
16
|
+
return None
|
|
17
|
+
return x
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _s(x: Any) -> str:
|
|
21
|
+
v = _v(x)
|
|
22
|
+
return "" if v is None else str(v).strip("'")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def parse_rate(rate: Any) -> Tuple[float, bool]:
|
|
26
|
+
"""Flame's frame-rate string (`"23.976 fps"`, `"29.97 DF"`, `"29.97 NDF"`,
|
|
27
|
+
`"25 fps"`) -> (fps, drop frame)."""
|
|
28
|
+
s = _s(rate)
|
|
29
|
+
m = re.match(r"^\s*([0-9]+(?:\.[0-9]+)?)", s)
|
|
30
|
+
fps = float(m.group(1)) if m else 24.0
|
|
31
|
+
up = s.upper()
|
|
32
|
+
drop = bool(re.search(r"\bDF\b", up)) and "NDF" not in up
|
|
33
|
+
return fps, drop
|