vapoursynth-graph 1.0.0__py3-none-win_amd64.whl
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.
- vapoursynth/plugins/graph/graph.avx2.dll +0 -0
- vapoursynth/plugins/graph/graph.dll +0 -0
- vapoursynth/plugins/graph/graph.zn4.dll +0 -0
- vapoursynth/plugins/graph/manifest.vs +2 -0
- vapoursynth_graph-1.0.0.dist-info/METADATA +73 -0
- vapoursynth_graph-1.0.0.dist-info/RECORD +13 -0
- vapoursynth_graph-1.0.0.dist-info/WHEEL +4 -0
- vapoursynth_graph-1.0.0.dist-info/licenses/LICENSE +291 -0
- vsgraph/__init__.py +42 -0
- vsgraph/graph.py +34 -0
- vsgraph/models.py +654 -0
- vsgraph/py.typed +1 -0
- vsgraph/vs.py +77 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: vapoursynth-graph
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: VapourSynth filter graph inspection
|
|
5
|
+
Author-email: Vardë <ichunjo.le.terrible@gmail.com>
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.12
|
|
8
|
+
Requires-Dist: vapoursynth>=79
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
|
|
11
|
+
# vsgraph
|
|
12
|
+
|
|
13
|
+
VapourSynth plugin (Rust) and typed Python API for inspecting filter graphs.
|
|
14
|
+
|
|
15
|
+
Walks the dependency graph of a `VideoNode` or `AudioNode` and returns typed dataclasses describing every node (filter name, filter mode, media info, processing time, creation call stack) and edge (request pattern).
|
|
16
|
+
|
|
17
|
+
Graphs can be exported to Mermaid, Graphviz DOT, ASCII, Cytoscape.js or JSON.
|
|
18
|
+
|
|
19
|
+
## Requirements
|
|
20
|
+
|
|
21
|
+
- Python ≥ 3.12
|
|
22
|
+
- VapourSynth ≥ R79 (API 4.2 or 4.3)
|
|
23
|
+
- The core must be created with `vs.CoreCreationFlags.ENABLE_GRAPH_INSPECTION`
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```powershell
|
|
28
|
+
pip install vsgraph
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The wheel ships the native `graph` plugin, which VapourSynth autoloads.
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
import vapoursynth as vs
|
|
37
|
+
from vsgraph import get_graph
|
|
38
|
+
|
|
39
|
+
core = vs.core
|
|
40
|
+
vs._try_enable_introspection(0)
|
|
41
|
+
|
|
42
|
+
clip = core.std.BlankClip(width=1920, height=1080, format=vs.YUV420P8)
|
|
43
|
+
clip = core.resize.Bicubic(clip, width=1280, height=720)
|
|
44
|
+
|
|
45
|
+
graph = get_graph(clip)
|
|
46
|
+
|
|
47
|
+
print(graph.root.name, graph.root.media_info.fps)
|
|
48
|
+
print(graph.to_ascii())
|
|
49
|
+
|
|
50
|
+
for node in graph.get_dependencies(graph.root):
|
|
51
|
+
print(node.name, node.filter_mode, f"{node.processing_time_ms:.2f} ms")
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Exports
|
|
55
|
+
|
|
56
|
+
| Method | Output |
|
|
57
|
+
| ---------------------- | -------------------------- |
|
|
58
|
+
| `Graph.to_mermaid()` | Mermaid flowchart |
|
|
59
|
+
| `Graph.to_dot()` | Graphviz DOT |
|
|
60
|
+
| `Graph.to_ascii()` | Tree view |
|
|
61
|
+
| `Graph.to_cytoscape()` | Cytoscape.js elements dict |
|
|
62
|
+
| `Graph.to_json()` | JSON string |
|
|
63
|
+
|
|
64
|
+
The raw plugin functions are also available as `core.graph.VideoGraph(clip, pretty)` and `core.graph.AudioGraph(clip, pretty)`, both returning a JSON string.
|
|
65
|
+
|
|
66
|
+
## Development
|
|
67
|
+
|
|
68
|
+
Requires a Rust toolchain and [uv](https://docs.astral.sh/uv/).
|
|
69
|
+
|
|
70
|
+
```powershell
|
|
71
|
+
uv sync --no-editable
|
|
72
|
+
uv run pytest
|
|
73
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
vapoursynth/plugins/graph/graph.avx2.dll,sha256=aVV_u1ltBLIGDtHFtiHJ1SCMmxnPmYiEa2TyEnA4s6E,203776
|
|
2
|
+
vapoursynth/plugins/graph/graph.dll,sha256=3rp5dHn1lIeIogm1Glc7ZWZNJHzaAsGeH-7kmLlvnDo,203776
|
|
3
|
+
vapoursynth/plugins/graph/graph.zn4.dll,sha256=Y021uEzLg92hCvx1pT0oh3PbeVA1sM5dNQYmxAQrx7E,203776
|
|
4
|
+
vapoursynth/plugins/graph/manifest.vs,sha256=-FtpHXQAwrfGg0HFTdIwWkpRUnQpXCfdyLe-MNz5ZmA,34
|
|
5
|
+
vsgraph/__init__.py,sha256=tvqGAC_uUgqNUtsl42xtkgJy79ALKjj_5ViYq1xDbeI,777
|
|
6
|
+
vsgraph/graph.py,sha256=n5FREOfJuv6MmyEZQIrZtJyyTgjieO8WQKb5mTF_srI,1377
|
|
7
|
+
vsgraph/models.py,sha256=yKrclBiPOLo7aFtv8lx--Cgf4gfYkcPcQhziAHSpXYE,23089
|
|
8
|
+
vsgraph/py.typed,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
|
|
9
|
+
vsgraph/vs.py,sha256=6ngzc1RXQr4Pk0_8e-_PXE0-iHZ3n1YImc8_gHFlSXA,2245
|
|
10
|
+
vapoursynth_graph-1.0.0.dist-info/METADATA,sha256=XE4YzBE-tCcfLLAl3AKfli2AI_1FC3TWh5uXjnZkuxI,2127
|
|
11
|
+
vapoursynth_graph-1.0.0.dist-info/WHEEL,sha256=A7YmR1UrJozxyeLCzQFwQUdR7CRUwkFKasEDmnrjVxY,94
|
|
12
|
+
vapoursynth_graph-1.0.0.dist-info/licenses/LICENSE,sha256=5N6rCiaYYl2Nma6bEvgCut4AoICEDLi9BkLKL4_OOGA,14120
|
|
13
|
+
vapoursynth_graph-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
EUROPEAN UNION PUBLIC LICENCE v. 1.2
|
|
2
|
+
EUPL © the European Union 2007, 2016
|
|
3
|
+
|
|
4
|
+
This European Union Public Licence (the ‘EUPL’) applies to the Work (as
|
|
5
|
+
defined below) which is provided under the terms of this Licence. Any use of
|
|
6
|
+
the Work, other than as authorised under this Licence is prohibited (to the
|
|
7
|
+
extent such use is covered by a right of the copyright holder of the Work).
|
|
8
|
+
|
|
9
|
+
The Work is provided under the terms of this Licence when the Licensor (as
|
|
10
|
+
defined below) has placed the following notice immediately following the
|
|
11
|
+
copyright notice for the Work:
|
|
12
|
+
|
|
13
|
+
Licensed under the EUPL
|
|
14
|
+
|
|
15
|
+
or has expressed by any other means his willingness to license under the EUPL.
|
|
16
|
+
|
|
17
|
+
1. Definitions
|
|
18
|
+
|
|
19
|
+
In this Licence, the following terms have the following meaning:
|
|
20
|
+
|
|
21
|
+
- ‘The Licence’: this Licence.
|
|
22
|
+
|
|
23
|
+
- ‘The Original Work’: the work or software distributed or communicated by the
|
|
24
|
+
Licensor under this Licence, available as Source Code and also as Executable
|
|
25
|
+
Code as the case may be.
|
|
26
|
+
|
|
27
|
+
- ‘Derivative Works’: the works or software that could be created by the
|
|
28
|
+
Licensee, based upon the Original Work or modifications thereof. This
|
|
29
|
+
Licence does not define the extent of modification or dependence on the
|
|
30
|
+
Original Work required in order to classify a work as a Derivative Work;
|
|
31
|
+
this extent is determined by copyright law applicable in the country
|
|
32
|
+
mentioned in Article 15.
|
|
33
|
+
|
|
34
|
+
- ‘The Work’: the Original Work or its Derivative Works.
|
|
35
|
+
|
|
36
|
+
- ‘The Source Code’: the human-readable form of the Work which is the most
|
|
37
|
+
convenient for people to study and modify.
|
|
38
|
+
|
|
39
|
+
- ‘The Executable Code’: any code which has generally been compiled and which
|
|
40
|
+
is meant to be interpreted by a computer as a program.
|
|
41
|
+
|
|
42
|
+
- ‘The Licensor’: the natural or legal person that distributes or communicates
|
|
43
|
+
the Work under the Licence.
|
|
44
|
+
|
|
45
|
+
- ‘Contributor(s)’: any natural or legal person who modifies the Work under
|
|
46
|
+
the Licence, or otherwise contributes to the creation of a Derivative Work.
|
|
47
|
+
|
|
48
|
+
- ‘The Licensee’ or ‘You’: any natural or legal person who makes any usage of
|
|
49
|
+
the Work under the terms of the Licence.
|
|
50
|
+
|
|
51
|
+
- ‘Distribution’ or ‘Communication’: any act of selling, giving, lending,
|
|
52
|
+
renting, distributing, communicating, transmitting, or otherwise making
|
|
53
|
+
available, online or offline, copies of the Work or providing access to its
|
|
54
|
+
essential functionalities at the disposal of any other natural or legal
|
|
55
|
+
person.
|
|
56
|
+
|
|
57
|
+
2. Scope of the rights granted by the Licence
|
|
58
|
+
|
|
59
|
+
The Licensor hereby grants You a worldwide, royalty-free, non-exclusive,
|
|
60
|
+
sublicensable licence to do the following, for the duration of copyright
|
|
61
|
+
vested in the Original Work:
|
|
62
|
+
|
|
63
|
+
- use the Work in any circumstance and for all usage,
|
|
64
|
+
- reproduce the Work,
|
|
65
|
+
- modify the Work, and make Derivative Works based upon the Work,
|
|
66
|
+
- communicate to the public, including the right to make available or display
|
|
67
|
+
the Work or copies thereof to the public and perform publicly, as the case
|
|
68
|
+
may be, the Work,
|
|
69
|
+
- distribute the Work or copies thereof,
|
|
70
|
+
- lend and rent the Work or copies thereof,
|
|
71
|
+
- sublicense rights in the Work or copies thereof.
|
|
72
|
+
|
|
73
|
+
Those rights can be exercised on any media, supports and formats, whether now
|
|
74
|
+
known or later invented, as far as the applicable law permits so.
|
|
75
|
+
|
|
76
|
+
In the countries where moral rights apply, the Licensor waives his right to
|
|
77
|
+
exercise his moral right to the extent allowed by law in order to make
|
|
78
|
+
effective the licence of the economic rights here above listed.
|
|
79
|
+
|
|
80
|
+
The Licensor grants to the Licensee royalty-free, non-exclusive usage rights
|
|
81
|
+
to any patents held by the Licensor, to the extent necessary to make use of
|
|
82
|
+
the rights granted on the Work under this Licence.
|
|
83
|
+
|
|
84
|
+
3. Communication of the Source Code
|
|
85
|
+
|
|
86
|
+
The Licensor may provide the Work either in its Source Code form, or as
|
|
87
|
+
Executable Code. If the Work is provided as Executable Code, the Licensor
|
|
88
|
+
provides in addition a machine-readable copy of the Source Code of the Work
|
|
89
|
+
along with each copy of the Work that the Licensor distributes or indicates,
|
|
90
|
+
in a notice following the copyright notice attached to the Work, a repository
|
|
91
|
+
where the Source Code is easily and freely accessible for as long as the
|
|
92
|
+
Licensor continues to distribute or communicate the Work.
|
|
93
|
+
|
|
94
|
+
4. Limitations on copyright
|
|
95
|
+
|
|
96
|
+
Nothing in this Licence is intended to deprive the Licensee of the benefits
|
|
97
|
+
from any exception or limitation to the exclusive rights of the rights owners
|
|
98
|
+
in the Work, of the exhaustion of those rights or of other applicable
|
|
99
|
+
limitations thereto.
|
|
100
|
+
|
|
101
|
+
5. Obligations of the Licensee
|
|
102
|
+
|
|
103
|
+
The grant of the rights mentioned above is subject to some restrictions and
|
|
104
|
+
obligations imposed on the Licensee. Those obligations are the following:
|
|
105
|
+
|
|
106
|
+
Attribution right: The Licensee shall keep intact all copyright, patent or
|
|
107
|
+
trademarks notices and all notices that refer to the Licence and to the
|
|
108
|
+
disclaimer of warranties. The Licensee must include a copy of such notices and
|
|
109
|
+
a copy of the Licence with every copy of the Work he/she distributes or
|
|
110
|
+
communicates. The Licensee must cause any Derivative Work to carry prominent
|
|
111
|
+
notices stating that the Work has been modified and the date of modification.
|
|
112
|
+
|
|
113
|
+
Copyleft clause: If the Licensee distributes or communicates copies of the
|
|
114
|
+
Original Works or Derivative Works, this Distribution or Communication will be
|
|
115
|
+
done under the terms of this Licence or of a later version of this Licence
|
|
116
|
+
unless the Original Work is expressly distributed only under this version of
|
|
117
|
+
the Licence — for example by communicating ‘EUPL v. 1.2 only’. The Licensee
|
|
118
|
+
(becoming Licensor) cannot offer or impose any additional terms or conditions
|
|
119
|
+
on the Work or Derivative Work that alter or restrict the terms of the
|
|
120
|
+
Licence.
|
|
121
|
+
|
|
122
|
+
Compatibility clause: If the Licensee Distributes or Communicates Derivative
|
|
123
|
+
Works or copies thereof based upon both the Work and another work licensed
|
|
124
|
+
under a Compatible Licence, this Distribution or Communication can be done
|
|
125
|
+
under the terms of this Compatible Licence. For the sake of this clause,
|
|
126
|
+
‘Compatible Licence’ refers to the licences listed in the appendix attached to
|
|
127
|
+
this Licence. Should the Licensee's obligations under the Compatible Licence
|
|
128
|
+
conflict with his/her obligations under this Licence, the obligations of the
|
|
129
|
+
Compatible Licence shall prevail.
|
|
130
|
+
|
|
131
|
+
Provision of Source Code: When distributing or communicating copies of the
|
|
132
|
+
Work, the Licensee will provide a machine-readable copy of the Source Code or
|
|
133
|
+
indicate a repository where this Source will be easily and freely available
|
|
134
|
+
for as long as the Licensee continues to distribute or communicate the Work.
|
|
135
|
+
|
|
136
|
+
Legal Protection: This Licence does not grant permission to use the trade
|
|
137
|
+
names, trademarks, service marks, or names of the Licensor, except as required
|
|
138
|
+
for reasonable and customary use in describing the origin of the Work and
|
|
139
|
+
reproducing the content of the copyright notice.
|
|
140
|
+
|
|
141
|
+
6. Chain of Authorship
|
|
142
|
+
|
|
143
|
+
The original Licensor warrants that the copyright in the Original Work granted
|
|
144
|
+
hereunder is owned by him/her or licensed to him/her and that he/she has the
|
|
145
|
+
power and authority to grant the Licence.
|
|
146
|
+
|
|
147
|
+
Each Contributor warrants that the copyright in the modifications he/she
|
|
148
|
+
brings to the Work are owned by him/her or licensed to him/her and that he/she
|
|
149
|
+
has the power and authority to grant the Licence.
|
|
150
|
+
|
|
151
|
+
Each time You accept the Licence, the original Licensor and subsequent
|
|
152
|
+
Contributors grant You a licence to their contributions to the Work, under the
|
|
153
|
+
terms of this Licence.
|
|
154
|
+
|
|
155
|
+
7. Disclaimer of Warranty
|
|
156
|
+
|
|
157
|
+
The Work is a work in progress, which is continuously improved by numerous
|
|
158
|
+
Contributors. It is not a finished work and may therefore contain defects or
|
|
159
|
+
‘bugs’ inherent to this type of development.
|
|
160
|
+
|
|
161
|
+
For the above reason, the Work is provided under the Licence on an ‘as is’
|
|
162
|
+
basis and without warranties of any kind concerning the Work, including
|
|
163
|
+
without limitation merchantability, fitness for a particular purpose, absence
|
|
164
|
+
of defects or errors, accuracy, non-infringement of intellectual property
|
|
165
|
+
rights other than copyright as stated in Article 6 of this Licence.
|
|
166
|
+
|
|
167
|
+
This disclaimer of warranty is an essential part of the Licence and a
|
|
168
|
+
condition for the grant of any rights to the Work.
|
|
169
|
+
|
|
170
|
+
8. Disclaimer of Liability
|
|
171
|
+
|
|
172
|
+
Except in the cases of wilful misconduct or damages directly caused to natural
|
|
173
|
+
persons, the Licensor will in no event be liable for any direct or indirect,
|
|
174
|
+
material or moral, damages of any kind, arising out of the Licence or of the
|
|
175
|
+
use of the Work, including without limitation, damages for loss of goodwill,
|
|
176
|
+
work stoppage, computer failure or malfunction, loss of data or any commercial
|
|
177
|
+
damage, even if the Licensor has been advised of the possibility of such
|
|
178
|
+
damage. However, the Licensor will be liable under statutory product liability
|
|
179
|
+
laws as far such laws apply to the Work.
|
|
180
|
+
|
|
181
|
+
9. Additional agreements
|
|
182
|
+
|
|
183
|
+
While distributing the Work, You may choose to conclude an additional
|
|
184
|
+
agreement, defining obligations or services consistent with this Licence.
|
|
185
|
+
However, if accepting obligations, You may act only on your own behalf and on
|
|
186
|
+
your sole responsibility, not on behalf of the original Licensor or any other
|
|
187
|
+
Contributor, and only if You agree to indemnify, defend, and hold each
|
|
188
|
+
Contributor harmless for any liability incurred by, or claims asserted against
|
|
189
|
+
such Contributor by the fact You have accepted any warranty or additional
|
|
190
|
+
liability.
|
|
191
|
+
|
|
192
|
+
10. Acceptance of the Licence
|
|
193
|
+
|
|
194
|
+
The provisions of this Licence can be accepted by clicking on an icon ‘I
|
|
195
|
+
agree’ placed under the bottom of a window displaying the text of this Licence
|
|
196
|
+
or by affirming consent in any other similar way, in accordance with the rules
|
|
197
|
+
of applicable law. Clicking on that icon indicates your clear and irrevocable
|
|
198
|
+
acceptance of this Licence and all of its terms and conditions.
|
|
199
|
+
|
|
200
|
+
Similarly, you irrevocably accept this Licence and all of its terms and
|
|
201
|
+
conditions by exercising any rights granted to You by Article 2 of this
|
|
202
|
+
Licence, such as the use of the Work, the creation by You of a Derivative Work
|
|
203
|
+
or the Distribution or Communication by You of the Work or copies thereof.
|
|
204
|
+
|
|
205
|
+
11. Information to the public
|
|
206
|
+
|
|
207
|
+
In case of any Distribution or Communication of the Work by means of
|
|
208
|
+
electronic communication by You (for example, by offering to download the Work
|
|
209
|
+
from a remote location) the distribution channel or media (for example, a
|
|
210
|
+
website) must at least provide to the public the information requested by the
|
|
211
|
+
applicable law regarding the Licensor, the Licence and the way it may be
|
|
212
|
+
accessible, concluded, stored and reproduced by the Licensee.
|
|
213
|
+
|
|
214
|
+
12. Termination of the Licence
|
|
215
|
+
|
|
216
|
+
The Licence and the rights granted hereunder will terminate automatically upon
|
|
217
|
+
any breach by the Licensee of the terms of the Licence.
|
|
218
|
+
|
|
219
|
+
Such a termination will not terminate the licences of any person who has
|
|
220
|
+
received the Work from the Licensee under the Licence, provided such persons
|
|
221
|
+
remain in full compliance with the Licence.
|
|
222
|
+
|
|
223
|
+
13. Miscellaneous
|
|
224
|
+
|
|
225
|
+
Without prejudice of Article 9 above, the Licence represents the complete
|
|
226
|
+
agreement between the Parties as to the Work.
|
|
227
|
+
|
|
228
|
+
If any provision of the Licence is invalid or unenforceable under applicable
|
|
229
|
+
law, this will not affect the validity or enforceability of the Licence as a
|
|
230
|
+
whole. Such provision will be construed or reformed so as necessary to make it
|
|
231
|
+
valid and enforceable.
|
|
232
|
+
|
|
233
|
+
The European Commission may publish other linguistic versions or new versions
|
|
234
|
+
of this Licence or updated versions of the Appendix, so far this is required
|
|
235
|
+
and reasonable, without reducing the scope of the rights granted by the
|
|
236
|
+
Licence. New versions of the Licence will be published with a unique version
|
|
237
|
+
number.
|
|
238
|
+
|
|
239
|
+
All linguistic versions of this Licence, approved by the European Commission,
|
|
240
|
+
have identical value. Parties can take advantage of the linguistic version of
|
|
241
|
+
their choice.
|
|
242
|
+
|
|
243
|
+
14. Jurisdiction
|
|
244
|
+
|
|
245
|
+
Without prejudice to specific agreement between parties,
|
|
246
|
+
|
|
247
|
+
- any litigation resulting from the interpretation of this License, arising
|
|
248
|
+
between the European Union institutions, bodies, offices or agencies, as a
|
|
249
|
+
Licensor, and any Licensee, will be subject to the jurisdiction of the Court
|
|
250
|
+
of Justice of the European Union, as laid down in article 272 of the Treaty
|
|
251
|
+
on the Functioning of the European Union,
|
|
252
|
+
|
|
253
|
+
- any litigation arising between other parties and resulting from the
|
|
254
|
+
interpretation of this License, will be subject to the exclusive
|
|
255
|
+
jurisdiction of the competent court where the Licensor resides or conducts
|
|
256
|
+
its primary business.
|
|
257
|
+
|
|
258
|
+
15. Applicable Law
|
|
259
|
+
|
|
260
|
+
Without prejudice to specific agreement between parties,
|
|
261
|
+
|
|
262
|
+
- this Licence shall be governed by the law of the European Union Member State
|
|
263
|
+
where the Licensor has his seat, resides or has his registered office,
|
|
264
|
+
|
|
265
|
+
- this licence shall be governed by Belgian law if the Licensor has no seat,
|
|
266
|
+
residence or registered office inside a European Union Member State.
|
|
267
|
+
|
|
268
|
+
Appendix
|
|
269
|
+
|
|
270
|
+
‘Compatible Licences’ according to Article 5 EUPL are:
|
|
271
|
+
|
|
272
|
+
- GNU General Public License (GPL) v. 2, v. 3
|
|
273
|
+
- GNU Affero General Public License (AGPL) v. 3
|
|
274
|
+
- Open Software License (OSL) v. 2.1, v. 3.0
|
|
275
|
+
- Eclipse Public License (EPL) v. 1.0
|
|
276
|
+
- CeCILL v. 2.0, v. 2.1
|
|
277
|
+
- Mozilla Public Licence (MPL) v. 2
|
|
278
|
+
- GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3
|
|
279
|
+
- Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for
|
|
280
|
+
works other than software
|
|
281
|
+
- European Union Public Licence (EUPL) v. 1.1, v. 1.2
|
|
282
|
+
- Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or Strong
|
|
283
|
+
Reciprocity (LiLiQ-R+).
|
|
284
|
+
|
|
285
|
+
The European Commission may update this Appendix to later versions of the
|
|
286
|
+
above licences without producing a new version of the EUPL, as long as they
|
|
287
|
+
provide the rights granted in Article 2 of this Licence and protect the
|
|
288
|
+
covered Source Code from exclusive appropriation.
|
|
289
|
+
|
|
290
|
+
All other changes or additions to this Appendix require the production of a
|
|
291
|
+
new EUPL version.
|
vsgraph/__init__.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Typed dataclasses and utilities for VapourSynth graph inspection."""
|
|
2
|
+
|
|
3
|
+
from .graph import get_graph
|
|
4
|
+
from .models import (
|
|
5
|
+
AudioFrameInfo,
|
|
6
|
+
AudioMediaInfo,
|
|
7
|
+
AudioNodeRef,
|
|
8
|
+
CallFrame,
|
|
9
|
+
Edge,
|
|
10
|
+
FrameInfo,
|
|
11
|
+
FuncRef,
|
|
12
|
+
Graph,
|
|
13
|
+
MediaInfo,
|
|
14
|
+
Node,
|
|
15
|
+
NodeKey,
|
|
16
|
+
NodeRef,
|
|
17
|
+
VideoFrameInfo,
|
|
18
|
+
VideoMediaInfo,
|
|
19
|
+
VideoNodeRef,
|
|
20
|
+
)
|
|
21
|
+
from .vs import AudioFormat, RequestPattern
|
|
22
|
+
|
|
23
|
+
__all__ = [
|
|
24
|
+
"AudioFormat",
|
|
25
|
+
"AudioFrameInfo",
|
|
26
|
+
"AudioMediaInfo",
|
|
27
|
+
"AudioNodeRef",
|
|
28
|
+
"CallFrame",
|
|
29
|
+
"Edge",
|
|
30
|
+
"FrameInfo",
|
|
31
|
+
"FuncRef",
|
|
32
|
+
"Graph",
|
|
33
|
+
"MediaInfo",
|
|
34
|
+
"Node",
|
|
35
|
+
"NodeKey",
|
|
36
|
+
"NodeRef",
|
|
37
|
+
"RequestPattern",
|
|
38
|
+
"VideoFrameInfo",
|
|
39
|
+
"VideoMediaInfo",
|
|
40
|
+
"VideoNodeRef",
|
|
41
|
+
"get_graph",
|
|
42
|
+
]
|
vsgraph/graph.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from typing import Any, assert_never, overload
|
|
2
|
+
|
|
3
|
+
import vapoursynth as vs
|
|
4
|
+
|
|
5
|
+
from .models import AudioMediaInfo, Graph, VideoMediaInfo
|
|
6
|
+
|
|
7
|
+
type MediaNode = vs.VideoNode | vs.AudioNode
|
|
8
|
+
|
|
9
|
+
core = vs.core
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@overload
|
|
13
|
+
def get_graph(clip: vs.VideoNode, /, *, pretty: bool = False, reset_timing: bool = False) -> Graph[VideoMediaInfo]: ...
|
|
14
|
+
@overload
|
|
15
|
+
def get_graph(clip: vs.AudioNode, /, *, pretty: bool = False, reset_timing: bool = False) -> Graph[AudioMediaInfo]: ...
|
|
16
|
+
@overload
|
|
17
|
+
def get_graph(clip: MediaNode, /, *, pretty: bool = False, reset_timing: bool = False) -> Graph[Any]: ...
|
|
18
|
+
def get_graph(clip: MediaNode, /, *, pretty: bool = False, reset_timing: bool = False) -> Graph[Any]:
|
|
19
|
+
"""
|
|
20
|
+
Inspect the dependency graph of a VideoNode or AudioNode and return a typed Graph.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
clip: The VapourSynth VideoNode or AudioNode to inspect.
|
|
24
|
+
pretty: Whether the underlying JSON should be formatted with indentation.
|
|
25
|
+
reset_timing: Whether to reset the node and core freed node processing timers after inspection.
|
|
26
|
+
"""
|
|
27
|
+
match clip:
|
|
28
|
+
case vs.VideoNode():
|
|
29
|
+
raw_json = core.graph.VideoGraph(clip, pretty, reset_timing)
|
|
30
|
+
case vs.AudioNode():
|
|
31
|
+
raw_json = core.graph.AudioGraph(clip, pretty, reset_timing)
|
|
32
|
+
case _:
|
|
33
|
+
assert_never(clip)
|
|
34
|
+
return Graph.from_json(raw_json)
|
vsgraph/models.py
ADDED
|
@@ -0,0 +1,654 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from abc import ABC, abstractmethod
|
|
5
|
+
from collections.abc import Collection, Iterator
|
|
6
|
+
from dataclasses import dataclass, field, fields
|
|
7
|
+
from fractions import Fraction
|
|
8
|
+
from functools import cache
|
|
9
|
+
from inspect import Signature
|
|
10
|
+
from operator import attrgetter
|
|
11
|
+
from typing import Any, Literal, Self, override
|
|
12
|
+
|
|
13
|
+
import vapoursynth as vs
|
|
14
|
+
|
|
15
|
+
from .vs import AudioFormat, RequestPattern
|
|
16
|
+
|
|
17
|
+
type NodeKey = vs.RawNode | Node[Any] | NodeRef | str
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(slots=True, kw_only=True)
|
|
21
|
+
class MediaInfo(ABC):
|
|
22
|
+
@property
|
|
23
|
+
@abstractmethod
|
|
24
|
+
def format(self) -> vs.VideoFormat | AudioFormat: ...
|
|
25
|
+
|
|
26
|
+
def to_dict(self) -> dict[str, Any]:
|
|
27
|
+
"""Convert to a dictionary."""
|
|
28
|
+
data = dict[str, Any]()
|
|
29
|
+
|
|
30
|
+
for dfield in fields(self):
|
|
31
|
+
attr = getattr(self, dfield.name)
|
|
32
|
+
if dfield.name != "gpu_resident" or attr is not None:
|
|
33
|
+
data[dfield.name] = attr
|
|
34
|
+
|
|
35
|
+
data["format"] = self.format._as_dict()
|
|
36
|
+
|
|
37
|
+
return data
|
|
38
|
+
|
|
39
|
+
@classmethod
|
|
40
|
+
@abstractmethod
|
|
41
|
+
def from_dict(cls, data: dict[str, Any]) -> Self: ...
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@dataclass(slots=True, kw_only=True)
|
|
45
|
+
class VideoMediaInfo(MediaInfo):
|
|
46
|
+
"""Media information for video nodes."""
|
|
47
|
+
|
|
48
|
+
format_id: vs.PresetVideoFormat
|
|
49
|
+
width: int
|
|
50
|
+
height: int
|
|
51
|
+
fps_num: int
|
|
52
|
+
fps_den: int
|
|
53
|
+
num_frames: int
|
|
54
|
+
gpu_resident: bool | None = None
|
|
55
|
+
type: Literal["vnode"] = "vnode"
|
|
56
|
+
|
|
57
|
+
@property
|
|
58
|
+
def fps(self) -> Fraction:
|
|
59
|
+
"""Frame rate as an exact Fraction."""
|
|
60
|
+
return Fraction(self.fps_num, self.fps_den) if self.fps_den != 0 else Fraction(0, 1)
|
|
61
|
+
|
|
62
|
+
@property
|
|
63
|
+
@override
|
|
64
|
+
def format(self) -> vs.VideoFormat:
|
|
65
|
+
"""The resolved VideoFormat from the core."""
|
|
66
|
+
return vs.core.get_video_format(self.format_id)
|
|
67
|
+
|
|
68
|
+
@override
|
|
69
|
+
def to_dict(self) -> dict[str, Any]:
|
|
70
|
+
data = super().to_dict()
|
|
71
|
+
data["format"] = self.format._as_dict()
|
|
72
|
+
return data
|
|
73
|
+
|
|
74
|
+
@classmethod
|
|
75
|
+
@override
|
|
76
|
+
def from_dict(cls, data: dict[str, Any]) -> Self:
|
|
77
|
+
"""Construct from a dictionary."""
|
|
78
|
+
return cls(
|
|
79
|
+
format_id=vs.PresetVideoFormat(data["format_id"]),
|
|
80
|
+
width=int(data["width"]),
|
|
81
|
+
height=int(data["height"]),
|
|
82
|
+
fps_num=int(data["fps_num"]),
|
|
83
|
+
fps_den=int(data["fps_den"]),
|
|
84
|
+
num_frames=int(data["num_frames"]),
|
|
85
|
+
gpu_resident=data.get("gpu_resident"),
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@dataclass(slots=True, kw_only=True)
|
|
90
|
+
class AudioMediaInfo(MediaInfo):
|
|
91
|
+
"""Media information for audio nodes."""
|
|
92
|
+
|
|
93
|
+
format_id: int
|
|
94
|
+
sample_rate: int
|
|
95
|
+
num_samples: int
|
|
96
|
+
num_frames: int
|
|
97
|
+
gpu_resident: bool | None = None
|
|
98
|
+
type: Literal["anode"] = "anode"
|
|
99
|
+
|
|
100
|
+
@property
|
|
101
|
+
@override
|
|
102
|
+
def format(self) -> AudioFormat:
|
|
103
|
+
"""The resolved AudioFormat."""
|
|
104
|
+
return AudioFormat.from_id(self.format_id)
|
|
105
|
+
|
|
106
|
+
@override
|
|
107
|
+
def to_dict(self) -> dict[str, Any]:
|
|
108
|
+
data = super().to_dict()
|
|
109
|
+
data["format"] = self.format._as_dict()
|
|
110
|
+
return data
|
|
111
|
+
|
|
112
|
+
@classmethod
|
|
113
|
+
@override
|
|
114
|
+
def from_dict(cls, data: dict[str, Any]) -> Self:
|
|
115
|
+
"""Construct from a dictionary."""
|
|
116
|
+
return cls(
|
|
117
|
+
format_id=int(data["format_id"]),
|
|
118
|
+
sample_rate=int(data["sample_rate"]),
|
|
119
|
+
num_samples=int(data["num_samples"]),
|
|
120
|
+
num_frames=int(data["num_frames"]),
|
|
121
|
+
gpu_resident=data.get("gpu_resident"),
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
@dataclass(slots=True, kw_only=True)
|
|
126
|
+
class FrameInfo(ABC):
|
|
127
|
+
props: dict[str, Any] = field(default_factory=dict)
|
|
128
|
+
|
|
129
|
+
def to_dict(self) -> dict[str, Any]:
|
|
130
|
+
"""Convert to a dictionary."""
|
|
131
|
+
data = dict[str, Any]()
|
|
132
|
+
|
|
133
|
+
for dfield in fields(self):
|
|
134
|
+
attr = getattr(self, dfield.name)
|
|
135
|
+
if dfield.name != "gpu_resident" or attr is not None:
|
|
136
|
+
data[dfield.name] = attr
|
|
137
|
+
|
|
138
|
+
return data
|
|
139
|
+
|
|
140
|
+
@classmethod
|
|
141
|
+
@abstractmethod
|
|
142
|
+
def from_dict(cls, data: dict[str, Any]) -> Self: ...
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
@dataclass(slots=True, kw_only=True)
|
|
146
|
+
class VideoFrameInfo(FrameInfo):
|
|
147
|
+
"""Video frame argument metadata."""
|
|
148
|
+
|
|
149
|
+
id: str
|
|
150
|
+
format_id: vs.PresetVideoFormat
|
|
151
|
+
width: int
|
|
152
|
+
height: int
|
|
153
|
+
gpu_resident: bool | None = None
|
|
154
|
+
type: Literal["vframe"] = "vframe"
|
|
155
|
+
|
|
156
|
+
@property
|
|
157
|
+
def format(self) -> vs.VideoFormat:
|
|
158
|
+
"""The resolved VideoFormat from the core."""
|
|
159
|
+
return vs.core.get_video_format(self.format_id)
|
|
160
|
+
|
|
161
|
+
@classmethod
|
|
162
|
+
@override
|
|
163
|
+
def from_dict(cls, data: dict[str, Any]) -> Self:
|
|
164
|
+
"""Construct from a dictionary."""
|
|
165
|
+
return cls(
|
|
166
|
+
id=str(data["id"]),
|
|
167
|
+
format_id=vs.PresetVideoFormat(data["format_id"]),
|
|
168
|
+
width=int(data["width"]),
|
|
169
|
+
height=int(data["height"]),
|
|
170
|
+
gpu_resident=data.get("gpu_resident"),
|
|
171
|
+
props=dict(data["props"]),
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
@dataclass(slots=True, kw_only=True)
|
|
176
|
+
class AudioFrameInfo(FrameInfo):
|
|
177
|
+
"""Audio frame argument metadata."""
|
|
178
|
+
|
|
179
|
+
id: str
|
|
180
|
+
format_id: int
|
|
181
|
+
num_samples: int
|
|
182
|
+
gpu_resident: bool | None = None
|
|
183
|
+
type: Literal["aframe"] = "aframe"
|
|
184
|
+
|
|
185
|
+
@property
|
|
186
|
+
def format(self) -> AudioFormat:
|
|
187
|
+
"""The resolved AudioFormat."""
|
|
188
|
+
return AudioFormat.from_id(self.format_id)
|
|
189
|
+
|
|
190
|
+
@classmethod
|
|
191
|
+
@override
|
|
192
|
+
def from_dict(cls, data: dict[str, Any]) -> Self:
|
|
193
|
+
"""Construct from a dictionary."""
|
|
194
|
+
return cls(
|
|
195
|
+
id=str(data["id"]),
|
|
196
|
+
format_id=int(data["format_id"]),
|
|
197
|
+
num_samples=int(data["num_samples"]),
|
|
198
|
+
gpu_resident=data.get("gpu_resident"),
|
|
199
|
+
props=dict(data["props"]),
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
@dataclass(slots=True, kw_only=True)
|
|
204
|
+
class NodeRef(ABC):
|
|
205
|
+
"""Reference to a node in a call frame argument."""
|
|
206
|
+
|
|
207
|
+
id: str
|
|
208
|
+
|
|
209
|
+
def to_dict(self) -> dict[str, Any]:
|
|
210
|
+
"""Convert to a dictionary."""
|
|
211
|
+
return {dfield.name: getattr(self, dfield.name) for dfield in fields(self)}
|
|
212
|
+
|
|
213
|
+
@classmethod
|
|
214
|
+
@abstractmethod
|
|
215
|
+
def from_dict(cls, data: dict[str, Any]) -> Self: ...
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
@dataclass(slots=True, kw_only=True)
|
|
219
|
+
class VideoNodeRef(NodeRef):
|
|
220
|
+
"""Video node argument reference."""
|
|
221
|
+
|
|
222
|
+
type: Literal["vnode"] = "vnode"
|
|
223
|
+
|
|
224
|
+
@classmethod
|
|
225
|
+
@override
|
|
226
|
+
def from_dict(cls, data: dict[str, Any]) -> Self:
|
|
227
|
+
"""Construct from a dictionary."""
|
|
228
|
+
return cls(id=str(data["id"]))
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
@dataclass(slots=True, kw_only=True)
|
|
232
|
+
class AudioNodeRef(NodeRef):
|
|
233
|
+
"""Audio node argument reference."""
|
|
234
|
+
|
|
235
|
+
type: Literal["anode"] = "anode"
|
|
236
|
+
|
|
237
|
+
@classmethod
|
|
238
|
+
@override
|
|
239
|
+
def from_dict(cls, data: dict[str, Any]) -> Self:
|
|
240
|
+
"""Construct from a dictionary."""
|
|
241
|
+
return cls(id=str(data["id"]))
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
@dataclass(slots=True, kw_only=True)
|
|
245
|
+
class FuncRef:
|
|
246
|
+
"""Function argument reference."""
|
|
247
|
+
|
|
248
|
+
id: str
|
|
249
|
+
type: Literal["func"] = "func"
|
|
250
|
+
|
|
251
|
+
def to_dict(self) -> dict[str, Any]:
|
|
252
|
+
"""Convert to a dictionary."""
|
|
253
|
+
return {"id": self.id, "type": self.type}
|
|
254
|
+
|
|
255
|
+
@classmethod
|
|
256
|
+
def from_dict(cls, data: dict[str, Any]) -> Self:
|
|
257
|
+
"""Construct from a dictionary."""
|
|
258
|
+
return cls(id=str(data["id"]))
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
@dataclass(slots=True, kw_only=True)
|
|
262
|
+
class CallFrame:
|
|
263
|
+
"""Represents a call frame in the node creation stack."""
|
|
264
|
+
|
|
265
|
+
level: int
|
|
266
|
+
id: str
|
|
267
|
+
plugin_id: str
|
|
268
|
+
plugin_ns: str
|
|
269
|
+
function: str
|
|
270
|
+
arguments: dict[str, Any] = field(default_factory=dict)
|
|
271
|
+
|
|
272
|
+
def to_dict(self) -> dict[str, Any]:
|
|
273
|
+
"""Convert to a dictionary."""
|
|
274
|
+
|
|
275
|
+
def serialize_arg(val: Any) -> Any:
|
|
276
|
+
if isinstance(val, (FrameInfo, NodeRef, FuncRef)):
|
|
277
|
+
return val.to_dict()
|
|
278
|
+
if isinstance(val, list):
|
|
279
|
+
return [serialize_arg(item) for item in val]
|
|
280
|
+
return val
|
|
281
|
+
|
|
282
|
+
param_names = _get_param_names(f"{self.plugin_ns}.{self.function}")
|
|
283
|
+
arguments = {k: serialize_arg(self.arguments[k]) for k in param_names if k in self.arguments}
|
|
284
|
+
|
|
285
|
+
return {
|
|
286
|
+
"level": self.level,
|
|
287
|
+
"id": self.id,
|
|
288
|
+
"plugin_id": self.plugin_id,
|
|
289
|
+
"plugin_ns": self.plugin_ns,
|
|
290
|
+
"function": self.function,
|
|
291
|
+
"arguments": arguments,
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
@classmethod
|
|
295
|
+
def from_dict(cls, data: dict[str, Any]) -> Self:
|
|
296
|
+
"""Construct from a dictionary."""
|
|
297
|
+
|
|
298
|
+
def parse_args(val: Any) -> Any:
|
|
299
|
+
if isinstance(val, dict):
|
|
300
|
+
match val.get("type"):
|
|
301
|
+
case "vnode":
|
|
302
|
+
return VideoNodeRef.from_dict(val)
|
|
303
|
+
case "anode":
|
|
304
|
+
return AudioNodeRef.from_dict(val)
|
|
305
|
+
case "vframe":
|
|
306
|
+
return VideoFrameInfo.from_dict(val)
|
|
307
|
+
case "aframe":
|
|
308
|
+
return AudioFrameInfo.from_dict(val)
|
|
309
|
+
case "func":
|
|
310
|
+
return FuncRef.from_dict(val)
|
|
311
|
+
case _:
|
|
312
|
+
return val
|
|
313
|
+
return [parse_args(item) for item in val] if isinstance(val, list) else val
|
|
314
|
+
|
|
315
|
+
return cls(
|
|
316
|
+
level=int(data["level"]),
|
|
317
|
+
id=str(data["id"]),
|
|
318
|
+
plugin_id=str(data["plugin_id"]),
|
|
319
|
+
plugin_ns=str(data["plugin_ns"]),
|
|
320
|
+
function=str(data["function"]),
|
|
321
|
+
arguments={k: parse_args(v) for k, v in data["arguments"].items()},
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
@dataclass(slots=True, kw_only=True)
|
|
326
|
+
class Edge:
|
|
327
|
+
"""Represents a dependency edge between nodes in the graph."""
|
|
328
|
+
|
|
329
|
+
source: str
|
|
330
|
+
target: str
|
|
331
|
+
pattern: RequestPattern
|
|
332
|
+
index: int
|
|
333
|
+
|
|
334
|
+
def to_dict(self) -> dict[str, Any]:
|
|
335
|
+
"""Convert to a dictionary."""
|
|
336
|
+
return {"source": self.source, "target": self.target, "pattern": self.pattern, "index": self.index}
|
|
337
|
+
|
|
338
|
+
@classmethod
|
|
339
|
+
def from_dict(cls, data: dict[str, Any]) -> Self:
|
|
340
|
+
"""Construct from a dictionary."""
|
|
341
|
+
return cls(
|
|
342
|
+
source=str(data["source"]),
|
|
343
|
+
target=str(data["target"]),
|
|
344
|
+
pattern=RequestPattern(data["pattern"]),
|
|
345
|
+
index=int(data["index"]),
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
@dataclass(slots=True, kw_only=True)
|
|
350
|
+
class Node[MediaInfoT: MediaInfo]:
|
|
351
|
+
"""Represents a filter node in the graph."""
|
|
352
|
+
|
|
353
|
+
id: str
|
|
354
|
+
name: str
|
|
355
|
+
filter_mode: vs.FilterMode
|
|
356
|
+
processing_time_ns: int
|
|
357
|
+
media_info: MediaInfoT
|
|
358
|
+
call_stack: list[CallFrame] = field(default_factory=list)
|
|
359
|
+
|
|
360
|
+
@property
|
|
361
|
+
def processing_time_ms(self) -> float:
|
|
362
|
+
"""Processing time in milliseconds."""
|
|
363
|
+
return self.processing_time_ns / 1_000_000.0
|
|
364
|
+
|
|
365
|
+
def to_dict(self) -> dict[str, Any]:
|
|
366
|
+
"""Convert to a dictionary."""
|
|
367
|
+
data: dict[str, Any] = {
|
|
368
|
+
"id": self.id,
|
|
369
|
+
"name": self.name,
|
|
370
|
+
"filter_mode": self.filter_mode,
|
|
371
|
+
"processing_time_ns": self.processing_time_ns,
|
|
372
|
+
"media_info": self.media_info.to_dict(),
|
|
373
|
+
"call_stack": [frame.to_dict() for frame in self.call_stack],
|
|
374
|
+
}
|
|
375
|
+
return data
|
|
376
|
+
|
|
377
|
+
@classmethod
|
|
378
|
+
def from_dict(cls, data: dict[str, Any]) -> Self:
|
|
379
|
+
"""Construct from a dictionary."""
|
|
380
|
+
match (raw_info := data["media_info"])["type"]:
|
|
381
|
+
case "vnode":
|
|
382
|
+
media_info = VideoMediaInfo.from_dict(raw_info)
|
|
383
|
+
case "anode":
|
|
384
|
+
media_info = AudioMediaInfo.from_dict(raw_info)
|
|
385
|
+
case other:
|
|
386
|
+
raise ValueError(f"Unknown media_info type: {other!r}")
|
|
387
|
+
|
|
388
|
+
call_stack = [CallFrame.from_dict(frame) for frame in data["call_stack"]]
|
|
389
|
+
|
|
390
|
+
return cls(
|
|
391
|
+
id=str(data["id"]),
|
|
392
|
+
name=str(data["name"]),
|
|
393
|
+
filter_mode=vs.FilterMode(data["filter_mode"]),
|
|
394
|
+
processing_time_ns=int(data["processing_time_ns"]),
|
|
395
|
+
media_info=media_info,
|
|
396
|
+
call_stack=call_stack,
|
|
397
|
+
)
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
@dataclass(slots=True, kw_only=True)
|
|
401
|
+
class Graph[MediaInfoT: (VideoMediaInfo, AudioMediaInfo)](Collection[Node[MediaInfoT]]):
|
|
402
|
+
"""Full VapourSynth dependency graph output."""
|
|
403
|
+
|
|
404
|
+
root_id: str
|
|
405
|
+
nodes: list[Node[MediaInfoT]] = field(default_factory=list)
|
|
406
|
+
edges: list[Edge] = field(default_factory=list)
|
|
407
|
+
|
|
408
|
+
@override
|
|
409
|
+
def __contains__(self, node_or_id: object) -> bool:
|
|
410
|
+
return (
|
|
411
|
+
to_node_id(node_or_id) in self.nodes_by_id
|
|
412
|
+
if isinstance(node_or_id, (vs.RawNode, Node, NodeRef, str))
|
|
413
|
+
else False
|
|
414
|
+
)
|
|
415
|
+
|
|
416
|
+
@override
|
|
417
|
+
def __iter__(self) -> Iterator[Node[MediaInfoT]]:
|
|
418
|
+
return iter(self.nodes)
|
|
419
|
+
|
|
420
|
+
@override
|
|
421
|
+
def __len__(self) -> int:
|
|
422
|
+
return len(self.nodes)
|
|
423
|
+
|
|
424
|
+
def __getitem__(self, node_or_id: NodeKey) -> Node[MediaInfoT]:
|
|
425
|
+
if node := self.nodes_by_id.get(to_node_id(node_or_id)):
|
|
426
|
+
return node
|
|
427
|
+
raise KeyError(node_or_id)
|
|
428
|
+
|
|
429
|
+
@property
|
|
430
|
+
def root(self) -> Node[MediaInfoT]:
|
|
431
|
+
"""The root node where inspection started."""
|
|
432
|
+
for node in self.nodes:
|
|
433
|
+
if node.id == self.root_id:
|
|
434
|
+
return node
|
|
435
|
+
raise KeyError(f"Root node '{self.root_id}' not found in graph nodes")
|
|
436
|
+
|
|
437
|
+
@property
|
|
438
|
+
def nodes_by_id(self) -> dict[str, Node[MediaInfoT]]:
|
|
439
|
+
"""Dictionary of nodes keyed by their ID."""
|
|
440
|
+
return {node.id: node for node in self.nodes}
|
|
441
|
+
|
|
442
|
+
def get_incoming_edges(self, node_or_id: NodeKey) -> list[Edge]:
|
|
443
|
+
"""Return all edges where this node is the target (inputs to this node)."""
|
|
444
|
+
nid = to_node_id(node_or_id)
|
|
445
|
+
return [edge for edge in self.edges if edge.target == nid]
|
|
446
|
+
|
|
447
|
+
def get_outgoing_edges(self, node_or_id: NodeKey) -> list[Edge]:
|
|
448
|
+
"""Return all edges where this node is the source (outputs from this node)."""
|
|
449
|
+
nid = to_node_id(node_or_id)
|
|
450
|
+
return [edge for edge in self.edges if edge.source == nid]
|
|
451
|
+
|
|
452
|
+
def get_dependencies(self, node_or_id: NodeKey) -> list[Node[MediaInfoT]]:
|
|
453
|
+
"""Return upstream nodes that this node directly depends on."""
|
|
454
|
+
node_map = self.nodes_by_id
|
|
455
|
+
incoming = self.get_incoming_edges(node_or_id)
|
|
456
|
+
return [node_map[e.source] for e in incoming if e.source in node_map]
|
|
457
|
+
|
|
458
|
+
def get_dependents(self, node_or_id: NodeKey) -> list[Node[MediaInfoT]]:
|
|
459
|
+
"""Return downstream nodes that directly depend on this node."""
|
|
460
|
+
node_map = self.nodes_by_id
|
|
461
|
+
outgoing = self.get_outgoing_edges(node_or_id)
|
|
462
|
+
return [node_map[e.target] for e in outgoing if e.target in node_map]
|
|
463
|
+
|
|
464
|
+
def to_dict(self) -> dict[str, Any]:
|
|
465
|
+
"""Convert graph to a dictionary matching the JSON format."""
|
|
466
|
+
return {
|
|
467
|
+
"root_id": self.root_id,
|
|
468
|
+
"nodes": [node.to_dict() for node in self.nodes],
|
|
469
|
+
"edges": [edge.to_dict() for edge in self.edges],
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
def to_json(self, *, indent: int | None = None, **kwargs: Any) -> str:
|
|
473
|
+
"""Serialize graph to a JSON string."""
|
|
474
|
+
return json.dumps(self.to_dict(), indent=indent, **kwargs)
|
|
475
|
+
|
|
476
|
+
def to_mermaid(self) -> str:
|
|
477
|
+
"""Generate a Mermaid flowchart diagram of the graph."""
|
|
478
|
+
lines = ["flowchart TD"]
|
|
479
|
+
for node in self.nodes:
|
|
480
|
+
lbl = f"{node.name} ({node.id})"
|
|
481
|
+
lines.append(f' {node.id}["{lbl}"]')
|
|
482
|
+
for edge in self.edges:
|
|
483
|
+
pattern_label = edge.pattern.name if edge.pattern != RequestPattern.GENERAL else ""
|
|
484
|
+
if pattern_label:
|
|
485
|
+
lines.append(f" {edge.source} -->|{pattern_label}| {edge.target}")
|
|
486
|
+
else:
|
|
487
|
+
lines.append(f" {edge.source} --> {edge.target}")
|
|
488
|
+
return "\n".join(lines)
|
|
489
|
+
|
|
490
|
+
def to_dot(self, *, direction: str = "TB", detailed: bool = True, fontname: str | None = None) -> str:
|
|
491
|
+
"""
|
|
492
|
+
Generate a Graphviz DOT representation of the graph.
|
|
493
|
+
|
|
494
|
+
Args:
|
|
495
|
+
direction: Layout direction ('TB', 'LR', 'BT', 'RL'). Default is 'TB'.
|
|
496
|
+
detailed: Whether to render HTML-like table record labels with media info and profiling.
|
|
497
|
+
fontname: Font name for Graphviz nodes and edges (e.g. 'Helvetica'). If None, uses Graphviz defaults.
|
|
498
|
+
"""
|
|
499
|
+
font_attr = f'fontname="{fontname}", ' if fontname else ""
|
|
500
|
+
lines = [
|
|
501
|
+
"digraph VSDependencyGraph {",
|
|
502
|
+
f' rankdir="{direction}";',
|
|
503
|
+
f' node [shape=box, style="filled,rounded", {font_attr}fillcolor="#f8f9fa", color="#343a40"];',
|
|
504
|
+
f' edge [{font_attr}color="#495057"];',
|
|
505
|
+
]
|
|
506
|
+
|
|
507
|
+
for node in self.nodes:
|
|
508
|
+
is_root = node.id == self.root_id
|
|
509
|
+
if detailed:
|
|
510
|
+
border_color = "#dc3545" if is_root else "#6c757d"
|
|
511
|
+
header_bg = "#ffc107" if is_root else "#e9ecef"
|
|
512
|
+
root_badge = " (Root)" if is_root else ""
|
|
513
|
+
|
|
514
|
+
match node.media_info:
|
|
515
|
+
case VideoMediaInfo() as vi:
|
|
516
|
+
info_line = f"{vi.width}x{vi.height} | {vi.format.name} | {float(vi.fps):.3f} fps"
|
|
517
|
+
case AudioMediaInfo() as ai:
|
|
518
|
+
info_line = f"{ai.sample_rate} Hz | {ai.format.num_channels} ch"
|
|
519
|
+
|
|
520
|
+
perf_line = f"Time: {node.processing_time_ms:.2f} ms | Mode: {node.filter_mode.name}"
|
|
521
|
+
|
|
522
|
+
label = (
|
|
523
|
+
f'<<TABLE BORDER="1" CELLBORDER="0" CELLSPACING="2" COLOR="{border_color}">'
|
|
524
|
+
f'<TR><TD BGCOLOR="{header_bg}"><B>{node.name} [{node.id}]{root_badge}</B></TD></TR>'
|
|
525
|
+
f'<TR><TD ALIGN="LEFT"><FONT POINT-SIZE="10">{info_line}</FONT></TD></TR>'
|
|
526
|
+
f'<TR><TD ALIGN="LEFT"><FONT POINT-SIZE="10">{perf_line}</FONT></TD></TR>'
|
|
527
|
+
f"</TABLE>>"
|
|
528
|
+
)
|
|
529
|
+
lines.append(f' "{node.id}" [shape=none, margin=0, label={label}];')
|
|
530
|
+
else:
|
|
531
|
+
root_style = ', fillcolor="#fff3cd", color="#856404"' if is_root else ""
|
|
532
|
+
lines.append(f' "{node.id}" [label="{node.name} ({node.id})"{root_style}];')
|
|
533
|
+
|
|
534
|
+
for edge in self.edges:
|
|
535
|
+
pattern_label = edge.pattern.name if edge.pattern != RequestPattern.GENERAL else ""
|
|
536
|
+
if pattern_label:
|
|
537
|
+
lines.append(f' "{edge.source}" -> "{edge.target}" [label="{pattern_label}"];')
|
|
538
|
+
else:
|
|
539
|
+
lines.append(f' "{edge.source}" -> "{edge.target}";')
|
|
540
|
+
|
|
541
|
+
lines.append("}")
|
|
542
|
+
return "\n".join(lines)
|
|
543
|
+
|
|
544
|
+
def to_ascii(self, *, compact: bool = False) -> str:
|
|
545
|
+
"""
|
|
546
|
+
Generate an ASCII / Unicode tree representation of the dependency graph starting at root.
|
|
547
|
+
|
|
548
|
+
Args:
|
|
549
|
+
compact: If True, only prints 'Name [id]'. If False, includes format, resolution, and time.
|
|
550
|
+
"""
|
|
551
|
+
root_node = self.root
|
|
552
|
+
lines = list[str]()
|
|
553
|
+
visited = set[str]()
|
|
554
|
+
|
|
555
|
+
def format_node_label(node: Node[MediaInfoT]) -> str:
|
|
556
|
+
if compact:
|
|
557
|
+
return f"{node.name} [{node.id}]"
|
|
558
|
+
|
|
559
|
+
match node.media_info:
|
|
560
|
+
case VideoMediaInfo() as vi:
|
|
561
|
+
spec = f"{vi.width}x{vi.height} {vi.format.name}"
|
|
562
|
+
case AudioMediaInfo() as ai:
|
|
563
|
+
spec = f"{ai.sample_rate}Hz {ai.format.num_channels}ch"
|
|
564
|
+
|
|
565
|
+
return f"{node.name} [{node.id}] ({spec}, {node.processing_time_ms:.2f}ms)"
|
|
566
|
+
|
|
567
|
+
def walk(current_node: Node[MediaInfoT], prefix: str = "") -> None:
|
|
568
|
+
deps = self.get_dependencies(current_node)
|
|
569
|
+
count = len(deps)
|
|
570
|
+
for i, dep in enumerate(deps):
|
|
571
|
+
is_last = i == count - 1
|
|
572
|
+
branch = "└── " if is_last else "├── "
|
|
573
|
+
extension = " " if is_last else "│ "
|
|
574
|
+
|
|
575
|
+
if dep.id in visited:
|
|
576
|
+
lines.append(f"{prefix}{branch}{dep.name} [{dep.id}] (ref)")
|
|
577
|
+
else:
|
|
578
|
+
visited.add(dep.id)
|
|
579
|
+
lines.append(f"{prefix}{branch}{format_node_label(dep)}")
|
|
580
|
+
walk(dep, prefix + extension)
|
|
581
|
+
|
|
582
|
+
lines.append(format_node_label(root_node))
|
|
583
|
+
visited.add(root_node.id)
|
|
584
|
+
walk(root_node)
|
|
585
|
+
return "\n".join(lines)
|
|
586
|
+
|
|
587
|
+
def to_cytoscape(self) -> dict[str, list[dict[str, Any]]]:
|
|
588
|
+
"""
|
|
589
|
+
Export the graph to a Cytoscape.js compatible dictionary.
|
|
590
|
+
|
|
591
|
+
Returns:
|
|
592
|
+
A dictionary with 'nodes' and 'edges' lists formatted for Cytoscape.js.
|
|
593
|
+
"""
|
|
594
|
+
return {
|
|
595
|
+
"nodes": [
|
|
596
|
+
{
|
|
597
|
+
"data": {
|
|
598
|
+
"id": node.id,
|
|
599
|
+
"label": node.name,
|
|
600
|
+
"name": node.name,
|
|
601
|
+
"filter_mode": node.filter_mode.value,
|
|
602
|
+
"filter_mode_name": node.filter_mode.name,
|
|
603
|
+
"processing_time_ns": node.processing_time_ns,
|
|
604
|
+
"processing_time_ms": node.processing_time_ms,
|
|
605
|
+
"media_info": node.media_info.to_dict(),
|
|
606
|
+
"call_stack": [frame.to_dict() for frame in node.call_stack],
|
|
607
|
+
"is_root": node.id == self.root_id,
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
for node in self.nodes
|
|
611
|
+
],
|
|
612
|
+
"edges": [
|
|
613
|
+
{
|
|
614
|
+
"data": {
|
|
615
|
+
"id": f"e{i}_{edge.source}_{edge.target}",
|
|
616
|
+
"source": edge.source,
|
|
617
|
+
"target": edge.target,
|
|
618
|
+
"pattern": edge.pattern.value,
|
|
619
|
+
"pattern_name": edge.pattern.name,
|
|
620
|
+
"label": edge.pattern.name if edge.pattern != RequestPattern.GENERAL else "",
|
|
621
|
+
"index": edge.index,
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
for i, edge in enumerate(self.edges)
|
|
625
|
+
],
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
@classmethod
|
|
629
|
+
def from_dict(cls, data: dict[str, Any]) -> Self:
|
|
630
|
+
"""Construct a Graph from a dictionary."""
|
|
631
|
+
return cls(
|
|
632
|
+
root_id=str(data["root_id"]),
|
|
633
|
+
nodes=[Node.from_dict(n) for n in data["nodes"]],
|
|
634
|
+
edges=[Edge.from_dict(e) for e in data["edges"]],
|
|
635
|
+
)
|
|
636
|
+
|
|
637
|
+
@classmethod
|
|
638
|
+
def from_json(cls, json_str: str | bytes | bytearray) -> Self:
|
|
639
|
+
"""Construct a Graph from a JSON string or bytes."""
|
|
640
|
+
return cls.from_dict(json.loads(json_str))
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
def to_node_id(node_or_id: NodeKey) -> str:
|
|
644
|
+
"""Normalize a Python VideoNode/AudioNode, graph Node, NodeRef, or string ID to a node ID string."""
|
|
645
|
+
if isinstance(node_or_id, vs.RawNode):
|
|
646
|
+
return str(hash(node_or_id))
|
|
647
|
+
if isinstance(node_or_id, (Node, NodeRef)):
|
|
648
|
+
return node_or_id.id
|
|
649
|
+
return str(node_or_id)
|
|
650
|
+
|
|
651
|
+
|
|
652
|
+
@cache
|
|
653
|
+
def _get_param_names(function_namespace: str) -> Collection[str]:
|
|
654
|
+
return Signature.from_callable(attrgetter(function_namespace)(vs.core)).parameters.keys()
|
vsgraph/py.typed
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
vsgraph/vs.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from enum import IntEnum
|
|
3
|
+
from typing import Any, Self, override
|
|
4
|
+
|
|
5
|
+
import vapoursynth as vs
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class RequestPattern(IntEnum):
|
|
9
|
+
"""VapourSynth node request pattern."""
|
|
10
|
+
|
|
11
|
+
GENERAL = 0
|
|
12
|
+
NO_FRAME_REUSE = 1
|
|
13
|
+
STRICT_SPATIAL = 2
|
|
14
|
+
FRAME_REUSE_LAST_ONLY = 3
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass(slots=True)
|
|
18
|
+
class AudioFormat:
|
|
19
|
+
sample_type: vs.SampleType
|
|
20
|
+
bits_per_sample: int
|
|
21
|
+
bytes_per_sample: int
|
|
22
|
+
num_channels: int
|
|
23
|
+
channel_layout: vs.ChannelLayout
|
|
24
|
+
|
|
25
|
+
@override
|
|
26
|
+
def __eq__(self, other: object) -> bool:
|
|
27
|
+
return int(self) == int(other) if isinstance(other, AudioFormat) else NotImplemented
|
|
28
|
+
|
|
29
|
+
@override
|
|
30
|
+
def __hash__(self) -> int:
|
|
31
|
+
return int(self)
|
|
32
|
+
|
|
33
|
+
def __int__(self) -> int:
|
|
34
|
+
return (
|
|
35
|
+
(int(self.sample_type) & 0xF) << 60
|
|
36
|
+
| (self.bits_per_sample & 0xFF) << 48
|
|
37
|
+
| (self.channel_layout & 0x0000_FFFF_FFFF_FFFF)
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
@property
|
|
41
|
+
def id(self) -> int:
|
|
42
|
+
return int(self)
|
|
43
|
+
|
|
44
|
+
@property
|
|
45
|
+
def name(self) -> str:
|
|
46
|
+
return (
|
|
47
|
+
f"Audio{self.bits_per_sample}{'F' if self.sample_type is vs.SampleType.FLOAT else ''} "
|
|
48
|
+
f"({self.num_channels} CH)"
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
@classmethod
|
|
52
|
+
def from_id(cls, id: int) -> Self:
|
|
53
|
+
sample_type = vs.SampleType((id >> 60) & 0xF)
|
|
54
|
+
bits_per_sample = (id >> 48) & 0xFF
|
|
55
|
+
channel_layout = vs.ChannelLayout(id & 0x0000_FFFF_FFFF_FFFF)
|
|
56
|
+
|
|
57
|
+
bytes_per_sample = 1 << ((bits_per_sample + 7) // 8 - 1).bit_length()
|
|
58
|
+
num_channels = channel_layout.bit_count()
|
|
59
|
+
|
|
60
|
+
return cls(
|
|
61
|
+
sample_type=sample_type,
|
|
62
|
+
bits_per_sample=bits_per_sample,
|
|
63
|
+
bytes_per_sample=bytes_per_sample,
|
|
64
|
+
num_channels=num_channels,
|
|
65
|
+
channel_layout=channel_layout,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
def _as_dict(self) -> dict[str, Any]:
|
|
69
|
+
return {
|
|
70
|
+
"id": self.id,
|
|
71
|
+
"name": self.name,
|
|
72
|
+
"sample_type": self.sample_type,
|
|
73
|
+
"bits_per_sample": self.bits_per_sample,
|
|
74
|
+
"bytes_per_sample": self.bytes_per_sample,
|
|
75
|
+
"num_channels": self.num_channels,
|
|
76
|
+
"channel_layout": self.channel_layout,
|
|
77
|
+
}
|