conformtools 0.5.1 → 0.6.0

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.
Files changed (96) hide show
  1. package/README.md +58 -0
  2. package/dist/browser/timeline_core_bg.wasm +0 -0
  3. package/dist/chunk-6TM32YIJ.js +7 -0
  4. package/dist/chunk-7XTBFOUJ.js +3 -0
  5. package/dist/chunk-E6YXZIJS.js +230 -0
  6. package/dist/chunk-GXEVALBL.js +3 -0
  7. package/dist/{chunk-YPRTUS5W.js → chunk-N43NAG5E.js} +1 -1
  8. package/dist/chunk-PSMXHDMX.js +3 -0
  9. package/dist/chunk-PZFWQJCF.js +3 -0
  10. package/dist/chunk-R6WJ6JIQ.js +3 -0
  11. package/dist/chunk-UUDNNFU7.js +3 -0
  12. package/dist/chunk-XDHIIZ6A.js +3 -0
  13. package/dist/chunk-Y2BEEOPB.js +3 -0
  14. package/dist/chunk-ZAHP3ES5.js +3 -0
  15. package/dist/cli.js +5 -4
  16. package/dist/cr3-wasm-CWKEOCYH.js +3 -0
  17. package/dist/dng-wasm-JNFS44V5.js +3 -0
  18. package/dist/dpx-wasm-VNJRFPYY.js +3 -0
  19. package/dist/exr-wasm-5D66YR7A.js +3 -0
  20. package/dist/{h264-JHQCJTWP.js → h264-ZB5DJSNV.js} +1 -1
  21. package/dist/{h264-mxf-4M63NBQK.js → h264-mxf-NVBLGU3V.js} +1 -1
  22. package/dist/http.js +2 -2
  23. package/dist/{inspect-6OM4FTVW.js → inspect-MGSZRRAF.js} +2 -2
  24. package/dist/isobmff-7G55HKDG.js +3 -0
  25. package/dist/mcp.js +11 -9
  26. package/dist/media_core-AISE7FMT.js +9 -0
  27. package/dist/{media_core_bg-XIM7Y4R3.js → media_core_bg-FGAR5KA5.js} +1 -1
  28. package/dist/mxf-YH2A2XLW.js +3 -0
  29. package/dist/{ops-7HVBBXUQ.js → ops-BQDPU4M6.js} +1 -1
  30. package/dist/premiere-uxp/icons/panel.png +0 -0
  31. package/dist/premiere-uxp/icons/panel@2x.png +0 -0
  32. package/dist/premiere-uxp/icons/plugin.png +0 -0
  33. package/dist/premiere-uxp/icons/plugin@2x.png +0 -0
  34. package/dist/premiere-uxp/index.html +38 -0
  35. package/dist/premiere-uxp/index.js +93 -0
  36. package/dist/premiere-uxp/lib/clipmeta.js +170 -0
  37. package/dist/premiere-uxp/lib/ctx.js +62 -0
  38. package/dist/premiere-uxp/lib/handles.js +57 -0
  39. package/dist/premiere-uxp/lib/markers.js +198 -0
  40. package/dist/premiere-uxp/lib/pairing.js +58 -0
  41. package/dist/premiere-uxp/lib/premiere.js +82 -0
  42. package/dist/premiere-uxp/lib/probe.js +139 -0
  43. package/dist/premiere-uxp/lib/protocol.js +165 -0
  44. package/dist/premiere-uxp/lib/render.js +38 -0
  45. package/dist/premiere-uxp/lib/session.js +85 -0
  46. package/dist/premiere-uxp/lib/sizing.js +312 -0
  47. package/dist/premiere-uxp/lib/time.js +82 -0
  48. package/dist/premiere-uxp/lib/timeline.js +336 -0
  49. package/dist/premiere-uxp/lib/verbs.js +20 -0
  50. package/dist/premiere-uxp/lib/write.js +97 -0
  51. package/dist/premiere-uxp/manifest.json +102 -0
  52. package/dist/r3d-T6D3M2XJ.js +3 -0
  53. package/dist/{r3d-AT6NNIY3.js → r3d-U4XTQJXQ.js} +1 -1
  54. package/dist/resolve-bridge.py +551 -0
  55. package/dist/resolve-presets/conform.tools.xml +127 -0
  56. package/dist/skills/auto-conform/SKILL.md +87 -0
  57. package/dist/skills/conform-artist/SKILL.md +68 -0
  58. package/dist/skills/conform-artist/references/avid.md +19 -0
  59. package/dist/skills/conform-artist/references/other-hosts.md +23 -0
  60. package/dist/skills/conform-artist/references/premiere.md +18 -0
  61. package/dist/skills/conform-artist/references/resolve.md +19 -0
  62. package/dist/skills/conform-artist/references/troubleshooting.md +33 -0
  63. package/dist/skills/conform-artist/references/turnover-checklist.md +37 -0
  64. package/dist/skills/delivery-qc/SKILL.md +48 -0
  65. package/dist/sscd-embed-DHFTEIOC.js +3 -0
  66. package/dist/sscd-sweep-OYS4XAID.js +3 -0
  67. package/dist/{still-E4HLCCST.js → still-UFLOAEM4.js} +1 -1
  68. package/dist/tiff-wasm-2CEABW6L.js +3 -0
  69. package/dist/wasm/media_core_bg.wasm +0 -0
  70. package/dist/wasm/udf_bg.wasm +0 -0
  71. package/dist/wasm-threads/media_core_bg.wasm +0 -0
  72. package/dist/{wav-DXF73Y56.js → wav-KNJZMOGX.js} +1 -1
  73. package/package.json +1 -1
  74. package/dist/chunk-35U7WGES.js +0 -3
  75. package/dist/chunk-3XTUTEKJ.js +0 -102
  76. package/dist/chunk-HJXRLQOI.js +0 -3
  77. package/dist/chunk-IDDQR56R.js +0 -7
  78. package/dist/chunk-UUMHVA7R.js +0 -3
  79. package/dist/chunk-WWGQFOB2.js +0 -64
  80. package/dist/cr3-wasm-X6Q4YMUU.js +0 -3
  81. package/dist/dng-wasm-EAB24KDN.js +0 -3
  82. package/dist/dpx-wasm-OX2D24ZB.js +0 -3
  83. package/dist/exr-wasm-Z6BBPJSN.js +0 -3
  84. package/dist/isobmff-XL33CVJR.js +0 -3
  85. package/dist/media_core-VSTO6CS4.js +0 -9
  86. package/dist/mxf-VIANACTI.js +0 -3
  87. package/dist/r3d-2QCFX7UX.js +0 -3
  88. package/dist/sscd-sweep-IXM4OD7O.js +0 -3
  89. package/dist/tiff-wasm-XYTQNL2F.js +0 -3
  90. package/dist/zod-IPSV75LP.js +0 -3
  91. /package/dist/{arriraw-Y5VXHXNX.js → arriraw-3GKCR6K2.js} +0 -0
  92. /package/dist/{chunk-NYB4ISL3.js → chunk-WHY3DVXS.js} +0 -0
  93. /package/dist/{media_core_bg-BKXQLNFA.js → media_core_bg-YK63OUDM.js} +0 -0
  94. /package/dist/{prores-TQEZ3KFH.js → prores-L4JZZWGH.js} +0 -0
  95. /package/dist/{timeline_core_bg-QEOVAIWP.js → timeline_core_bg-2TYWZ35G.js} +0 -0
  96. /package/dist/{udf_bg-UTQ6BVXX.js → udf_bg-A4WEMSAX.js} +0 -0
