davinci-resolve-mcp 5.3.1 → 5.3.3

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/CHANGELOG.md CHANGED
@@ -2,6 +2,41 @@
2
2
 
3
3
  Release history for the DaVinci Resolve MCP Server. The latest release is summarized in the root README; older entries live here to keep the README focused.
4
4
 
5
+ ## What's New in v5.3.3 — DRP timeline start frame and timecode agree
6
+
7
+ From #384.
8
+
9
+ ### Fixed
10
+
11
+ When the DRP/DRT writer builds a timeline, it writes the start twice: as `<StartFrame>` and as the `<StartTC>` label. The two could disagree, or both be wrong.
12
+
13
+ - **An explicit `startFrame` left `<StartTC>` stale.** `startFrame: 90000` at 24 fps was written next to `StartTC 01:00:00:00`, but 90000 is `01:02:30:00`. The label now matches the frame, in the caller's counting mode.
14
+ - **Drop-frame was applied at every frame rate.** `01:00:00;00` at 24 fps counted to frame 86292. Drop-frame now applies only at 29.97 and 59.94 (SMPTE 12M).
15
+ - **A label that didn't parse became frame 0**, and the bad label was still written out.
16
+ - **Out-of-range fields were counted as if they were valid.** For example, `01:00:00:30` at 29.97 was counted as `01:00:01:00`.
17
+
18
+ Valid start timecodes count exactly as before.
19
+
20
+ ### Changed
21
+
22
+ - **An invalid start timecode now throws a `RangeError`** instead of writing a wrong start. This covers malformed labels, out-of-range fields, `;` at a rate with no drop-frame, and labels that drop-frame counting skips.
23
+
24
+ ### Not verified here
25
+
26
+ - Offline tests only. Drop-frame labels were checked against a second, independent SMPTE 12M labeller over two hours at 29.97 and 59.94. No timeline was imported into Resolve for this release.
27
+
28
+ ## What's New in v5.3.2 — OFX choice and color parameters decode
29
+
30
+ From #383.
31
+
32
+ ### Added
33
+
34
+ - **`extractOFXTools` decodes OFX choice menus and RGB colors.** Before, both came back as `null`. A choice parameter now decodes to `{choice: index}`, and a color to `{rgb: [r, g, b], alpha?}`, from the bytes Resolve 19.1.3 writes in a node's OFX container. Index 0 is stored as an empty field, and a parameter left at its default isn't stored at all, so a missing parameter means "default". Only the raw index is returned; what it means depends on each plugin's own menu.
35
+
36
+ ### Not verified here
37
+
38
+ - Decoding was measured on stills exported from Resolve Studio 19.1.3. No other Resolve version was checked.
39
+
5
40
  ## What's New in v5.3.1 — prettier dev-dependency update
6
41
 
7
42
  From #375 (Dependabot).
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  English | [简体中文](README.zh-CN.md) | [繁體中文](README.zh-TW.md)
4
4
 
