davinci-resolve-mcp 4.7.8 → 4.7.10
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 +46 -0
- package/README.md +1 -1
- package/README.zh-CN.md +2 -2
- package/install.py +1 -1
- package/package.json +1 -1
- package/src/granular/common.py +4 -2
- package/src/granular/gallery.py +28 -10
- package/src/server.py +27 -9
- package/src/utils/multicam.py +49 -0
- package/src/utils/sync_detection.py +14 -27
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,52 @@
|
|
|
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 v4.7.10 — drop-frame sync events are reported at the timecode they happen
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- **A sync event on a drop-frame clip was reported 3.6 seconds per hour early, and
|
|
10
|
+
rendered as non-drop.** ([#248](https://github.com/samuelgursky/davinci-resolve-mcp/pull/248), @Dev-next-gen)
|
|
11
|
+
`_timecode_for_event` reports an event at `start_timecode + offset`, where the start
|
|
12
|
+
timecode comes from the media's own timecode track via ffprobe and on an NTSC
|
|
13
|
+
deliverable is routinely drop-frame (`HH:MM:SS;FF`). `timecode_to_frames` honours
|
|
14
|
+
drop-frame (`01:00:00;00` at 29.97 is frame 107892), but the detector's private
|
|
15
|
+
`_frames_to_timecode` had no drop-frame arithmetic, so the frame numbers subtracted
|
|
16
|
+
on the way in were never added back: the head of a drop-frame clip came back as
|
|
17
|
+
`00:59:56:12`. That value is appended to the marker note written into the Resolve
|
|
18
|
+
project — the thing someone reads to line two cameras up off a 2-pop. The inverse
|
|
19
|
+
now lives next to the forward conversion in `src/utils/multicam.py` as
|
|
20
|
+
`frames_to_timecode`, so the pair cannot drift apart again, and `sync_detection`
|
|
21
|
+
carries the drop-frame spelling of the start timecode through to it. Non-drop
|
|
22
|
+
timecode is deliberately unchanged (29.97 colon timecode legitimately lags the wall
|
|
23
|
+
clock), and a semicolon at 23.976 still drops nothing because drop-frame is only
|
|
24
|
+
defined at nominal 30 and 60. Verified on landing by brute force against the forward
|
|
25
|
+
conversion: two hours at 29.97 (216,000 frames) and 59.94 (432,000 frames), zero
|
|
26
|
+
round-trip violations, every timecode unique, dropped numbers never at the top of a
|
|
27
|
+
non-tenth minute. Guard test: `tests/test_sync_event_timecode.py`.
|
|
28
|
+
|
|
29
|
+
## What's New in v4.7.9 — a negative still, album or item index is refused
|
|
30
|
+
|
|
31
|
+
### Fixed
|
|
32
|
+
|
|
33
|
+
- **A negative index acted on the last element instead of being refused.** ([#247](https://github.com/samuelgursky/davinci-resolve-mcp/pull/247), @Dev-next-gen)
|
|
34
|
+
Python reads `items[-1]` as the last item, and several lookups bounded an index with
|
|
35
|
+
`>= len(...)` only. The granular `_get_timeline_item` — which 85 granular tools go
|
|
36
|
+
through — had exactly the gap EX5 closed in the compound `_get_item`, so
|
|
37
|
+
`item_index=-1` acted on the last clip of the track. Every album and still lookup in
|
|
38
|
+
the compound `gallery` / `gallery_stills` tools and in `src/granular/gallery.py` had
|
|
39
|
+
the same one-sided check. Sharpest case: `gallery_stills delete_stills` and granular
|
|
40
|
+
`delete_stills_from_album` with `still_indices=[-1]` deleted the album's LAST still,
|
|
41
|
+
and an out-of-range index was silently dropped while the others were deleted and the
|
|
42
|
+
call reported success. The lower bound is now in the granular resolver and gallery
|
|
43
|
+
lookups, a small `_index_in_range` helper guards the compound gallery tools, and the
|
|
44
|
+
two delete paths refuse the whole call when any index is not a 0-based position
|
|
45
|
+
(the way `ti_copy_grades` treats its target list) rather than deleting a set nobody
|
|
46
|
+
asked for. Valid indices behave exactly as before; the one visible change is that a
|
|
47
|
+
partly invalid `still_indices` list now errors instead of partially deleting. Guard
|
|
48
|
+
test: `tests/test_negative_index_refused.py` drives the real tool bodies against fake
|
|
49
|
+
gallery and timeline objects; 16 subtests fail on the previous code.
|
|
50
|
+
|
|
5
51
|
## What's New in v4.7.8 — `allow_non_mcp_name="false"` no longer lifts the `_mcp_` name guard
|
|
6
52
|
|
|
7
53
|
### Fixed
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
English | [简体中文](README.zh-CN.md)
|
|
4
4
|
|
|
5
|
-
[](https://github.com/samuelgursky/davinci-resolve-mcp/releases)
|
|
6
6
|
[](https://www.npmjs.com/package/davinci-resolve-mcp)
|
|
7
7
|
[](docs/reference/api-coverage.md)
|
|
8
8
|
[-blue.svg)](#server-modes)
|
package/README.zh-CN.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[English](README.md) | 简体中文
|
|
4
4
|
|
|
5
|
-
[](https://github.com/samuelgursky/davinci-resolve-mcp/releases)
|
|
6
6
|
[](https://www.npmjs.com/package/davinci-resolve-mcp)
|
|
7
7
|
[](docs/reference/api-coverage.md)
|
|
8
8
|
[-blue.svg)](#服务器模式)
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
[](https://www.python.org/downloads/)
|
|
13
13
|
[](https://opensource.org/licenses/MIT)
|
|
14
14
|
|
|
15
|
-
> 本翻译对应 v4.7.
|
|
15
|
+
> 本翻译对应 v4.7.10 版 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 = "4.7.
|
|
40
|
+
VERSION = "4.7.10"
|
|
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
package/src/granular/common.py
CHANGED
|
@@ -93,7 +93,7 @@ if not logging.getLogger().handlers:
|
|
|
93
93
|
handlers=[logging.StreamHandler()],
|
|
94
94
|
)
|
|
95
95
|
|
|
96
|
-
VERSION = "4.7.
|
|
96
|
+
VERSION = "4.7.10"
|
|
97
97
|
logger = logging.getLogger("davinci-resolve-mcp")
|
|
98
98
|
logger.info(f"Starting DaVinci Resolve MCP Server v{VERSION}")
|
|
99
99
|
logger.info(f"Detected platform: {get_platform()}")
|
|
@@ -810,7 +810,9 @@ def _get_timeline_item(track_type="video", track_index=1, item_index=0):
|
|
|
810
810
|
if err:
|
|
811
811
|
return None, err
|
|
812
812
|
items = tl.GetItemListInTrack(track_type, track_index)
|
|
813
|
-
|
|
813
|
+
# Reject negatives: `items[-1]` is the LAST clip, so a negative index would
|
|
814
|
+
# act on a clip nobody named (EX5 fixed the compound `_get_item`, not this twin).
|
|
815
|
+
if not items or item_index < 0 or item_index >= len(items):
|
|
814
816
|
return None, {"error": f"No item at index {item_index} on {track_type} track {track_index}"}
|
|
815
817
|
return items[item_index], None
|
|
816
818
|
|
package/src/granular/gallery.py
CHANGED
|
@@ -4,6 +4,18 @@ from src.granular.common import * # noqa: F401,F403
|
|
|
4
4
|
|
|
5
5
|
resolve = ResolveProxy()
|
|
6
6
|
|
|
7
|
+
|
|
8
|
+
def _index_in_range(idx, length):
|
|
9
|
+
"""True for a real 0-based position. Negatives are refused: Python would read
|
|
10
|
+
`albums[-1]` as the last album and act on something nobody named."""
|
|
11
|
+
return isinstance(idx, int) and not isinstance(idx, bool) and 0 <= idx < length
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _invalid_indices(indices, length):
|
|
15
|
+
"""The entries of `indices` that are not a 0-based position below `length`."""
|
|
16
|
+
return [i for i in indices if not _index_in_range(i, length)]
|
|
17
|
+
|
|
18
|
+
|
|
7
19
|
@mcp.tool(annotations=READ_ONLY_TOOL)
|
|
8
20
|
def get_gallery_album_name() -> Dict[str, Any]:
|
|
9
21
|
"""Get the name of the current gallery album."""
|
|
@@ -107,7 +119,7 @@ def set_current_still_album(album_index: int) -> Dict[str, Any]:
|
|
|
107
119
|
if not gallery:
|
|
108
120
|
return {"error": "Failed to get Gallery"}
|
|
109
121
|
albums = gallery.GetGalleryStillAlbums()
|
|
110
|
-
if not albums or album_index >= len(albums):
|
|
122
|
+
if not albums or album_index < 0 or album_index >= len(albums):
|
|
111
123
|
return {"error": f"No album at index {album_index}"}
|
|
112
124
|
result = gallery.SetCurrentStillAlbum(albums[album_index])
|
|
113
125
|
return {"success": bool(result)}
|
|
@@ -176,7 +188,7 @@ def get_album_stills(album_index: int = 0) -> Dict[str, Any]:
|
|
|
176
188
|
if not gallery:
|
|
177
189
|
return {"error": "Failed to get Gallery"}
|
|
178
190
|
albums = gallery.GetGalleryStillAlbums()
|
|
179
|
-
if not albums or album_index >= len(albums):
|
|
191
|
+
if not albums or album_index < 0 or album_index >= len(albums):
|
|
180
192
|
return {"error": f"No album at index {album_index}"}
|
|
181
193
|
stills = albums[album_index].GetStills()
|
|
182
194
|
return {"still_count": len(stills) if stills else 0}
|
|
@@ -198,10 +210,10 @@ def get_still_label(album_index: int, still_index: int) -> Dict[str, Any]:
|
|
|
198
210
|
return {"error": "No project open"}
|
|
199
211
|
gallery = project.GetGallery()
|
|
200
212
|
albums = gallery.GetGalleryStillAlbums()
|
|
201
|
-
if not albums or album_index >= len(albums):
|
|
213
|
+
if not albums or album_index < 0 or album_index >= len(albums):
|
|
202
214
|
return {"error": f"No album at index {album_index}"}
|
|
203
215
|
stills = albums[album_index].GetStills()
|
|
204
|
-
if not stills or still_index >= len(stills):
|
|
216
|
+
if not stills or still_index < 0 or still_index >= len(stills):
|
|
205
217
|
return {"error": f"No still at index {still_index}"}
|
|
206
218
|
label = albums[album_index].GetLabel(stills[still_index])
|
|
207
219
|
return {"label": label if label else ""}
|
|
@@ -225,10 +237,10 @@ def set_still_label(album_index: int, still_index: int, label: str) -> Dict[str,
|
|
|
225
237
|
return {"error": "No project open"}
|
|
226
238
|
gallery = project.GetGallery()
|
|
227
239
|
albums = gallery.GetGalleryStillAlbums()
|
|
228
|
-
if not albums or album_index >= len(albums):
|
|
240
|
+
if not albums or album_index < 0 or album_index >= len(albums):
|
|
229
241
|
return {"error": f"No album at index {album_index}"}
|
|
230
242
|
stills = albums[album_index].GetStills()
|
|
231
|
-
if not stills or still_index >= len(stills):
|
|
243
|
+
if not stills or still_index < 0 or still_index >= len(stills):
|
|
232
244
|
return {"error": f"No still at index {still_index}"}
|
|
233
245
|
result = albums[album_index].SetLabel(stills[still_index], label)
|
|
234
246
|
return {"success": bool(result)}
|
|
@@ -250,7 +262,7 @@ def import_stills_to_album(album_index: int, file_paths: List[str]) -> Dict[str,
|
|
|
250
262
|
return {"error": "No project open"}
|
|
251
263
|
gallery = project.GetGallery()
|
|
252
264
|
albums = gallery.GetGalleryStillAlbums()
|
|
253
|
-
if not albums or album_index >= len(albums):
|
|
265
|
+
if not albums or album_index < 0 or album_index >= len(albums):
|
|
254
266
|
return {"error": f"No album at index {album_index}"}
|
|
255
267
|
result = albums[album_index].ImportStills(file_paths)
|
|
256
268
|
return {"success": bool(result)}
|
|
@@ -274,7 +286,7 @@ def export_stills_from_album(album_index: int, folder_path: str, file_prefix: st
|
|
|
274
286
|
return {"error": "No project open"}
|
|
275
287
|
gallery = project.GetGallery()
|
|
276
288
|
albums = gallery.GetGalleryStillAlbums()
|
|
277
|
-
if not albums or album_index >= len(albums):
|
|
289
|
+
if not albums or album_index < 0 or album_index >= len(albums):
|
|
278
290
|
return {"error": f"No album at index {album_index}"}
|
|
279
291
|
stills = albums[album_index].GetStills()
|
|
280
292
|
if not stills:
|
|
@@ -300,11 +312,17 @@ def delete_stills_from_album(album_index: int, still_indices: List[int]) -> Dict
|
|
|
300
312
|
return {"error": "No project open"}
|
|
301
313
|
gallery = project.GetGallery()
|
|
302
314
|
albums = gallery.GetGalleryStillAlbums()
|
|
303
|
-
if not albums or album_index >= len(albums):
|
|
315
|
+
if not albums or album_index < 0 or album_index >= len(albums):
|
|
304
316
|
return {"error": f"No album at index {album_index}"}
|
|
305
317
|
stills = albums[album_index].GetStills()
|
|
306
318
|
if not stills:
|
|
307
319
|
return {"error": "No stills in album"}
|
|
308
|
-
|
|
320
|
+
# A negative index is a real Python index (`stills[-1]` is the last still),
|
|
321
|
+
# and an out-of-range one used to be dropped while the rest were deleted.
|
|
322
|
+
# Refuse the whole call instead of deleting a set nobody asked for.
|
|
323
|
+
invalid = _invalid_indices(still_indices, len(stills))
|
|
324
|
+
if invalid:
|
|
325
|
+
return {"error": f"still_indices out of range for {len(stills)} stills: {invalid}"}
|
|
326
|
+
to_delete = [stills[i] for i in still_indices]
|
|
309
327
|
result = albums[album_index].DeleteStills(to_delete)
|
|
310
328
|
return {"success": bool(result)}
|
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 = "4.7.
|
|
14
|
+
VERSION = "4.7.10"
|
|
15
15
|
|
|
16
16
|
import base64
|
|
17
17
|
import os
|
|
@@ -28848,6 +28848,17 @@ def timeline_item_takes(action: str, params: Optional[Dict[str, Any]] = None) ->
|
|
|
28848
28848
|
return _unknown(action, ["add","get_count","get_selected_index","get_by_index","select","delete","finalize"])
|
|
28849
28849
|
|
|
28850
28850
|
|
|
28851
|
+
def _index_in_range(idx, length):
|
|
28852
|
+
"""True for a real 0-based position. Negatives are refused: Python would read
|
|
28853
|
+
`albums[-1]` as the last album and act on something nobody named."""
|
|
28854
|
+
return isinstance(idx, int) and not isinstance(idx, bool) and 0 <= idx < length
|
|
28855
|
+
|
|
28856
|
+
|
|
28857
|
+
def _invalid_indices(indices, length):
|
|
28858
|
+
"""The entries of `indices` that are not a 0-based position below `length`."""
|
|
28859
|
+
return [i for i in indices if not _index_in_range(i, length)]
|
|
28860
|
+
|
|
28861
|
+
|
|
28851
28862
|
# ═══════════════════════════════════════════════════════════════════════════════
|
|
28852
28863
|
# TOOL 23: gallery
|
|
28853
28864
|
# ═══════════════════════════════════════════════════════════════════════════════
|
|
@@ -28881,13 +28892,13 @@ def gallery(action: str, params: Optional[Dict[str, Any]] = None) -> Dict[str, A
|
|
|
28881
28892
|
if action == "get_album_name":
|
|
28882
28893
|
albums = gal.GetGalleryStillAlbums() or []
|
|
28883
28894
|
idx = p.get("album_index", 0)
|
|
28884
|
-
if idx
|
|
28895
|
+
if _index_in_range(idx, len(albums)):
|
|
28885
28896
|
return {"name": gal.GetAlbumName(albums[idx])}
|
|
28886
28897
|
return _err("Album index out of range")
|
|
28887
28898
|
elif action == "set_album_name":
|
|
28888
28899
|
albums = gal.GetGalleryStillAlbums() or []
|
|
28889
28900
|
idx = p.get("album_index", 0)
|
|
28890
|
-
if idx
|
|
28901
|
+
if _index_in_range(idx, len(albums)):
|
|
28891
28902
|
return {"success": bool(gal.SetAlbumName(albums[idx], p["name"]))}
|
|
28892
28903
|
return _err("Album index out of range")
|
|
28893
28904
|
elif action == "get_current_album":
|
|
@@ -28896,7 +28907,7 @@ def gallery(action: str, params: Optional[Dict[str, Any]] = None) -> Dict[str, A
|
|
|
28896
28907
|
elif action == "set_current_album":
|
|
28897
28908
|
albums = gal.GetGalleryStillAlbums() or []
|
|
28898
28909
|
idx = p.get("album_index", 0)
|
|
28899
|
-
if idx
|
|
28910
|
+
if _index_in_range(idx, len(albums)):
|
|
28900
28911
|
return {"success": bool(gal.SetCurrentStillAlbum(albums[idx]))}
|
|
28901
28912
|
return _err("Album index out of range")
|
|
28902
28913
|
elif action == "get_still_albums":
|
|
@@ -28964,7 +28975,7 @@ def gallery_stills(action: str, params: Optional[Dict[str, Any]] = None) -> Dict
|
|
|
28964
28975
|
album_idx = p.get("album_index")
|
|
28965
28976
|
if album_idx is not None:
|
|
28966
28977
|
albums = gal.GetGalleryStillAlbums() or []
|
|
28967
|
-
if album_idx
|
|
28978
|
+
if _index_in_range(album_idx, len(albums)):
|
|
28968
28979
|
album = albums[album_idx]
|
|
28969
28980
|
else:
|
|
28970
28981
|
return _err("Album index out of range")
|
|
@@ -28982,13 +28993,13 @@ def gallery_stills(action: str, params: Optional[Dict[str, Any]] = None) -> Dict
|
|
|
28982
28993
|
elif action == "get_label":
|
|
28983
28994
|
stills = album.GetStills() or []
|
|
28984
28995
|
idx = p.get("still_index", 0)
|
|
28985
|
-
if idx
|
|
28996
|
+
if _index_in_range(idx, len(stills)):
|
|
28986
28997
|
return {"label": album.GetLabel(stills[idx])}
|
|
28987
28998
|
return _err("Still index out of range")
|
|
28988
28999
|
elif action == "set_label":
|
|
28989
29000
|
stills = album.GetStills() or []
|
|
28990
29001
|
idx = p.get("still_index", 0)
|
|
28991
|
-
if idx
|
|
29002
|
+
if _index_in_range(idx, len(stills)):
|
|
28992
29003
|
return {"success": bool(album.SetLabel(stills[idx], p["label"]))}
|
|
28993
29004
|
return _err("Still index out of range")
|
|
28994
29005
|
elif action == "import_stills":
|
|
@@ -29119,8 +29130,15 @@ def gallery_stills(action: str, params: Optional[Dict[str, Any]] = None) -> Dict
|
|
|
29119
29130
|
return {"files": file_details, "format": used_format, "folder": folder_path, "cleaned_up": cleanup}
|
|
29120
29131
|
elif action == "delete_stills":
|
|
29121
29132
|
stills = album.GetStills() or []
|
|
29122
|
-
|
|
29123
|
-
|
|
29133
|
+
still_indices = p["still_indices"]
|
|
29134
|
+
if not isinstance(still_indices, list) or not still_indices:
|
|
29135
|
+
return _err("still_indices must be a non-empty list of 0-based indices")
|
|
29136
|
+
# A negative index is a real Python index (`stills[-1]` is the last still),
|
|
29137
|
+
# and an out-of-range one used to be dropped while the rest were deleted.
|
|
29138
|
+
invalid = _invalid_indices(still_indices, len(stills))
|
|
29139
|
+
if invalid:
|
|
29140
|
+
return _err(f"still_indices out of range for {len(stills)} stills: {invalid}")
|
|
29141
|
+
return {"success": bool(album.DeleteStills([stills[i] for i in still_indices]))}
|
|
29124
29142
|
return _unknown(action, ["get_stills","get_label","set_label","import_stills","export_stills","grab_and_export","delete_stills"])
|
|
29125
29143
|
|
|
29126
29144
|
|
package/src/utils/multicam.py
CHANGED
|
@@ -99,6 +99,55 @@ def timecode_to_frames(timecode: Any, fps: Any, *, drop_frame: Optional[bool] =
|
|
|
99
99
|
return total
|
|
100
100
|
|
|
101
101
|
|
|
102
|
+
def frames_to_timecode(frame: Any, fps: Any, *, drop_frame: bool = False) -> Optional[str]:
|
|
103
|
+
"""Convert a frame count back to HH:MM:SS:FF timecode.
|
|
104
|
+
|
|
105
|
+
The exact inverse of `timecode_to_frames`, and it lives next to it so the
|
|
106
|
+
pair cannot drift apart: a frames->timecode helper written on its own
|
|
107
|
+
reliably forgets that drop-frame dropped frame NUMBERS on the way in, and
|
|
108
|
+
then reports a timecode 3.6 seconds early per hour.
|
|
109
|
+
|
|
110
|
+
`drop_frame` renders drop-frame timecode (semicolon separator) at the two
|
|
111
|
+
nominal rates where it is defined, 30 and 60; at any other rate it is
|
|
112
|
+
ignored, exactly as `timecode_to_frames` ignores a semicolon there.
|
|
113
|
+
"""
|
|
114
|
+
rate = parse_frame_rate(fps)
|
|
115
|
+
if rate is None:
|
|
116
|
+
return None
|
|
117
|
+
try:
|
|
118
|
+
frame = max(0, int(frame))
|
|
119
|
+
except (TypeError, ValueError):
|
|
120
|
+
return None
|
|
121
|
+
nominal = _nominal_timecode_rate(rate)
|
|
122
|
+
if nominal <= 0:
|
|
123
|
+
return None
|
|
124
|
+
|
|
125
|
+
if drop_frame and nominal in (30, 60):
|
|
126
|
+
# Two (30) or four (60) frame numbers are skipped at the top of every
|
|
127
|
+
# minute except every tenth, so a ten-minute block holds one full
|
|
128
|
+
# minute and nine short ones.
|
|
129
|
+
drop = 2 if nominal == 30 else 4
|
|
130
|
+
per_minute = nominal * 60 - drop
|
|
131
|
+
per_ten = per_minute * 10 + drop
|
|
132
|
+
tens, rem = divmod(frame, per_ten)
|
|
133
|
+
if rem < nominal * 60:
|
|
134
|
+
minutes = tens * 10
|
|
135
|
+
frame_in_minute = rem
|
|
136
|
+
else:
|
|
137
|
+
rem -= nominal * 60
|
|
138
|
+
extra_minutes, frame_in_minute = divmod(rem, per_minute)
|
|
139
|
+
minutes = tens * 10 + 1 + extra_minutes
|
|
140
|
+
frame_in_minute += drop
|
|
141
|
+
hours, minutes = divmod(minutes, 60)
|
|
142
|
+
seconds, frames = divmod(frame_in_minute, nominal)
|
|
143
|
+
return f"{hours:02d}:{minutes:02d}:{seconds:02d};{frames:02d}"
|
|
144
|
+
|
|
145
|
+
hours, remainder = divmod(frame, nominal * 3600)
|
|
146
|
+
minutes, remainder = divmod(remainder, nominal * 60)
|
|
147
|
+
seconds, frames = divmod(remainder, nominal)
|
|
148
|
+
return f"{hours:02d}:{minutes:02d}:{seconds:02d}:{frames:02d}"
|
|
149
|
+
|
|
150
|
+
|
|
102
151
|
def _get_clip_property_map(clip: Any) -> Dict[str, Any]:
|
|
103
152
|
try:
|
|
104
153
|
props = clip.GetClipProperty()
|
|
@@ -16,7 +16,7 @@ from array import array
|
|
|
16
16
|
from pathlib import Path
|
|
17
17
|
from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple
|
|
18
18
|
|
|
19
|
-
from src.utils.multicam import timecode_to_frames
|
|
19
|
+
from src.utils.multicam import frames_to_timecode, timecode_to_frames
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
SYNC_EVENT_TYPES = ("two_pop", "slate_clap")
|
|
@@ -237,38 +237,25 @@ def _probe_media(path: str, ffprobe_path: str, timeout: int) -> Dict[str, Any]:
|
|
|
237
237
|
}
|
|
238
238
|
|
|
239
239
|
|
|
240
|
-
def _nominal_timecode_rate(fps: float) -> int:
|
|
241
|
-
if abs(fps - 23.976) < 0.02:
|
|
242
|
-
return 24
|
|
243
|
-
if abs(fps - 29.97) < 0.02:
|
|
244
|
-
return 30
|
|
245
|
-
if abs(fps - 47.952) < 0.05:
|
|
246
|
-
return 48
|
|
247
|
-
if abs(fps - 59.94) < 0.05:
|
|
248
|
-
return 60
|
|
249
|
-
return int(round(fps))
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
def _frames_to_timecode(frame: int, fps: float) -> Optional[str]:
|
|
253
|
-
if fps <= 0:
|
|
254
|
-
return None
|
|
255
|
-
nominal = _nominal_timecode_rate(fps)
|
|
256
|
-
if nominal <= 0:
|
|
257
|
-
return None
|
|
258
|
-
frame = max(0, int(frame))
|
|
259
|
-
hours, remainder = divmod(frame, nominal * 3600)
|
|
260
|
-
minutes, remainder = divmod(remainder, nominal * 60)
|
|
261
|
-
seconds, frames = divmod(remainder, nominal)
|
|
262
|
-
return f"{hours:02d}:{minutes:02d}:{seconds:02d}:{frames:02d}"
|
|
263
|
-
|
|
264
|
-
|
|
265
240
|
def _timecode_for_event(time_seconds: float, fps: Optional[float], start_timecode: Optional[str]) -> Optional[str]:
|
|
241
|
+
"""Timecode of an event `time_seconds` into a clip whose head is `start_timecode`.
|
|
242
|
+
|
|
243
|
+
The start timecode comes from the media's own timecode track, via ffprobe,
|
|
244
|
+
so on an NTSC deliverable it is routinely DROP-FRAME (`HH:MM:SS;FF`).
|
|
245
|
+
`timecode_to_frames` subtracts the dropped frame numbers on the way in, so
|
|
246
|
+
the way back out has to add them again — carry the drop-frame spelling
|
|
247
|
+
through rather than rendering the result as non-drop.
|
|
248
|
+
"""
|
|
266
249
|
if not fps or not start_timecode:
|
|
267
250
|
return None
|
|
268
251
|
start_frame = timecode_to_frames(start_timecode, fps)
|
|
269
252
|
if start_frame is None:
|
|
270
253
|
return None
|
|
271
|
-
return
|
|
254
|
+
return frames_to_timecode(
|
|
255
|
+
start_frame + int(round(time_seconds * fps)),
|
|
256
|
+
fps,
|
|
257
|
+
drop_frame=";" in str(start_timecode),
|
|
258
|
+
)
|
|
272
259
|
|
|
273
260
|
|
|
274
261
|
def _event_marker_color(event_type: str, params: Dict[str, Any]) -> str:
|