@@ -0,0 +1,551 @@
1
+ #!/usr/bin/env python3
2
+ """The engine's door into a running DaVinci Resolve (mcp/hosts/resolve/adapter.ts).
3
+
4
+ python3 bridge.py <action> '<json args>' -> one JSON line on stdout
5
+
6
+ Resolve's scripting API exists only for Python and Lua, so this file is the one place the engine
7
+ speaks it. It is glue, not know-how: every decision (what to import, what to render, what the
8
+ findings mean) is made in TypeScript; this file performs one host action and reports exactly what
9
+ Resolve said. One process per action: connecting costs ~0.1 s, and a crashed call can never wedge
10
+ the next one.
11
+
12
+ Safety, kept by every action (see mcp/hosts/contract.ts):
13
+ - read-only unless the action's name says otherwise
14
+ - the user's project, page and Deliver settings are restored after we touch them
15
+ - only our render job is ever started (StartRendering([job])), never the user's queue
16
+ Python 3.6+ (what Resolve supports); standard library only.
17
+ """
18
+ import json
19
+ import os
20
+ import sys
21
+ import time
22
+
23
+ OK = 0
24
+ FAIL = 1
25
+
26
+
27
+ def reply(obj, code=OK):
28
+ sys.stdout.write(json.dumps(obj) + "\n")
29
+ sys.stdout.flush()
30
+ sys.exit(code)
31
+
32
+
33
+ def fail(why, detail="", **extra):
34
+ out = {"ok": False, "why": why, "detail": detail}
35
+ out.update(extra)
36
+ reply(out, FAIL)
37
+
38
+
39
+ # ── connection ────────────────────────────────────────────────────────────
40
+
41
+ def connect():
42
+ """The Resolve object, or a reply naming exactly what is missing."""
43
+ try:
44
+ import DaVinciResolveScript as dvr # noqa: N813 (Resolve's own module name)
45
+ except Exception as e: # module not installed / paths not set
46
+ fail("module", "the Resolve scripting module could not be imported: %s" % e)
47
+ resolve = dvr.scriptapp("Resolve")
48
+ if not resolve:
49
+ fail(
50
+ "no_connection",
51
+ "Resolve is not running, or refused the connection. Start Resolve, and set "
52
+ "Preferences > System > General > External scripting using: Local (Studio only).",
53
+ )
54
+ return resolve
55
+
56
+
57
+ def project_or_fail(resolve):
58
+ pm = resolve.GetProjectManager()
59
+ p = pm.GetCurrentProject()
60
+ if not p:
61
+ fail("no_project", "no project is open in Resolve (only the Project Manager)")
62
+ return pm, p
63
+
64
+
65
+ def timelines(project):
66
+ return [project.GetTimelineByIndex(i + 1) for i in range(int(project.GetTimelineCount() or 0))]
67
+
68
+
69
+ def find_timeline(project, name):
70
+ if not name:
71
+ t = project.GetCurrentTimeline()
72
+ if not t:
73
+ fail("no_timeline", "the project %r has no timeline open" % project.GetName())
74
+ return t
75
+ for t in timelines(project):
76
+ if t.GetName() == name:
77
+ return t
78
+ fail("not_found", "no timeline named %r in project %r" % (name, project.GetName()),
79
+ timelines=[t.GetName() for t in timelines(project)])
80
+
81
+
82
+ # ── actions ───────────────────────────────────────────────────────────────
83
+
84
+ def a_version(resolve, _args):
85
+ """Product, version and what the API offers on this install."""
86
+ pm = resolve.GetProjectManager()
87
+ p = pm.GetCurrentProject()
88
+ return {
89
+ "ok": True,
90
+ "product": resolve.GetProductName(),
91
+ "version": resolve.GetVersionString(),
92
+ "project": p.GetName() if p else None,
93
+ "page": resolve.GetCurrentPage(),
94
+ "db": pm.GetCurrentDatabase() or {},
95
+ }
96
+
97
+
98
+ def a_current(resolve, _args):
99
+ """What is open: project, its timelines, the timeline in the viewer, the database."""
100
+ pm, p = project_or_fail(resolve)
101
+ t = p.GetCurrentTimeline()
102
+ return {
103
+ "ok": True,
104
+ "product": resolve.GetProductName(),
105
+ "version": resolve.GetVersionString(),
106
+ "project": p.GetName(),
107
+ "timelines": [x.GetName() for x in timelines(p)],
108
+ "timeline": t.GetName() if t else None,
109
+ "page": resolve.GetCurrentPage(),
110
+ "db": pm.GetCurrentDatabase() or {},
111
+ }
112
+
113
+
114
+ def a_export(resolve, args):
115
+ """A timeline → Resolve's own .drt (read-only on the project). Export does not switch timelines."""
116
+ _pm, p = project_or_fail(resolve)
117
+ t = find_timeline(p, args.get("timeline"))
118
+ out = args["out_path"]
119
+ if os.path.exists(out):
120
+ os.remove(out)
121
+ ok = bool(t.Export(out, resolve.EXPORT_DRT))
122
+ # Export returns True for some failures and writes a bundle for others: trust the file.
123
+ if not os.path.isfile(out) or os.path.getsize(out) == 0:
124
+ fail("export_failed", "Resolve did not write %s (Export returned %s)" % (out, ok))
125
+ return {"ok": True, "path": out, "format": "drt", "project": p.GetName(), "timeline": t.GetName()}
126
+
127
+
128
+ OUR_FOLDER = "conform.tools"
129
+
130
+
131
+ def unique_name(project, wanted):
132
+ taken = set(t.GetName() for t in timelines(project))
133
+ if wanted not in taken:
134
+ return wanted
135
+ n = 2
136
+ while "%s (%d)" % (wanted, n) in taken:
137
+ n += 1
138
+ return "%s (%d)" % (wanted, n)
139
+
140
+
141
+ def our_folder(media_pool):
142
+ """The media pool folder our imports land in, created under the root if missing."""
143
+ root = media_pool.GetRootFolder()
144
+ for f in root.GetSubFolderList() or []:
145
+ if f.GetName() == OUR_FOLDER:
146
+ return f
147
+ return media_pool.AddSubFolder(root, OUR_FOLDER)
148
+
149
+
150
+ def a_open(resolve, args):
151
+ """A timeline file -> a NEW timeline in the open project (never overwrites), inside the
152
+ conform.tools media pool folder. The user's timeline, folder and page are restored unless
153
+ `stay`. `into: scratch` switches to (or creates) our scratch project instead, saving the
154
+ user's project first so nothing of theirs is lost, and switches back afterwards."""
155
+ pm, p = project_or_fail(resolve)
156
+ path = args["path"]
157
+ if not os.path.isfile(path):
158
+ fail("not_found", "no file at %s" % path)
159
+ page = resolve.GetCurrentPage()
160
+ prev_project = p.GetName()
161
+ if args.get("into") == "scratch":
162
+ scratch = args.get("scratch_project") or "conform.tools scratch"
163
+ if prev_project != scratch:
164
+ pm.SaveProject()
165
+ if not pm.LoadProject(scratch):
166
+ if not pm.CreateProject(scratch):
167
+ fail("scratch_failed", "could not open or create the project %r" % scratch)
168
+ p = pm.GetCurrentProject()
169
+ prev_tl = p.GetCurrentTimeline()
170
+ mp = p.GetMediaPool()
171
+ prev_folder = mp.GetCurrentFolder()
172
+ folder = our_folder(mp)
173
+ if folder:
174
+ mp.SetCurrentFolder(folder)
175
+ name = unique_name(p, args.get("name") or os.path.splitext(os.path.basename(path))[0])
176
+ opts = {"timelineName": name, "importSourceClips": True}
177
+ if args.get("media_dir"):
178
+ opts["sourceClipsPath"] = args["media_dir"]
179
+ tl = mp.ImportTimelineFromFile(path, opts)
180
+ if not tl:
181
+ tl = mp.ImportTimelineFromFile(path, {"timelineName": name, "importSourceClips": False})
182
+ notes = []
183
+ if tl and tl.GetName() != name: # Resolve may name it after the file
184
+ tl.SetName(name)
185
+ got = tl.GetName() if tl else None
186
+ restored = False
187
+ if not args.get("stay"):
188
+ if prev_folder:
189
+ mp.SetCurrentFolder(prev_folder)
190
+ if prev_tl:
191
+ p.SetCurrentTimeline(prev_tl)
192
+ if args.get("into") == "scratch" and prev_project != p.GetName():
193
+ pm.SaveProject()
194
+ pm.LoadProject(prev_project)
195
+ if resolve.GetCurrentPage() != page:
196
+ resolve.OpenPage(page)
197
+ restored = True
198
+ if not tl:
199
+ fail("import_failed", "Resolve refused to import %s" % path, restored=restored)
200
+ if not opts.get("sourceClipsPath") and args.get("media_dir"):
201
+ notes.append("media_dir was not used")
202
+ return {"ok": True, "project": p.GetName(), "timeline": got, "folder": OUR_FOLDER if folder else None,
203
+ "restored": restored, "notes": notes}
204
+
205
+
206
+ # ── render ────────────────────────────────────────────────────────────────
207
+ #
208
+ # Stateless across calls: render_start returns what to restore, the engine keeps it in its job
209
+ # record and hands it back to render_finish. Settings are restored right after AddRenderJob (a
210
+ # queued job keeps the settings it was added with), so the user's Deliver page is theirs again
211
+ # while our job renders; their timeline and page come back in render_finish.
212
+
213
+ KEEP_PREFIX = "__ct_keep_"
214
+
215
+
216
+ def find_job(project, job_id):
217
+ for j in project.GetRenderJobList() or []:
218
+ if j.get("JobId") == job_id:
219
+ return j
220
+ return None
221
+
222
+
223
+ def a_render_start(resolve, args):
224
+ _pm, p = project_or_fail(resolve)
225
+ if p.IsRenderingInProgress():
226
+ fail("busy", "Resolve is already rendering; we never interrupt someone else's render")
227
+ target = args["target_dir"]
228
+ if not os.path.isdir(target):
229
+ os.makedirs(target)
230
+ page = resolve.GetCurrentPage()
231
+ if args.get("renderplugin") is not None or args.get("preset"):
232
+ _deliver_ready(resolve, p)
233
+ prev_tl = p.GetCurrentTimeline()
234
+ tl = find_timeline(p, args.get("timeline"))
235
+ if not prev_tl or prev_tl.GetName() != tl.GetName():
236
+ p.SetCurrentTimeline(tl)
237
+ keep = "%s%d_%d" % (KEEP_PREFIX, os.getpid(), int(time.time() * 1000))
238
+ kept = bool(p.SaveAsNewRenderPreset(keep))
239
+ if args.get("renderplugin") is not None:
240
+ args["preset"] = QC_PRESET
241
+ for f in QC_REPORTS: # a stale report from an earlier run is the classic wrong answer
242
+ if os.path.exists(os.path.join(target, f)):
243
+ os.remove(os.path.join(target, f))
244
+ _write_qc_config(target, args["renderplugin"])
245
+ try:
246
+ if args.get("preset"):
247
+ if args["preset"] not in (p.GetRenderPresetList() or []):
248
+ fail("no_preset", "no render preset named %r" % args["preset"], presets=p.GetRenderPresetList() or [])
249
+ p.LoadRenderPreset(args["preset"])
250
+ settings = {"TargetDir": target, "CustomName": args.get("name") or tl.GetName(),
251
+ "ExportVideo": True, "ExportAudio": bool(args.get("audio"))}
252
+ rng = args.get("range")
253
+ if rng:
254
+ settings.update({"SelectAllFrames": False, "MarkIn": int(rng["in"]), "MarkOut": int(rng["out"])})
255
+ else:
256
+ settings["SelectAllFrames"] = True
257
+ p.SetRenderSettings(settings) # may return False and still apply: never fatal
258
+ job = p.AddRenderJob()
259
+ if not job:
260
+ fail("render_refused", "Resolve did not queue the job (check the format/codec and target folder)")
261
+ finally:
262
+ if kept:
263
+ p.LoadRenderPreset(keep)
264
+ p.DeleteRenderPreset(keep)
265
+ if not p.StartRendering([job]):
266
+ p.DeleteRenderJob(job)
267
+ fail("render_refused", "Resolve would not start the job")
268
+ return {"ok": True, "job_id": job, "timeline": tl.GetName(), "project": p.GetName(),
269
+ "settings_restored": kept,
270
+ "restore": {"timeline": prev_tl.GetName() if prev_tl else None, "page": page}}
271
+
272
+
273
+ def a_render_status(resolve, args):
274
+ _pm, p = project_or_fail(resolve)
275
+ st = p.GetRenderJobStatus(args["job_id"]) or {}
276
+ status = st.get("JobStatus", "")
277
+ rendering = bool(p.IsRenderingInProgress())
278
+ if status in ("Complete", "Completed"):
279
+ state = "complete"
280
+ elif status in ("Failed",):
281
+ state = "failed"
282
+ elif status in ("Cancelled",):
283
+ state = "cancelled"
284
+ elif not rendering and status not in ("", "Rendering", "Queued", "Ready"):
285
+ state = "complete"
286
+ elif not find_job(p, args["job_id"]):
287
+ state = "failed"
288
+ st["Error"] = st.get("Error") or "the job is no longer in Resolve's render queue"
289
+ else:
290
+ state = "rendering" if rendering else "queued"
291
+ return {"ok": True, "job_id": args["job_id"], "state": state, "status": status,
292
+ "percent": int(st.get("CompletionPercentage") or 0), "error": st.get("Error")}
293
+
294
+
295
+ def a_render_cancel(resolve, args):
296
+ _pm, p = project_or_fail(resolve)
297
+ if p.IsRenderingInProgress():
298
+ st = p.GetRenderJobStatus(args["job_id"]) or {}
299
+ if st.get("JobStatus") == "Rendering":
300
+ p.StopRendering()
301
+ return a_render_finish(resolve, args, state="cancelled")
302
+
303
+
304
+ def a_render_finish(resolve, args, state=None):
305
+ """Remove our job from the queue and give the user back their timeline and page."""
306
+ _pm, p = project_or_fail(resolve)
307
+ job = find_job(p, args["job_id"])
308
+ out = {"ok": True, "job_id": args["job_id"], "state": state or "complete"}
309
+ if job:
310
+ out["output"] = os.path.join(job.get("TargetDir", ""), job.get("OutputFilename", ""))
311
+ p.DeleteRenderJob(args["job_id"])
312
+ r = args.get("restore") or {}
313
+ if r.get("timeline"):
314
+ for t in timelines(p):
315
+ if t.GetName() == r["timeline"]:
316
+ p.SetCurrentTimeline(t)
317
+ break
318
+ if r.get("page") and resolve.GetCurrentPage() != r["page"]:
319
+ resolve.OpenPage(r["page"])
320
+ return out
321
+
322
+
323
+ # ── the renderplugin (conform.tools render plugin) ───────────────────────────────────────
324
+ #
325
+ # Resolve's scripting API cannot select a plugin codec (GetRenderFormats omits it), but a saved
326
+ # render preset can: it stores "<pluginUUID>:<codecUUID>". We ship that preset
327
+ # (presets/conform.tools.xml) and import it with Resolve.ImportRenderPreset, which names the preset
328
+ # after the FILE and also SELECTS it, so the user's Deliver settings are snapshotted around it.
329
+ # Presets live per Resolve database: ensure on every QC run.
330
+
331
+ # Resolve names an imported preset after its FILE (presets/conform.tools.xml) and may cut the name at
332
+ # the first dot ("conform"); a cut name is renamed back below. Earlier names of ours are renamed to it.
333
+ QC_PRESET = "conform.tools"
334
+ LEGACY_PRESETS = ("CONFORM.TOOLS", "CONFORM.TOOLS QC", "Conform Tools QC")
335
+ QC_REPORTS = ("qc_report.json", "qc_audio.json", "qc_filmstrip.jpg")
336
+
337
+
338
+ def _codec_id(xml_text):
339
+ import re
340
+ m = re.search(r"<RecordFormatSubType>([^<]+)</RecordFormatSubType>", xml_text or "")
341
+ return m.group(1).strip().upper() if m else ""
342
+
343
+
344
+ def _saved_codec_id(resolve, name):
345
+ """The codec a saved preset really selects (export it and read it); None when unknowable."""
346
+ import glob
347
+ import shutil
348
+ import tempfile
349
+ exporter = getattr(resolve, "ExportRenderPreset", None)
350
+ if exporter is None:
351
+ return None
352
+ d = tempfile.mkdtemp(prefix="ct_preset_")
353
+ try:
354
+ exporter(name, d) # the 2nd argument is a DIRECTORY; returns True regardless: trust the file
355
+ for f in glob.glob(os.path.join(d, "*.xml")):
356
+ with open(f) as fh:
357
+ return _codec_id(fh.read()) or None
358
+ return None
359
+ except Exception:
360
+ return None
361
+ finally:
362
+ shutil.rmtree(d, ignore_errors=True)
363
+
364
+
365
+ def _keeping_settings(project, fn):
366
+ """Run fn() and put the user's Deliver settings back (import and load both SELECT a preset)."""
367
+ keep = "%s%d_%d" % (KEEP_PREFIX, os.getpid(), int(time.time() * 1000))
368
+ kept = bool(project.SaveAsNewRenderPreset(keep))
369
+ try:
370
+ return fn()
371
+ finally:
372
+ if kept:
373
+ project.LoadRenderPreset(keep)
374
+ project.DeleteRenderPreset(keep)
375
+
376
+
377
+ def _rename_preset(project, src, dst):
378
+ project.LoadRenderPreset(src)
379
+ if not project.SaveAsNewRenderPreset(dst):
380
+ return False
381
+ project.DeleteRenderPreset(src)
382
+ return True
383
+
384
+
385
+ def _deliver_ready(resolve, project):
386
+ """Open the Deliver page and give its panel a moment before touching render presets, and sweep
387
+ snapshot presets an interrupted earlier run left behind (ours only: the __ct_keep_ prefix).
388
+ Measured 2026-10-01 on Resolve Studio 20.3.2: a first renderplugin run on a project whose Deliver
389
+ page had never been opened aborted Resolve inside its Deliver panel (assertion
390
+ GetUseProjectTimelineFilter in UiDeliverPanelTimelineController); the same calls on a project
391
+ whose Deliver page had been opened ran clean. This is the precaution; the exact trigger is not
392
+ proven. Returns the page to restore."""
393
+ page = resolve.GetCurrentPage()
394
+ if page != "deliver":
395
+ resolve.OpenPage("deliver")
396
+ time.sleep(1.0)
397
+ for name in project.GetRenderPresetList() or []:
398
+ if name.startswith(KEEP_PREFIX):
399
+ project.DeleteRenderPreset(name)
400
+ return page
401
+
402
+
403
+ def a_renderplugin_preset(resolve, args):
404
+ """Make sure the conform.tools render preset exists and selects OUR codec. Never deletes a preset
405
+ the user named; replaces ours when it is stale; renames a legacy name of ours. The user's page and
406
+ Deliver settings are put back."""
407
+ _pm, p = project_or_fail(resolve)
408
+ with open(args["preset_path"]) as fh:
409
+ expected = _codec_id(fh.read())
410
+ page = _deliver_ready(resolve, p)
411
+ try:
412
+ presets = p.GetRenderPresetList() or []
413
+ if QC_PRESET in presets:
414
+ got = _saved_codec_id(resolve, QC_PRESET)
415
+ if got is None or got == expected:
416
+ return {"ok": True, "preset": QC_PRESET, "imported": False}
417
+ _keeping_settings(p, lambda: p.DeleteRenderPreset(QC_PRESET))
418
+ replaced = True
419
+ else:
420
+ replaced = False
421
+ for legacy in LEGACY_PRESETS:
422
+ if legacy in presets:
423
+ got = _saved_codec_id(resolve, legacy)
424
+ if got is None or got == expected:
425
+ if _keeping_settings(p, lambda: _rename_preset(p, legacy, QC_PRESET)):
426
+ return {"ok": True, "preset": QC_PRESET, "imported": False, "renamed_from": legacy}
427
+ importer = getattr(resolve, "ImportRenderPreset", None)
428
+ if importer is None:
429
+ fail("no_preset_import", "this Resolve cannot import render presets (Resolve 19 or later can)")
430
+ before = set(p.GetRenderPresetList() or [])
431
+ _keeping_settings(p, lambda: importer(os.path.abspath(args["preset_path"])))
432
+ after = p.GetRenderPresetList() or []
433
+ if QC_PRESET not in after:
434
+ new = [x for x in after if x not in before]
435
+ if len(new) == 1: # Resolve may cut the name at the first dot
436
+ _keeping_settings(p, lambda: _rename_preset(p, new[0], QC_PRESET))
437
+ if QC_PRESET not in (p.GetRenderPresetList() or []):
438
+ fail("preset_import_failed", "Resolve did not import the conform.tools render preset")
439
+ return {"ok": True, "preset": QC_PRESET, "imported": True, "replaced": replaced}
440
+ finally:
441
+ if resolve.GetCurrentPage() != page:
442
+ resolve.OpenPage(page)
443
+
444
+
445
+ def _write_qc_config(folder, config):
446
+ """<render folder>/qc_config.txt, flat key=value lines the codec reads at its first frame. No config:
447
+ remove any stale one so the codec runs every check."""
448
+ path = os.path.join(folder, "qc_config.txt")
449
+ if not config:
450
+ if os.path.exists(path):
451
+ os.remove(path)
452
+ return
453
+ lines = ["color_space=%s" % (config.get("color_space") or "sdr_rec709")]
454
+ if config.get("id"):
455
+ lines.append("template_id=%s" % config["id"])
456
+ for check, params in (config.get("checks") or {}).items():
457
+ params = params or {}
458
+ lines.append("%s.enabled=%d" % (check, 1 if params.get("enabled", True) else 0))
459
+ for k, v in params.items():
460
+ if k != "enabled":
461
+ lines.append("%s.%s=%s" % (check, k, int(v) if isinstance(v, bool) else v))
462
+ with open(path, "w") as fh:
463
+ fh.write("\n".join(lines) + "\n")
464
+
465
+
466
+ def a_clips(resolve, args):
467
+ """The video items of a timeline (absolute frames, end exclusive) + its start frame and raster:
468
+ what maps a measured frame to the clip that composites it."""
469
+ _pm, p = project_or_fail(resolve)
470
+ t = find_timeline(p, args.get("timeline"))
471
+ out = []
472
+ for track in range(1, int(t.GetTrackCount("video") or 0) + 1):
473
+ for i, it in enumerate(t.GetItemListInTrack("video", track) or []):
474
+ out.append({"id": "%d:%d" % (track, i), "name": it.GetName(), "start": int(it.GetStart()),
475
+ "end": int(it.GetEnd()), "track": track})
476
+ return {"ok": True, "timeline": t.GetName(), "start_frame": int(t.GetStartFrame()),
477
+ "end_frame": int(t.GetEndFrame()),
478
+ "width": int(float(t.GetSetting("timelineResolutionWidth") or 0)),
479
+ "height": int(float(t.GetSetting("timelineResolutionHeight") or 0)),
480
+ "fps": t.GetSetting("timelineFrameRate"), "clips": out}
481
+
482
+
483
+ def a_markers(resolve, args):
484
+ """Place or clear OUR markers on a timeline. Ours carry customData starting with the tag; a marker
485
+ someone else placed is never edited or deleted, and a frame they occupy is skipped and reported."""
486
+ _pm, p = project_or_fail(resolve)
487
+ t = find_timeline(p, args.get("timeline"))
488
+ prefix = args["tag"]
489
+
490
+ def ours_by_frame():
491
+ return dict((int(f), m) for f, m in (t.GetMarkers() or {}).items()
492
+ if str(m.get("customData") or "").startswith(prefix))
493
+
494
+ cleared = 0
495
+ if args.get("clear"):
496
+ for f in ours_by_frame():
497
+ if t.DeleteMarkerAtFrame(f):
498
+ cleared += 1
499
+ placed, skipped = 0, []
500
+ for m in args.get("place") or []:
501
+ f = int(m["frame"]) # relative to the timeline start, as Resolve counts markers
502
+ everyone = t.GetMarkers() or {}
503
+ if f in ours_by_frame():
504
+ t.DeleteMarkerAtFrame(f) # re-running replaces our own marker, never stacks a second
505
+ elif f in everyone or float(f) in everyone:
506
+ skipped.append(f) # someone else's: leave it
507
+ continue
508
+ if t.AddMarker(f, m.get("color", "Red"), m.get("name", "conform.tools"), m.get("note", ""),
509
+ max(1, int(m.get("duration", 1))), m.get("tag", prefix)):
510
+ placed += 1
511
+ else:
512
+ skipped.append(f)
513
+ return {"ok": True, "timeline": t.GetName(), "placed": placed, "cleared": cleared, "skipped": skipped}
514
+
515
+
516
+ ACTIONS = {
517
+ "version": a_version,
518
+ "current": a_current,
519
+ "export": a_export,
520
+ "open": a_open,
521
+ "render_start": a_render_start,
522
+ "render_status": a_render_status,
523
+ "render_cancel": a_render_cancel,
524
+ "render_finish": a_render_finish,
525
+ "renderplugin_preset": a_renderplugin_preset,
526
+ "clips": a_clips,
527
+ "markers": a_markers,
528
+ }
529
+
530
+
531
+ def main():
532
+ if len(sys.argv) < 2 or sys.argv[1] not in ACTIONS:
533
+ fail("usage", "bridge.py <%s> '<json>'" % "|".join(sorted(ACTIONS)))
534
+ try:
535
+ args = json.loads(sys.argv[2]) if len(sys.argv) > 2 else {}
536
+ except ValueError as e:
537
+ fail("usage", "arguments are not JSON: %s" % e)
538
+ resolve = connect()
539
+ t0 = time.time()
540
+ try:
541
+ out = ACTIONS[sys.argv[1]](resolve, args)
542
+ except SystemExit:
543
+ raise
544
+ except Exception as e: # report Resolve's own failure verbatim; never a traceback on stdout
545
+ fail("resolve_error", "%s: %s" % (type(e).__name__, e))
546
+ out["ms"] = int((time.time() - t0) * 1000)
547
+ reply(out)
548
+
549
+
550
+ if __name__ == "__main__":
551
+ main()
@@ -0,0 +1,127 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--DbAppVer="20.3.3.0010" DbPrjVer="15"-->
3
+ <SyRecordInfo DbId="a977254f-7ada-4fc7-8a13-e57ad89dd3c2">
4
+ <FieldsBlob>00000001000000090000002a00550073006500540069006d0065006c0069006e0065005200650073006f006c007500740069006f006e0000000100010000002800550073006500540069006d0065006c0069006e0065004600720061006d0065005200610074006500000001000100000026005300750062007400690074006c0065005200650063006f007200640043006f00640065006300000002006d73633100000028005300750062007400690074006c0065004500780070006f007200740046006f0072006d006100740000000200000000030000002200520065006e0064006500720041007500640069006f0054007200610063006b00730000000c000000006f00000001000000010000000200300000000c000000005800000001000000020000001c0054007200610063006b0049006e0066006f00560061006c007500650000000200000000010000001a0054007200610063006b0049006e0066006f00540079007000650000000200000000010000002a005200650063006f007200640041007500640069006f00530061006d0070006c0065005200610074006500000002000000bb800000005e005200650063006f007200640041007500640069006f004e006f0072006d0061006c0069007a006100740069006f006e004f007500740070007500740054007200610063006b00730045006e00610062006c0065005300740061007400650000000c000000001700000001000000010000000200300000000200000000010000002800490073005200650063006f007200640041006c007000680061005000720065006d0075006c0074000000010001000000240043007500730074006f006d00500072006500730065007400490063006f006e00490064000000020000000001</FieldsBlob>
5
+ <Session/>
6
+ <Timeline/>
7
+ <UniqueSequenceId/>
8
+ <ReplaceHoleWithBlank>0</ReplaceHoleWithBlank>
9
+ <ApplyWfmDuringRecord>0</ApplyWfmDuringRecord>
10
+ <DisableCcDuringRecording>0</DisableCcDuringRecording>
11
+ <DisablePtzDuringRecording>0</DisablePtzDuringRecording>
12
+ <RecordStartFrame>0</RecordStartFrame>
13
+ <RecordEndFrame>0</RecordEndFrame>
14
+ <RecordTotalFrame>0</RecordTotalFrame>
15
+ <RecordOldFrame>0</RecordOldFrame>
16
+ <RecordNewFrame>86400</RecordNewFrame>
17
+ <RecordAllowDupImg>1</RecordAllowDupImg>
18
+ <RecordClipUniqueName>false</RecordClipUniqueName>
19
+ <RecordClipUniqueNameStyle>0</RecordClipUniqueNameStyle>
20
+ <RecordDigit>8</RecordDigit>
21
+ <RecordBitDepth>16</RecordBitDepth>
22
+ <RecordAsFloat>false</RecordAsFloat>
23
+ <FormatWidth>1920</FormatWidth>
24
+ <FormatHeight>1080</FormatHeight>
25
+ <FormatPixelAspectRatio>1</FormatPixelAspectRatio>
26
+ <FormatOption>-1</FormatOption>
27
+ <RecordTargetDir></RecordTargetDir>
28
+ <RecordUseTgtTimeCode>1</RecordUseTgtTimeCode>
29
+ <RenderAtSourceResolution>false</RenderAtSourceResolution>
30
+ <RecordSetTimelineTimecode>false</RecordSetTimelineTimecode>
31
+ <UseRecordClipStartFrame>true</UseRecordClipStartFrame>
32
+ <RecordClipStartFrame>1001</RecordClipStartFrame>
33
+ <RecordPrefix>conform_qc</RecordPrefix>
34
+ <RecordSuffix/>
35
+ <RecordFormatType>7145B29C33684D8AA1C7E5126F9B405D:C04F07127A5D4E18B93684A15D2F7166</RecordFormatType>
36
+ <RecordFormatSubType>7145B29C33684D8AA1C7E5126F9B405D:9E4FA32B8C714D55A63DE8124F9B6C07</RecordFormatSubType>
37
+ <RecordInFieldMode>false</RecordInFieldMode>
38
+ <RecordDataLevel>DATA_LEVEL_AUTO</RecordDataLevel>
39
+ <RecordQuality>4</RecordQuality>
40
+ <RecordFPS>23.976</RecordFPS>
41
+ <StereoRender>false</StereoRender>
42
+ <StereoRenderFrameMeshMode>-1</StereoRenderFrameMeshMode>
43
+ <StereoRenderBothEyesSeparately>false</StereoRenderBothEyesSeparately>
44
+ <StereoRenderSourceType>0</StereoRenderSourceType>
45
+ <UserName/>
46
+ <ProjectName/>
47
+ <FolderName/>
48
+ <SessionName/>
49
+ <CreationTime/>
50
+ <Status>READY</Status>
51
+ <RecordSpeed>0</RecordSpeed>
52
+ <UsePrefixAndSuffixFromSrc>0</UsePrefixAndSuffixFromSrc>
53
+ <UseCommercialWorkflow>0</UseCommercialWorkflow>
54
+ <AlternateOffset>0</AlternateOffset>
55
+ <ReelInFolder>0</ReelInFolder>
56
+ <ClipInFolder>0</ClipInFolder>
57
+ <AlternateInFolder>1</AlternateInFolder>
58
+ <SrcDirPreserveLevel>0</SrcDirPreserveLevel>
59
+ <SrcDirLevelsMode>0</SrcDirLevelsMode>
60
+ <NumFramesOfHandles>0</NumFramesOfHandles>
61
+ <UseVersionNameForFolder>0</UseVersionNameForFolder>
62
+ <DestSuffix/>
63
+ <RecordInfoName/>
64
+ <VersionIdList/>
65
+ <VersionNameList/>
66
+ <CompletionPercentage>0</CompletionPercentage>
67
+ <RecordSlatePreset>None</RecordSlatePreset>
68
+ <AdditionalOutputFormats/>
69
+ <RecordAudioEnabled>true</RecordAudioEnabled>
70
+ <RecordAudioNumChannels>2</RecordAudioNumChannels>
71
+ <RecordAudioBitDepth>24</RecordAudioBitDepth>
72
+ <CustomClips>0000000000000000</CustomClips>
73
+ <DisplayOrder>-1</DisplayOrder>
74
+ <ForceHighestQualitySizing>1</ForceHighestQualitySizing>
75
+ <ForceHighestQualityDebayerRes>1</ForceHighestQualityDebayerRes>
76
+ <RecordMode>RECORD_MODE_NONE</RecordMode>
77
+ <ExtraInfoMap>
78
+ <Element>
79
+ <DbKey>smpte</DbKey>
80
+ <DbVal>y</DbVal>
81
+ </Element>
82
+ <Element>
83
+ <DbKey>aud_codec</DbKey>
84
+ <DbVal>lpcm</DbVal>
85
+ </Element>
86
+ <Element>
87
+ <DbKey>subs_enable</DbKey>
88
+ <DbVal>0</DbVal>
89
+ </Element>
90
+ <Element>
91
+ <DbKey>aud_discrete</DbKey>
92
+ <DbVal>0</DbVal>
93
+ </Element>
94
+ <Element>
95
+ <DbKey>tag_sm_gamma</DbKey>
96
+ <DbVal>13</DbVal>
97
+ </Element>
98
+ <Element>
99
+ <DbKey>aud_src_config</DbKey>
100
+ <DbVal>AUX0</DbVal>
101
+ </Element>
102
+ <Element>
103
+ <DbKey>imf_profile_level</DbKey>
104
+ <DbVal>0</DbVal>
105
+ </Element>
106
+ <Element>
107
+ <DbKey>tag_sm_colorspace</DbKey>
108
+ <DbVal>23</DbVal>
109
+ </Element>
110
+ <Element>
111
+ <DbKey>plugin_vcodec_config</DbKey>
112
+ <DbVal>CgAAAHFjX2VuYWJsZWQCAAAAAQAAAAE=</DbVal>
113
+ </Element>
114
+ <Element>
115
+ <DbKey>include_spatial_metadata</DbKey>
116
+ <DbVal>0</DbVal>
117
+ </Element>
118
+ </ExtraInfoMap>
119
+ <UseRenderCachedImagesForRecording>false</UseRenderCachedImagesForRecording>
120
+ <TgtSysId>None</TgtSysId>
121
+ <CurSysId/>
122
+ <TimeTakenToRenderInMs>0</TimeTakenToRenderInMs>
123
+ <EstimatedTimeRemainingInMs>0</EstimatedTimeRemainingInMs>
124
+ <ErrorCode>0</ErrorCode>
125
+ <ErrorStr/>
126
+ <ErrorNotified>true</ErrorNotified>
127
+ </SyRecordInfo>