5
- [![Version](https://img.shields.io/badge/version-5.3.1-blue.svg)](https://github.com/samuelgursky/davinci-resolve-mcp/releases)
5
+ [![Version](https://img.shields.io/badge/version-5.3.3-blue.svg)](https://github.com/samuelgursky/davinci-resolve-mcp/releases)
6
6
  [![npm](https://img.shields.io/npm/v/davinci-resolve-mcp.svg?label=npm&color=CB3837)](https://www.npmjs.com/package/davinci-resolve-mcp)
7
7
  [![API Coverage](https://img.shields.io/badge/API%20Coverage-100%25-brightgreen.svg)](docs/reference/api-coverage.md)
8
8
  [![Tools](https://img.shields.io/badge/MCP%20Tools-37%20(390%20full)-blue.svg)](#server-modes)
package/README.zh-CN.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [English](README.md) | 简体中文 | [繁體中文](README.zh-TW.md)
4
4
 
5
- [![Version](https://img.shields.io/badge/version-5.3.1-blue.svg)](https://github.com/samuelgursky/davinci-resolve-mcp/releases)
5
+ [![Version](https://img.shields.io/badge/version-5.3.3-blue.svg)](https://github.com/samuelgursky/davinci-resolve-mcp/releases)
6
6
  [![npm](https://img.shields.io/npm/v/davinci-resolve-mcp.svg?label=npm&color=CB3837)](https://www.npmjs.com/package/davinci-resolve-mcp)
7
7
  [![API Coverage](https://img.shields.io/badge/API%20Coverage-100%25-brightgreen.svg)](docs/reference/api-coverage.md)
8
8
  [![Tools](https://img.shields.io/badge/MCP%20Tools-37%20(390%20full)-blue.svg)](#服务器模式)
@@ -12,7 +12,7 @@
12
12
  [![Python](https://img.shields.io/badge/python-3.10+-green.svg)](https://www.python.org/downloads/)
13
13
  [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
14
14
 
15
- > 本翻译对应 v5.3.1 版 README。如与英文原版有出入,以 [英文原版](README.md) 为准。
15
+ > 本翻译对应 v5.3.3 版 README。如与英文原版有出入,以 [英文原版](README.md) 为准。
16
16
 
17
17
  一个 Model Context Protocol (MCP) 服务器,让 AI 助手通过官方脚本 API 控制 DaVinci Resolve Studio(达芬奇)。它提供完整的 API 覆盖,外加带护栏的工作流助手,涵盖剪辑、媒体池整理、渲染设置、审阅标记、调色、Fusion、Fairlight、项目生命周期任务、扩展开发,以及不碰源媒体的媒体分析。
18
18
 
package/README.zh-TW.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [English](README.md) | [简体中文](README.zh-CN.md) | 繁體中文
4
4
 
5
- [![Version](https://img.shields.io/badge/version-5.3.1-blue.svg)](https://github.com/samuelgursky/davinci-resolve-mcp/releases)
5
+ [![Version](https://img.shields.io/badge/version-5.3.3-blue.svg)](https://github.com/samuelgursky/davinci-resolve-mcp/releases)
6
6
  [![npm](https://img.shields.io/npm/v/davinci-resolve-mcp.svg?label=npm&color=CB3837)](https://www.npmjs.com/package/davinci-resolve-mcp)
7
7
  [![API Coverage](https://img.shields.io/badge/API%20Coverage-100%25-brightgreen.svg)](docs/reference/api-coverage.md)
8
8
  [![Tools](https://img.shields.io/badge/MCP%20Tools-37%20(390%20full)-blue.svg)](#伺服器模式)
@@ -12,7 +12,7 @@
12
12
  [![Python](https://img.shields.io/badge/python-3.10+-green.svg)](https://www.python.org/downloads/)
13
13
  [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
14
14
 
15
- > 本翻譯對應 v5.3.1 版 README。如與英文原版有出入,以[英文原版](README.md)為準。
15
+ > 本翻譯對應 v5.3.3 版 README。如與英文原版有出入,以[英文原版](README.md)為準。
16
16
 
17
17
  一個 Model Context Protocol(MCP)伺服器,讓 AI 助理透過官方腳本 API 控制 DaVinci Resolve Studio。它提供完整的 API 覆蓋,並附上有防護機制的工作流程輔助工具,涵蓋剪輯、媒體池整理、算圖輸出設定、審閱標記、調色、Fusion、Fairlight、專案生命週期作業、擴充功能開發,以及不更動原始素材的媒體分析。
18
18
 
package/install.py CHANGED
@@ -37,7 +37,7 @@ from src.utils.update_check import (
37
37
 
38
38
  # ─── Version ──────────────────────────────────────────────────────────────────
39
39
 
40
- VERSION = "5.3.1"
40
+ VERSION = "5.3.3"
41
41
  # Only hard floor: mcp[cli] requires Python 3.10+. There is no upper bound —
42
42
  # Resolve's scripting bridge loads into newer interpreters on recent builds
43
43
  # (Python 3.14 verified against Resolve Studio 20.3.2). Older Resolve builds
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "davinci-resolve-mcp",
3
- "version": "5.3.1",
3
+ "version": "5.3.3",
4
4
  "description": "NPM bootstrapper for the DaVinci Resolve MCP Server.",
5
5
  "license": "MIT",
6
6
  "author": "Samuel Gursky <samgursky@gmail.com>",
@@ -0,0 +1,139 @@
1
+ // SeqContainer timeline start: <StartFrame> and <StartTC> must describe the
2
+ // same frame, and a start timecode the rate cannot count is refused instead of
3
+ // being turned into a wrong frame number.
4
+ //
5
+ // - An explicit startFrame wins (issue #168), but <StartTC> kept the caller's
6
+ // (or the default 01:00:00:00) label, so the file named two different
7
+ // starts. It is now the label of that frame.
8
+ // - ';' (drop-frame) at a rate without drop-frame (24, 25, 23.976, 30) had
9
+ // dropped numbers subtracted anyway: 01:00:00;00 at 24 -> 86292.
10
+ // - A malformed label became frame 0 and was still written as <StartTC>.
11
+ // - Fields past their range (ff >= the timebase, mm/ss > 59) and drop-frame
12
+ // labels that do not exist (00:01:00;00) were counted as if they did.
13
+ const { test } = require('node:test');
14
+ const assert = require('node:assert');
15
+ const {
16
+ buildSeqContainerFile,
17
+ timecodeToFrames,
18
+ framesToTimecode,
19
+ } = require('../seq-container-builder');
20
+
21
+ const NTSC30 = 30000 / 1001;
22
+ const NTSC60 = 60000 / 1001;
23
+ const NTSC24 = 24000 / 1001;
24
+ const tl = { name: 'T', videoTracks: [], audioTracks: [] };
25
+
26
+ function start(xml) {
27
+ return {
28
+ frame: Number(xml.match(/<StartFrame>([^<]*)<\/StartFrame>/)[1]),
29
+ tc: xml.match(/<StartTC>([^<]*)<\/StartTC>/)[1],
30
+ };
31
+ }
32
+
33
+ // Reference drop-frame labeller, written from SMPTE 12M independently of the
34
+ // module under test (whole 10-minute blocks, then the first undropped minute).
35
+ function refDropFrameLabel(frames, nominal) {
36
+ const drop = nominal / 15;
37
+ const perMin = nominal * 60 - drop;
38
+ const per10 = perMin * 10 + drop;
39
+ const blocks = Math.floor(frames / per10);
40
+ let rem = frames % per10;
41
+ let minutes = blocks * 10;
42
+ if (rem >= nominal * 60) {
43
+ rem -= nominal * 60;
44
+ minutes += 1 + Math.floor(rem / perMin);
45
+ rem = (rem % perMin) + drop;
46
+ }
47
+ const h = Math.floor(minutes / 60);
48
+ const m = minutes % 60;
49
+ const s = Math.floor(rem / nominal);
50
+ const f = rem % nominal;
51
+ const p = (n) => String(n).padStart(2, '0');
52
+ return `${p(h)}:${p(m)}:${p(s)};${p(f)}`;
53
+ }
54
+
55
+ test('NULL CONTROL: valid starts count exactly as before', async () => {
56
+ assert.strictEqual(timecodeToFrames('01:00:00:00', NTSC30), 108000);
57
+ assert.strictEqual(timecodeToFrames('01:00:00:00', NTSC24), 86400);
58
+ assert.strictEqual(timecodeToFrames('10:00:00:00', 25), 900000);
59
+ assert.strictEqual(timecodeToFrames('00:01:00;02', NTSC30), 1800);
60
+ assert.strictEqual(timecodeToFrames('01:00:00;00', NTSC30), 107892);
61
+ assert.strictEqual(timecodeToFrames('01:00:00;00', NTSC60), 215784);
62
+ // No startFrame: the caller's label is written as given, frame from it.
63
+ assert.deepStrictEqual(
64
+ start(await buildSeqContainerFile(tl, { frameRate: NTSC30, startTimecode: '01:00:00;00' })),
65
+ { frame: 107892, tc: '01:00:00;00' },
66
+ );
67
+ assert.deepStrictEqual(
68
+ start(await buildSeqContainerFile(tl, { frameRate: NTSC24 })),
69
+ { frame: 86400, tc: '01:00:00:00' },
70
+ );
71
+ // A startFrame that agrees with the label leaves both unchanged.
72
+ assert.deepStrictEqual(
73
+ start(await buildSeqContainerFile(tl, { frameRate: NTSC30, startTimecode: '01:00:00;00', startFrame: 107892 })),
74
+ { frame: 107892, tc: '01:00:00;00' },
75
+ );
76
+ });
77
+
78
+ test('an explicit startFrame is written with its own label in <StartTC>', async () => {
79
+ // 90000 / 24 = 3750 s = 01:02:30:00.
80
+ assert.deepStrictEqual(
81
+ start(await buildSeqContainerFile(tl, { frameRate: 24, startFrame: 90000 })),
82
+ { frame: 90000, tc: '01:02:30:00' },
83
+ );
84
+ // 99999 at the 30 timebase = 3333 s + 9 f = 00:55:33:09 (non-drop: ':' given).
85
+ assert.deepStrictEqual(
86
+ start(await buildSeqContainerFile(tl, { frameRate: NTSC30, startTimecode: '01:00:00:00', startFrame: 99999 })),
87
+ { frame: 99999, tc: '00:55:33:09' },
88
+ );
89
+ // Drop-frame stays drop-frame: 125874 = 107892 + 17982 (ten DF minutes).
90
+ assert.deepStrictEqual(
91
+ start(await buildSeqContainerFile(tl, { frameRate: NTSC30, startTimecode: '01:00:00;00', startFrame: 125874 })),
92
+ { frame: 125874, tc: '01:10:00;00' },
93
+ );
94
+ });
95
+
96
+ test('drop-frame labels are refused at rates that have no drop-frame', async () => {
97
+ for (const fps of [24, 25, NTSC24, 30, 50]) {
98
+ assert.throws(() => timecodeToFrames('01:00:00;00', fps), RangeError, `fps ${fps}`);
99
+ await assert.rejects(buildSeqContainerFile(tl, { frameRate: fps, startTimecode: '01:00:00;00' }), RangeError);
100
+ }
101
+ });
102
+
103
+ test('malformed and out-of-range labels are refused, not counted as frame 0', async () => {
104
+ for (const tc of ['garbage', '01:00:00', '', '01:00:00:00:00', '01:60:00:00', '01:00:60:00', '01:00:00:30', '1:2:3:4']) {
105
+ assert.throws(() => timecodeToFrames(tc, NTSC30), RangeError, JSON.stringify(tc));
106
+ }
107
+ assert.throws(() => timecodeToFrames('01:00:00:24', 24), RangeError);
108
+ assert.throws(() => timecodeToFrames(null, 24), RangeError);
109
+ await assert.rejects(buildSeqContainerFile(tl, { frameRate: 24, startTimecode: 'garbage' }), RangeError);
110
+ });
111
+
112
+ test('drop-frame labels that do not exist are refused', () => {
113
+ // Minute 1 has no ;00 or ;01 at 29.97 (no ;00-;03 at 59.94); minute 10 keeps them.
114
+ assert.throws(() => timecodeToFrames('00:01:00;00', NTSC30), RangeError);
115
+ assert.throws(() => timecodeToFrames('00:01:00;01', NTSC30), RangeError);
116
+ assert.throws(() => timecodeToFrames('00:01:00;03', NTSC60), RangeError);
117
+ assert.strictEqual(timecodeToFrames('00:10:00;00', NTSC30), 17982);
118
+ assert.strictEqual(timecodeToFrames('00:01:00;04', NTSC60), 3600);
119
+ });
120
+
121
+ test('SECOND CHANNEL: labels match an independent SMPTE 12M labeller and round-trip', () => {
122
+ // Hand values first.
123
+ assert.strictEqual(framesToTimecode(1800, NTSC30, true), '00:01:00;02');
124
+ assert.strictEqual(framesToTimecode(17982, NTSC30, true), '00:10:00;00');
125
+ assert.strictEqual(framesToTimecode(107892, NTSC30, true), '01:00:00;00');
126
+ assert.strictEqual(framesToTimecode(86400, NTSC24, false), '01:00:00:00');
127
+ for (const [fps, nominal] of [[NTSC30, 30], [NTSC60, 60]]) {
128
+ for (let f = 0; f < nominal * 3600 * 2; f += 7) {
129
+ const label = framesToTimecode(f, fps, true);
130
+ assert.strictEqual(label, refDropFrameLabel(f, nominal), `frame ${f} @ ${nominal}`);
131
+ assert.strictEqual(timecodeToFrames(label, fps), f);
132
+ }
133
+ }
134
+ for (const fps of [NTSC24, 24, 25, NTSC30]) {
135
+ for (let f = 0; f < 200000; f += 13) {
136
+ assert.strictEqual(timecodeToFrames(framesToTimecode(f, fps, false), fps), f);
137
+ }
138
+ }
139
+ });
@@ -27,7 +27,6 @@ const { encodeRichEffectFiltersBA, buildRichFieldsBlob } = require('./rich-title
27
27
  async function buildSeqContainerFile(timeline, options = {}) {
28
28
  const {
29
29
  frameRate = 24,
30
- startTimecode = '01:00:00:00',
31
30
  markers = [],
32
31
  resolution = '1920x1080',
33
32
  } = options;
@@ -60,11 +59,9 @@ async function buildSeqContainerFile(timeline, options = {}) {
60
59
  // Build lockable blob with markers
61
60
  const lockableBlob = buildLockableBlobElement(markers, lockableBlobId, frameRate);
62
61
 
63
- // An explicit startFrame wins; otherwise derive it from the timecode
64
- // (issue #168 — the spec field used to be ignored entirely).
65
- const startFrame = Number.isFinite(options.startFrame)
66
- ? Math.round(options.startFrame)
67
- : timecodeToFrames(startTimecode, frameRate);
62
+ // <StartFrame> and the <StartTC> that labels it: an explicit startFrame
63
+ // wins (issue #168), otherwise counted from the timecode; they always agree.
64
+ const { startFrame, startTimecode } = resolveTimelineStart(options, frameRate);
68
65
 
69
66
  // Combine video tracks: standard video tracks first, then Rich title tracks
70
67
  const allVideoTrackElements = [...videoTrackElements, ...richTitleTrackElements];
@@ -363,35 +360,121 @@ function buildMarkersFieldsBlob(markers, frameRate) {
363
360
  return '0000000100000000';
364
361
  }
365
362
 
363
+ // =============================================================================
364
+ // TIMELINE START (<StartFrame> / <StartTC>)
365
+ // =============================================================================
366
+
367
+ const TIMECODE_LABEL = /^(\d{1,2})[:;](\d{2})[:;](\d{2})[:;](\d{2})$/;
368
+
366
369
  /**
367
- * Convert timecode to frames
370
+ * The integer timebase SMPTE timecode counts at (24 for 23.976, 30 for 29.97)
371
+ * and how many numbers drop-frame skips a minute: 2 at 30000/1001, 4 at
372
+ * 60000/1001, and 0 at every other rate, which has no drop-frame timecode
373
+ * (SMPTE 12M).
368
374
  */
369
- function timecodeToFrames(timecode, fps = 24) {
370
- if (!timecode || typeof timecode !== 'string') return 0;
371
-
372
- const dropFrame = timecode.includes(';');
373
- const parts = timecode.replace(/;/g, ':').split(':').map(Number);
374
- if (parts.length !== 4 || parts.some(Number.isNaN)) return 0;
375
+ function timecodeBase(fps) {
376
+ const rate = Number(fps);
377
+ if (!Number.isFinite(rate) || rate <= 0) {
378
+ throw new RangeError(`frame rate ${JSON.stringify(fps)} is not a positive number`);
379
+ }
380
+ const nominal = Math.round(rate);
381
+ const ntsc = Math.abs(rate - nominal) > 0.001 && Math.abs(rate - (nominal * 1000) / 1001) < 0.01;
382
+ const dropPerMinute = ntsc && (nominal === 30 || nominal === 60) ? nominal / 15 : 0;
383
+ return { nominal, dropPerMinute };
384
+ }
375
385
 
376
- const [hh, mm, ss, ff] = parts;
386
+ /**
387
+ * Convert a timecode label to a frame count. ';' marks drop-frame.
388
+ * Throws a RangeError for anything the rate cannot count: a malformed label,
389
+ * a field out of range, drop-frame at a rate without it, or a drop-frame label
390
+ * that does not exist (00:01:00;00 at 29.97). It used to return 0 or a wrong
391
+ * count for these, which was then written as the timeline start.
392
+ */
393
+ function timecodeToFrames(timecode, fps = 24) {
394
+ const m = typeof timecode === 'string' ? timecode.trim().match(TIMECODE_LABEL) : null;
395
+ if (!m) {
396
+ throw new RangeError(`timecode ${JSON.stringify(timecode)} is not HH:MM:SS:FF (HH:MM:SS;FF for drop-frame)`);
397
+ }
398
+ const [hh, mm, ss, ff] = m.slice(1, 5).map(Number);
399
+ const { nominal, dropPerMinute } = timecodeBase(fps);
400
+ if (mm > 59 || ss > 59 || ff >= nominal) {
401
+ throw new RangeError(`timecode ${JSON.stringify(timecode)} is out of range at ${fps} fps`);
402
+ }
377
403
  // SMPTE timecode counts NOMINAL frames: the fields multiply by the integer
378
404
  // base (30 for 29.97, 24 for 23.976), not the exact rate. Measured against
379
405
  // Resolve itself (Studio 19.1.3.7): a 29.97 timeline at 01:00:00:00 reads
380
406
  // GetStartFrame 108000 = 3600 x 30, and a 23.976 one reads 86400 = 3600 x
381
407
  // 24. Both the pre-#168 exact-rate product (107892.107...) and its rounded
382
408
  // fix (107892) were wrong; nominal is what Resolve stores.
383
- const nominal = Math.round(fps);
384
409
  let frames = (hh * 3600 + mm * 60 + ss) * nominal + ff;
385
- if (dropFrame) {
386
- // Drop-frame skips 2 (or 4 at 59.94) TC numbers per minute except every
387
- // tenth minute — same formula as the Python _timecode_to_frame_id.
388
- const dropped = Math.round(nominal * 0.0666666667);
410
+ if (timecode.includes(';')) {
411
+ if (!dropPerMinute) {
412
+ throw new RangeError(`drop-frame timecode ${JSON.stringify(timecode)} does not exist at ${fps} fps (only 29.97 and 59.94 drop frames)`);
413
+ }
414
+ if (ss === 0 && ff < dropPerMinute && mm % 10 !== 0) {
415
+ throw new RangeError(`drop-frame timecode ${JSON.stringify(timecode)} is a dropped label`);
416
+ }
417
+ // Drop-frame skips 2 (4 at 59.94) numbers per minute except every tenth
418
+ // minute — same formula as the Python _timecode_to_frame_id.
389
419
  const totalMinutes = hh * 60 + mm;
390
- frames -= dropped * (totalMinutes - Math.floor(totalMinutes / 10));
420
+ frames -= dropPerMinute * (totalMinutes - Math.floor(totalMinutes / 10));
391
421
  }
392
422
  return frames;
393
423
  }
394
424
 
425
+ /**
426
+ * Label a frame count as timecode at `fps`: the inverse of timecodeToFrames.
427
+ * @param {number} frames - non-negative integer frame count
428
+ * @param {number} fps - frame rate
429
+ * @param {boolean} [dropFrame=false] - drop-frame labels (29.97 / 59.94 only)
430
+ * @returns {string} HH:MM:SS:FF, or HH:MM:SS;FF for drop-frame
431
+ */
432
+ function framesToTimecode(frames, fps, dropFrame = false) {
433
+ if (!Number.isSafeInteger(frames) || frames < 0) {
434
+ throw new RangeError(`frame ${JSON.stringify(frames)} is not a non-negative integer`);
435
+ }
436
+ const { nominal, dropPerMinute } = timecodeBase(fps);
437
+ if (dropFrame && !dropPerMinute) {
438
+ throw new RangeError(`drop-frame timecode does not exist at ${fps} fps (only 29.97 and 59.94 drop frames)`);
439
+ }
440
+ let n = frames;
441
+ if (dropFrame) {
442
+ // Put back the numbers skipped before this frame, then count as non-drop.
443
+ const perMinute = nominal * 60 - dropPerMinute;
444
+ const perTenMinutes = perMinute * 10 + dropPerMinute;
445
+ const tens = Math.floor(n / perTenMinutes);
446
+ const rem = n % perTenMinutes;
447
+ n += dropPerMinute * 9 * tens;
448
+ if (rem > dropPerMinute) n += dropPerMinute * Math.floor((rem - dropPerMinute) / perMinute);
449
+ }
450
+ const pad = (v) => String(v).padStart(2, '0');
451
+ const totalSeconds = Math.floor(n / nominal);
452
+ return `${pad(Math.floor(totalSeconds / 3600))}:${pad(Math.floor(totalSeconds / 60) % 60)}:${pad(totalSeconds % 60)}${dropFrame ? ';' : ':'}${pad(n % nominal)}`;
453
+ }
454
+
455
+ /**
456
+ * The timeline's first frame as the pair a SeqContainer stores: <StartFrame>
457
+ * and the <StartTC> that labels it. An explicit startFrame wins (issue #168)
458
+ * and is labelled in the caller's counting mode (';' in startTimecode means
459
+ * drop-frame); otherwise the frame is counted from startTimecode. Either way
460
+ * the two describe the same frame — before, an explicit startFrame was written
461
+ * beside the caller's (or the default 01:00:00:00) unrelated label.
462
+ *
463
+ * @param {{ startTimecode?: string, startFrame?: number }} options
464
+ * @param {number} frameRate - timeline frame rate
465
+ * @returns {{ startFrame: number, startTimecode: string }}
466
+ */
467
+ function resolveTimelineStart(options = {}, frameRate = 24) {
468
+ const startTimecode = options.startTimecode === undefined ? '01:00:00:00' : options.startTimecode;
469
+ if (Number.isFinite(options.startFrame)) {
470
+ const startFrame = Math.round(options.startFrame);
471
+ const dropFrame = typeof startTimecode === 'string' && startTimecode.includes(';');
472
+ return { startFrame, startTimecode: framesToTimecode(startFrame, frameRate, dropFrame) };
473
+ }
474
+ const label = typeof startTimecode === 'string' ? startTimecode.trim() : startTimecode;
475
+ return { startFrame: timecodeToFrames(label, frameRate), startTimecode: label };
476
+ }
477
+
395
478
  // =============================================================================
396
479
  // SUBTITLE TRACK / CLIP BUILDERS
397
480
  // =============================================================================
@@ -595,4 +678,6 @@ module.exports = {
595
678
  buildRichTitleClipElement,
596
679
  buildRichTitleTrackElement,
597
680
  timecodeToFrames,
681
+ framesToTimecode,
682
+ resolveTimelineStart,
598
683
  };
@@ -0,0 +1,81 @@
1
+ /**
2
+ * OFX parameter value encodings beyond float64 / int / string: CHOICE menus and
3
+ * RGB colors, as Resolve 19.1.3 writes them in a node's OFX container (measured
4
+ * on stills exported from a node with a choice parameter set to non-default
5
+ * indices, and a color parameter set to 128/255 grey).
6
+ *
7
+ * choice: value F2 -> F4 { F1 = zigzag varint(index) }. Index 0 is stored as an
8
+ * EMPTY F4 (proto3 drops the zero), and a parameter left at its
9
+ * default is not stored at all (no F5 entry).
10
+ * color: value F2 -> F7 { F1, F2, F3 = float32 r, g, b (F4 = a when present) }.
11
+ *
12
+ * Generic: indices and components only. What an index MEANS is the plugin's own
13
+ * menu, which is not this library's business.
14
+ */
15
+ const test = require('node:test');
16
+ const assert = require('node:assert/strict');
17
+
18
+ const { extractOFXTools, _internals } = require('../extract-ofx-params');
19
+
20
+ function encVarint(value) {
21
+ let n = BigInt(value);
22
+ const bytes = [];
23
+ while (n > 0x7fn) {
24
+ bytes.push(Number((n & 0x7fn) | 0x80n));
25
+ n >>= 7n;
26
+ }
27
+ bytes.push(Number(n & 0x7fn));
28
+ return Buffer.from(bytes);
29
+ }
30
+ const tag = (f, w) => encVarint((f << 3) | w);
31
+ const bytesField = (f, buf) => Buffer.concat([tag(f, 2), encVarint(buf.length), buf]);
32
+ const varintField = (f, v) => Buffer.concat([tag(f, 0), encVarint(v)]);
33
+ const f32 = (f, v) => { const b = Buffer.alloc(4); b.writeFloatLE(v); return Buffer.concat([tag(f, 5), b]); };
34
+ const f64 = (f, v) => { const b = Buffer.alloc(8); b.writeDoubleLE(v); return Buffer.concat([tag(f, 1), b]); };
35
+ const zigzag = (n) => (n << 1) ^ (n >> 31);
36
+ const entry = (name, valueBuf) => Buffer.concat([bytesField(1, Buffer.from(name)), bytesField(2, valueBuf)]);
37
+
38
+ test('choice: F2.F4.F1 zigzag varint decodes to {choice: index}', () => {
39
+ // The exact bytes Resolve wrote for index 10: 22 02 08 14.
40
+ assert.deepEqual(Buffer.from('22020814', 'hex'), bytesField(4, varintField(1, zigzag(10))));
41
+ assert.deepEqual(_internals.decodeParamEntry(entry('aspect', Buffer.from('22020814', 'hex'))), { name: 'aspect', value: { choice: 10 } });
42
+ assert.deepEqual(_internals.decodeParamEntry(entry('aspect', Buffer.from('22020820', 'hex'))).value, { choice: 16 });
43
+ });
44
+
45
+ test('choice: an empty F4 is index 0, not "no value"', () => {
46
+ assert.deepEqual(_internals.decodeParamEntry(entry('version', Buffer.from('2200', 'hex'))).value, { choice: 0 });
47
+ });
48
+
49
+ test('color: F2.F7 float32 components decode to {rgb: [r, g, b]}', () => {
50
+ // Resolve's bytes for 128/255 grey: 3a 0f 0d <f32> 15 <f32> 1d <f32>.
51
+ const grey = Buffer.from('3a0f0d8180003f158180003f1d8180003f', 'hex');
52
+ const v = _internals.decodeParamEntry(entry('fill', grey)).value;
53
+ assert.ok(v && Array.isArray(v.rgb) && v.rgb.length === 3);
54
+ for (const c of v.rgb) assert.ok(Math.abs(c - 128 / 255) < 1e-6, `component ${c}`);
55
+ const rgba = bytesField(7, Buffer.concat([f32(1, 1), f32(2, 0.5), f32(3, 0.25), f32(4, 0.75)]));
56
+ assert.deepEqual(_internals.decodeParamEntry(entry('fill', rgba)).value, { rgb: [1, 0.5, 0.25], alpha: 0.75 });
57
+ });
58
+
59
+ test('null controls: float64, int and string values decode as before', () => {
60
+ assert.equal(_internals.decodeParamEntry(entry('scale', f64(2, 90))).value, 90);
61
+ assert.deepEqual(_internals.decodeParamEntry(entry('n', varintField(3, 4))).value, { int: 4 });
62
+ assert.equal(_internals.decodeParamEntry(entry('s', bytesField(5, Buffer.from('x')))).value, 'x');
63
+ // An unknown wrapped field is still "no value", never guessed as a choice or color.
64
+ assert.equal(_internals.decodeParamEntry(entry('u', varintField(9, 1))).value, null);
65
+ });
66
+
67
+ test('end to end: a container with a choice and a color comes back through extractOFXTools', () => {
68
+ const container = Buffer.concat([
69
+ varintField(1, 0x4f4659),
70
+ bytesField(2, Buffer.from('com.example.plugin')),
71
+ bytesField(3, Buffer.from('inst-1')),
72
+ varintField(4, 1),
73
+ bytesField(5, entry('aspect', Buffer.from('22020814', 'hex'))),
74
+ bytesField(5, entry('fill', bytesField(7, Buffer.concat([f32(1, 0.5), f32(2, 0.5), f32(3, 0.5)])))),
75
+ bytesField(5, entry('scale', f64(2, 90))),
76
+ ]);
77
+ const toolEntry = Buffer.concat([varintField(1, 2), bytesField(2, bytesField(21, container))]);
78
+ const tools = extractOFXTools(bytesField(1, toolEntry));
79
+ assert.equal(tools.length, 1);
80
+ assert.deepEqual(tools[0].params, { aspect: { choice: 10 }, fill: { rgb: [0.5, 0.5, 0.5] }, scale: 90 });
81
+ });
@@ -14,13 +14,16 @@
14
14
  * F4 = enabled varint (1)
15
15
  * F5[] = repeated param entries
16
16
  * F1 = param name UTF-8
17
- * F2 = wrapped value: F2 (float64) OR F5 (UTF-8 string)
17
+ * F2 = wrapped value: F2 (float64), F3 (varint int), F5 (UTF-8 string),
18
+ * F4 { F1 = zigzag varint } (CHOICE index; an empty F4 is index 0) or
19
+ * F7 { F1..F3 float32 r,g,b; F4 alpha } (RGB(A) color)
18
20
  *
19
21
  * extractOFXTools(toolListBuf | toolListField) returns
20
22
  * Array<{ pluginId, instanceId, enabled, params: {name: value} }>
21
23
  *
22
- * Each `value` is either a number (when F2.F2 was a float64) or a
23
- * string (when F2.F5 was UTF-8).
24
+ * Each `value` is a number (F2.F2 float64), {int} (F2.F3), a string (F2.F5),
25
+ * {choice: index} (F2.F4) or {rgb: [r,g,b], alpha?} (F2.F7). A choice left at
26
+ * its default is not stored by Resolve at all: absent is "default", not 0.
24
27
  *
25
28
  * P2 coverage: tool IDs beyond Film Grain land in the registry as
26
29
  * AutoResearch lands them. The extractor doesn't depend on the tool ID
@@ -111,6 +114,27 @@ function decodeParamEntry(entryBuf) {
111
114
  value = { int: Number(inn.value) };
112
115
  } else if (inn.fieldNum === 5 && inn.wireType === 2) {
113
116
  value = utf8(inn.value);
117
+ } else if (inn.fieldNum === 4 && inn.wireType === 2) {
118
+ // CHOICE menu: F4 { F1 = zigzag varint(index) }. Index 0 is an EMPTY F4
119
+ // (proto3 drops the zero). Measured on Resolve 19.1.3 stills.
120
+ let index = 0;
121
+ for (const c of readAllFields(inn.value)) {
122
+ if (c.fieldNum === 1 && c.wireType === 0) {
123
+ const z = c.value;
124
+ index = Number((z >> 1n) ^ -(z & 1n));
125
+ }
126
+ }
127
+ value = { choice: index };
128
+ } else if (inn.fieldNum === 7 && inn.wireType === 2) {
129
+ // RGB(A) color: F7 { F1, F2, F3 = float32 r, g, b; F4 = alpha when present }.
130
+ const comp = [0, 0, 0];
131
+ let alpha = null;
132
+ for (const c of readAllFields(inn.value)) {
133
+ if (c.wireType !== 5) continue;
134
+ if (c.fieldNum >= 1 && c.fieldNum <= 3) comp[c.fieldNum - 1] = c.value;
135
+ else if (c.fieldNum === 4) alpha = c.value;
136
+ }
137
+ value = alpha === null ? { rgb: comp } : { rgb: comp, alpha };
114
138
  }
115
139
  }
116
140
  }
@@ -94,7 +94,7 @@ if not logging.getLogger().handlers:
94
94
  handlers=[logging.StreamHandler()],
95
95
  )
96
96
 
97
- VERSION = "5.3.1"
97
+ VERSION = "5.3.3"
98
98
  logger = logging.getLogger("davinci-resolve-mcp")
99
99
  logger.info(f"Starting DaVinci Resolve MCP Server v{VERSION}")
100
100
  logger.info(f"Detected platform: {get_platform()}")
package/src/server.py CHANGED
@@ -11,7 +11,7 @@ Usage:
11
11
  python src/server.py --full # Start the 377-tool granular server instead
12
12
  """
13
13
 
14
- VERSION = "5.3.1"
14
+ VERSION = "5.3.3"
15
15
 
16
16
  import base64
17
17
  import os