kinescript 1.1.1__tar.gz → 1.3.0__tar.gz
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.
- {kinescript-1.1.1 → kinescript-1.3.0}/PKG-INFO +91 -17
- {kinescript-1.1.1 → kinescript-1.3.0}/README.md +87 -14
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/__init__.py +1 -1
- kinescript-1.3.0/kinescript/audio.py +139 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/cli.py +17 -3
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/components.py +1 -1
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/docs.py +97 -11
- kinescript-1.3.0/kinescript/listen.py +349 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/mcp.py +24 -5
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/media.py +26 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/output.py +267 -32
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/render.py +5 -2
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/scene.py +184 -13
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/schema.py +98 -11
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/timing.py +42 -10
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/verify.py +31 -7
- kinescript-1.3.0/kinescript/voice.py +261 -0
- kinescript-1.3.0/kinescript/words.py +115 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript.egg-info/PKG-INFO +91 -17
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript.egg-info/SOURCES.txt +4 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/pyproject.toml +5 -3
- kinescript-1.3.0/tests/test_core.py +1189 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/tests/test_docs.py +20 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/tests/test_packaging.py +29 -19
- {kinescript-1.1.1 → kinescript-1.3.0}/tests/test_schema.py +34 -2
- kinescript-1.1.1/tests/test_core.py +0 -533
- {kinescript-1.1.1 → kinescript-1.3.0}/LICENSE +0 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/color.py +0 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/ease.py +0 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/fonts/IBMPlexMono-Bold.ttf +0 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/fonts/IBMPlexMono-Medium.ttf +0 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/fonts/IBMPlexMono-OFL.txt +0 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/fonts/IBMPlexMono-Regular.ttf +0 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/fonts/IBMPlexMono-SemiBold.ttf +0 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/fonts/SpaceGrotesk-Bold.ttf +0 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/fonts/SpaceGrotesk-Medium.ttf +0 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/fonts/SpaceGrotesk-OFL.txt +0 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/fonts/SpaceGrotesk-Regular.ttf +0 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/fonts/SpaceGrotesk-SemiBold.ttf +0 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/mesh.py +0 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/models.py +0 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/presets.py +0 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/props.py +0 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/render3d.py +0 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/shaders.py +0 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/space.py +0 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript/svgpath.py +0 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript.egg-info/dependency_links.txt +0 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript.egg-info/entry_points.txt +0 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript.egg-info/requires.txt +0 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/kinescript.egg-info/top_level.txt +0 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/setup.cfg +0 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/tests/test_color_pipeline.py +0 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/tests/test_models.py +0 -0
- {kinescript-1.1.1 → kinescript-1.3.0}/tests/test_motion_blur.py +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: kinescript
|
|
3
|
-
Version: 1.
|
|
4
|
-
Summary: Render motion graphics
|
|
3
|
+
Version: 1.3.0
|
|
4
|
+
Summary: Render motion graphics, video edits and voice-over from JSON scenes on the GPU, with checks an agent can read.
|
|
5
5
|
Author: Dr. Know How
|
|
6
6
|
License-Expression: MIT
|
|
7
7
|
Project-URL: Homepage, https://drknowhow.github.io/kinescript/
|
|
@@ -9,7 +9,7 @@ Project-URL: Documentation, https://drknowhow.github.io/kinescript/
|
|
|
9
9
|
Project-URL: Source, https://github.com/drknowhow/kinescript
|
|
10
10
|
Project-URL: Issues, https://github.com/drknowhow/kinescript/issues
|
|
11
11
|
Project-URL: Changelog, https://github.com/drknowhow/kinescript/blob/main/CHANGELOG.md
|
|
12
|
-
Keywords: video,video rendering,video editing,programmatic video,motion graphics,animation,json,skia,gpu,ffmpeg,3d,captions,mcp,ai agents
|
|
12
|
+
Keywords: video,video rendering,video editing,programmatic video,motion graphics,animation,json,skia,gpu,ffmpeg,3d,captions,voice-over,text to speech,audio mixing,loudness,mcp,ai agents
|
|
13
13
|
Classifier: Development Status :: 5 - Production/Stable
|
|
14
14
|
Classifier: Environment :: Console
|
|
15
15
|
Classifier: Environment :: GPU
|
|
@@ -25,6 +25,7 @@ Classifier: Programming Language :: Python :: 3.14
|
|
|
25
25
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
26
26
|
Classifier: Topic :: Artistic Software
|
|
27
27
|
Classifier: Topic :: Multimedia :: Graphics
|
|
28
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: Mixers
|
|
28
29
|
Classifier: Topic :: Multimedia :: Video
|
|
29
30
|
Classifier: Topic :: Multimedia :: Video :: Conversion
|
|
30
31
|
Classifier: Topic :: Multimedia :: Video :: Non-Linear Editor
|
|
@@ -46,16 +47,16 @@ Dynamic: license-file
|
|
|
46
47
|
|
|
47
48
|
<p align="center"><img src="https://raw.githubusercontent.com/drknowhow/kinescript/main/brand/logo-dark.png" width="460" alt="kinescript"></p>
|
|
48
49
|
|
|
49
|
-
<p align="center"><b>Video you can diff.</b><br>Motion graphics
|
|
50
|
+
<p align="center"><b>Video you can diff.</b><br>Motion graphics, video edits and voice-over written as JSON, checked by agents, rendered on the GPU.</p>
|
|
50
51
|
|
|
51
52
|
<p align="center"><a href="https://drknowhow.github.io/kinescript/">Documentation</a> · <a href="https://github.com/drknowhow/kinescript">Source</a> · <a href="https://github.com/drknowhow/kinescript/blob/main/CHANGELOG.md">Changelog</a> · <a href="https://github.com/drknowhow/kinescript/blob/main/docs/promo.mp4">Launch video</a></p>
|
|
52
53
|
|
|
53
54
|
<p align="center"><img src="https://raw.githubusercontent.com/drknowhow/kinescript/main/docs/hero.gif" width="720" alt="The Kinescript launch video, rendered by Kinescript"></p>
|
|
54
55
|
|
|
55
|
-
Kinescript turns a JSON scene into video. Every layer, keyframe and
|
|
56
|
-
generated, reviewed in a pull request, and changed by a script or an agent.
|
|
57
|
-
the frame number: any frame renders on its own, which makes previews
|
|
58
|
-
processes.
|
|
56
|
+
Kinescript turns a JSON scene into video. Every layer, keyframe, cut and sound is a line of data, so a scene can
|
|
57
|
+
be generated, reviewed in a pull request, and changed by a script or an agent. A voice-over can start as a line of
|
|
58
|
+
text. The renderer is a pure function of the frame number: any frame renders on its own, which makes previews
|
|
59
|
+
instant and lets a render split across processes.
|
|
59
60
|
|
|
60
61
|
```bash
|
|
61
62
|
pip install kinescript
|
|
@@ -66,7 +67,7 @@ It needs Python 3.10 or newer and ffmpeg on your `PATH` ([details](https://githu
|
|
|
66
67
|
|
|
67
68
|
The [launch video](https://github.com/drknowhow/kinescript/blob/main/docs/promo.mp4) is a Kinescript scene,
|
|
68
69
|
[`marketing/promo.json`](https://github.com/drknowhow/kinescript/blob/main/marketing/promo.json). It is 35
|
|
69
|
-
seconds of 1080p and renders, with audio, in about 3.
|
|
70
|
+
seconds of 1080p and renders, with audio, in about 3.3 seconds on the development machine. The
|
|
70
71
|
[project site](https://drknowhow.github.io/kinescript/) shows more demos, each next to the scene file it was
|
|
71
72
|
rendered from.
|
|
72
73
|
|
|
@@ -83,7 +84,10 @@ rendered from.
|
|
|
83
84
|
- **Footage.** Video layers with trim, speed, loop, cover/contain fit, punch-in `zoom` around a `focus` point, and
|
|
84
85
|
rounded picture-in-picture. A `sequence` turns a cut list into clips with fade, wipe, slide, zoom or blur
|
|
85
86
|
transitions. Clip audio and music beds are mixed automatically.
|
|
86
|
-
- **
|
|
87
|
+
- **Sound on the same timeline.** Voice-over, music and effects are cues like layers, a voice's words are cues
|
|
88
|
+
too, a voice can be spoken from text, and sounds with a role are levelled and ducked for you
|
|
89
|
+
([Sound](https://github.com/drknowhow/kinescript#sound)).
|
|
90
|
+
- **Captions** from `.srt`/`.vtt`, inline cues or a voice's word times, with karaoke and pop modes.
|
|
87
91
|
- **Shaders.** SkSL layers with `mesh`, `aurora`, `grid` and `score` presets, or your own source.
|
|
88
92
|
- **Finishing.** Per-layer blur, shadow, blend modes and colour adjustments; a scene grade with vignette and film
|
|
89
93
|
grain; optional motion blur.
|
|
@@ -118,6 +122,60 @@ A 3D title that builds in and turns to face the camera:
|
|
|
118
122
|
"shine": 0.6, "enter": {"name": "build", "dur": 1.2}}
|
|
119
123
|
```
|
|
120
124
|
|
|
125
|
+
## Sound
|
|
126
|
+
|
|
127
|
+
Sounds are a top-level `audio` list, timed like layers and mixed by ffmpeg while the frames render.
|
|
128
|
+
|
|
129
|
+
- **Cues both ways.** `"at": "vo1.out+0.3"` starts a layer 0.3 s after the voice ends, and a sound can start at
|
|
130
|
+
`"title.in"`. A layer's `"sound": "pop.wav"` plays when it appears and moves when it moves. A voice stretches an
|
|
131
|
+
`auto` duration so it is never cut off.
|
|
132
|
+
- **Words are cues.** A words file next to a voice (`vo1.words.json`, or Whisper's JSON as it is) times each
|
|
133
|
+
word: `"at": "vo1:render"` starts a layer as the voice says "render", and `{"type": "captions", "voice": "vo1"}`
|
|
134
|
+
captions it, lighting each word as it is said.
|
|
135
|
+
- **Voice-over from text.** Write what a voice says in `text` and `kine voice` speaks it through a plugin, writing
|
|
136
|
+
the file and its word times: [Kokoro](https://github.com/drknowhow/kinescript/tree/main/plugins/kinescript-kokoro)
|
|
137
|
+
(local, fast),
|
|
138
|
+
[Chatterbox](https://github.com/drknowhow/kinescript/tree/main/plugins/kinescript-chatterbox) (local, tags,
|
|
139
|
+
cloned voices) or [ElevenLabs](https://github.com/drknowhow/kinescript/tree/main/plugins/kinescript-elevenlabs)
|
|
140
|
+
(cloud, needs an API key), picked per sound with `backend`. `[[go]]` in the text names the next
|
|
141
|
+
word, so a cue to `vo1:go` survives a rewrite of the line. Only a line whose text, speaker, rate, backend or
|
|
142
|
+
options changed is spoken again, and rendering never calls a speech engine.
|
|
143
|
+
- **Delivery tags.** `[whispers]`, `[laughs]` or `[sighs]` in the text tell Chatterbox and ElevenLabs how to say
|
|
144
|
+
what follows. Tags are not words, so cues, marks and captions skip them, and Kokoro says the line without them.
|
|
145
|
+
- **A mix without listening.** Give a sound a `role` and it is set to that role's level: voice -18 LUFS, music
|
|
146
|
+
-16, ambience -30, effects peaking at -6 dBFS. Music and ambience dip 14 dB while a voice speaks, an effect's
|
|
147
|
+
leading silence is skipped so it lands on its cue, and the whole mix ends at -16 LUFS with peaks under
|
|
148
|
+
-1.5 dBTP. A top-level `mix` changes the targets. Sounds without a role are mixed as given.
|
|
149
|
+
- **Checked and drawn.** `kine check` mixes and measures the sound and reports a voice cut off or masked by the
|
|
150
|
+
music, an effect that lands late, silence, and a mix off its targets. `kine look --audio` draws the sound under
|
|
151
|
+
the frames on the same time axis.
|
|
152
|
+
- **Everywhere.** Gain takes keyframes and expressions like any property; sounds loop and pan; the mix goes into
|
|
153
|
+
MP4, MOV, WebM and `--from/--to` renders, and `-o mix.wav` renders the sound alone.
|
|
154
|
+
|
|
155
|
+
A narrated beat with a click on a marked word, over music that ducks under the voice:
|
|
156
|
+
|
|
157
|
+
```json
|
|
158
|
+
"audio": [
|
|
159
|
+
{"id": "vo", "role": "voice", "at": 0.6, "text": "Each word it says is a [[hit]]cue."},
|
|
160
|
+
{"id": "bed", "role": "music", "src": "bed.m4a", "loop": true, "until": "end", "fadeOut": 1.5}
|
|
161
|
+
],
|
|
162
|
+
"layers": [
|
|
163
|
+
{"id": "cue", "type": "text", "text": "Cue", "size": 200, "at": "vo:hit", "sound": "click.wav", "enter": "pop"},
|
|
164
|
+
{"id": "cc", "type": "captions", "voice": "vo", "mode": "karaoke"}
|
|
165
|
+
]
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
`kine voice scene.json` speaks it once. The
|
|
169
|
+
[voice demo](https://drknowhow.github.io/kinescript/#sound) on the project site plays the result with sound, next
|
|
170
|
+
to its scene file. The Kokoro plugin needs Python 3.10 to 3.12:
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
pip install kinescript-kokoro
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
On a newer Python, install it into another one and point `KINE_VOICE_CMD` at it
|
|
177
|
+
([details](https://github.com/drknowhow/kinescript/tree/main/plugins/kinescript-kokoro)).
|
|
178
|
+
|
|
121
179
|
## Built for agents
|
|
122
180
|
|
|
123
181
|
An agent cannot watch a video, so Kinescript gives it things it can read:
|
|
@@ -127,18 +185,23 @@ An agent cannot watch a video, so Kinescript gives it things it can read:
|
|
|
127
185
|
| `kine docs` | the full scene reference, short enough to keep in context |
|
|
128
186
|
| `kine check scene.json` | every problem at once as JSON, each with its layer, time range and a fix |
|
|
129
187
|
| `kine look scene.json --boxes` | one PNG of many labelled frames, with every layer outlined and the top-level ones named |
|
|
188
|
+
| `kine look scene.json --audio` | the same frames with the sound under them: a lane per role and the mix, the duck and issues, plus each sound's measured loudness |
|
|
130
189
|
| `kine probe scene.json --at 3.2` | resolved in/out of every layer and each visible layer's screen box |
|
|
131
190
|
| `kine still` / `kine render` | a frame, a range (`--from/--to`), a draft (`-q draft --scale 0.5`) or the final file |
|
|
132
191
|
| `kine watch scene.json` | the contact sheet, made again every time the file is saved |
|
|
192
|
+
| `kine voice scene.json` | each sound with text spoken into its file, with its word times, skipping what has not changed |
|
|
133
193
|
|
|
134
194
|
`kine check` reports unknown keys and bad values, missing media and out-of-range trims, text off the canvas or
|
|
135
195
|
in the safe margin, overlapping text, contrast under 3:1 against what is actually behind the text, tiny text and
|
|
136
|
-
too little reading time.
|
|
196
|
+
too little reading time. When the scene has sound it mixes and measures it, without drawing a frame, while the
|
|
197
|
+
frames are checked, and reports a voice cut off by the scene end, two voices at once, music less than 10 LU under a
|
|
198
|
+
voice, an effect whose first sound comes late, a silent sound, and a mix off its loudness target or at its peak
|
|
199
|
+
ceiling. An unknown key names the intended key first. Common names from other tools (`color`,
|
|
137
200
|
`fontSize`, `duration`, `position`) are read and reported as info notes. It exits with status 1 while there are
|
|
138
201
|
errors.
|
|
139
202
|
|
|
140
203
|
The same tools are available over MCP (`kine mcp`) as `kine_docs`, `kine_check`, `kine_look`, `kine_still`,
|
|
141
|
-
`kine_probe` and `
|
|
204
|
+
`kine_probe`, `kine_render` and `kine_voice`. They take a scene as a file path or as the JSON object itself, and `kine_look`
|
|
142
205
|
and `kine_still` return images inline.
|
|
143
206
|
|
|
144
207
|
```json
|
|
@@ -205,8 +268,13 @@ More scenes in [`examples/`](https://github.com/drknowhow/kinescript/tree/main/e
|
|
|
205
268
|
extruded SVG path and the wordmark as extruded text, 5 s.
|
|
206
269
|
- [`import.json`](https://github.com/drknowhow/kinescript/blob/main/examples/import.json): a glTF rocket on a
|
|
207
270
|
ground shadow, 6 s.
|
|
271
|
+
- [`voiceover.json`](https://github.com/drknowhow/kinescript/blob/main/examples/voiceover.json): titles cued from
|
|
272
|
+
the words of a voice-over, karaoke captions of it, and a music bed that dips under it, 5.4 s.
|
|
273
|
+
- [`narrated.json`](https://github.com/drknowhow/kinescript/blob/main/examples/narrated.json): the same idea
|
|
274
|
+
with a voice written as text, a marked word and a click on it. Run `kine voice examples/narrated.json` first.
|
|
208
275
|
|
|
209
|
-
`edit.json` and `
|
|
276
|
+
`edit.json`, `import.json`, `voiceover.json` and `narrated.json` read sample media: run
|
|
277
|
+
`python examples/make_media.py` first to generate it.
|
|
210
278
|
|
|
211
279
|
## Performance
|
|
212
280
|
|
|
@@ -215,9 +283,9 @@ Measured on the development machine (Intel Core Ultra 7 265, 20 threads, NVIDIA
|
|
|
215
283
|
|
|
216
284
|
| Workload | Result |
|
|
217
285
|
|---|---|
|
|
218
|
-
| Drawing one 1080p frame of the launch video on the GPU, converted to I420 and read back as a render does | median 2.
|
|
219
|
-
| Launch video, 34.6 s at 1080p30, `-q high`, with audio | 3.
|
|
220
|
-
| `examples/edit.json`, 10.4 s with two decoded video clips | 2.
|
|
286
|
+
| Drawing one 1080p frame of the launch video on the GPU, converted to I420 and read back as a render does | median 2.8 ms, p95 3.8 ms (all 1038 frames) |
|
|
287
|
+
| Launch video, 34.6 s at 1080p30, `-q high`, with audio | 3.3 s wall, about 320 frames/s (median of 5 runs) |
|
|
288
|
+
| `examples/edit.json`, 10.4 s with two decoded video clips | 2.25 s wall, 139 frames/s (median of 5 runs) |
|
|
221
289
|
|
|
222
290
|
[`python bench/stages.py`](https://github.com/drknowhow/kinescript/blob/main/bench/stages.py) splits the time
|
|
223
291
|
per frame into drawing, conversion and readback, and writing to ffmpeg for several workloads, and times whole
|
|
@@ -235,7 +303,11 @@ Within one process, such as the MCP server, the workers stay warm for two minute
|
|
|
235
303
|
- 3D is drawn by Skia with a depth sort, not a GL pipeline: models have no image textures, skeletal animation or
|
|
236
304
|
shadows cast on each other, and separate model layers do not hide each other per pixel (merge touching
|
|
237
305
|
objects as `parts` of one model). Draco- and meshopt-compressed model files are not read.
|
|
238
|
-
- Audio is mixing (trim, gain, fades, speed
|
|
306
|
+
- Audio is mixing and levelling (trim, gain over time, fades, speed, loop, pan, role levels, ducking, a loudness
|
|
307
|
+
target), with no effects such as EQ, compression of single sounds or reverb.
|
|
308
|
+
- Kinescript does not speak by itself: `kine voice` needs a plugin or a command. The Kokoro plugin times words
|
|
309
|
+
for English voices only and needs Python 3.10 to 3.12; the Chatterbox plugin speaks and times English only;
|
|
310
|
+
the ElevenLabs plugin needs an API key and a network connection.
|
|
239
311
|
- Video is decoded and resampled by ffmpeg to the scene frame rate. Jumping backwards or far ahead reopens the
|
|
240
312
|
decoder, which is slower than sequential playback.
|
|
241
313
|
- Text layout is single-script left-to-right with greedy wrapping. No shaping for complex scripts or bidi.
|
|
@@ -248,6 +320,8 @@ kinescript/ engine: timing, props, scene, components, render (Skia), space, re
|
|
|
248
320
|
mesh and models (3D), output (encoding and the audio mix),
|
|
249
321
|
verify (check, look, probe), schema, docs, mcp, cli
|
|
250
322
|
examples/ example scenes and the generator for sample media
|
|
323
|
+
plugins/ voices for kine voice, each installed on its own: kinescript-kokoro, kinescript-chatterbox,
|
|
324
|
+
kinescript-elevenlabs
|
|
251
325
|
marketing/ the launch video as a scene and its builder; build_site.py renders the site
|
|
252
326
|
site/ the project site: demo scenes next to the videos rendered from them
|
|
253
327
|
brand/ logo files, generated art and the brand guide
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
<p align="center"><img src="https://raw.githubusercontent.com/drknowhow/kinescript/main/brand/logo-dark.png" width="460" alt="kinescript"></p>
|
|
2
2
|
|
|
3
|
-
<p align="center"><b>Video you can diff.</b><br>Motion graphics
|
|
3
|
+
<p align="center"><b>Video you can diff.</b><br>Motion graphics, video edits and voice-over written as JSON, checked by agents, rendered on the GPU.</p>
|
|
4
4
|
|
|
5
5
|
<p align="center"><a href="https://drknowhow.github.io/kinescript/">Documentation</a> · <a href="https://github.com/drknowhow/kinescript">Source</a> · <a href="https://github.com/drknowhow/kinescript/blob/main/CHANGELOG.md">Changelog</a> · <a href="https://github.com/drknowhow/kinescript/blob/main/docs/promo.mp4">Launch video</a></p>
|
|
6
6
|
|
|
7
7
|
<p align="center"><img src="https://raw.githubusercontent.com/drknowhow/kinescript/main/docs/hero.gif" width="720" alt="The Kinescript launch video, rendered by Kinescript"></p>
|
|
8
8
|
|
|
9
|
-
Kinescript turns a JSON scene into video. Every layer, keyframe and
|
|
10
|
-
generated, reviewed in a pull request, and changed by a script or an agent.
|
|
11
|
-
the frame number: any frame renders on its own, which makes previews
|
|
12
|
-
processes.
|
|
9
|
+
Kinescript turns a JSON scene into video. Every layer, keyframe, cut and sound is a line of data, so a scene can
|
|
10
|
+
be generated, reviewed in a pull request, and changed by a script or an agent. A voice-over can start as a line of
|
|
11
|
+
text. The renderer is a pure function of the frame number: any frame renders on its own, which makes previews
|
|
12
|
+
instant and lets a render split across processes.
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
15
|
pip install kinescript
|
|
@@ -20,7 +20,7 @@ It needs Python 3.10 or newer and ffmpeg on your `PATH` ([details](https://githu
|
|
|
20
20
|
|
|
21
21
|
The [launch video](https://github.com/drknowhow/kinescript/blob/main/docs/promo.mp4) is a Kinescript scene,
|
|
22
22
|
[`marketing/promo.json`](https://github.com/drknowhow/kinescript/blob/main/marketing/promo.json). It is 35
|
|
23
|
-
seconds of 1080p and renders, with audio, in about 3.
|
|
23
|
+
seconds of 1080p and renders, with audio, in about 3.3 seconds on the development machine. The
|
|
24
24
|
[project site](https://drknowhow.github.io/kinescript/) shows more demos, each next to the scene file it was
|
|
25
25
|
rendered from.
|
|
26
26
|
|
|
@@ -37,7 +37,10 @@ rendered from.
|
|
|
37
37
|
- **Footage.** Video layers with trim, speed, loop, cover/contain fit, punch-in `zoom` around a `focus` point, and
|
|
38
38
|
rounded picture-in-picture. A `sequence` turns a cut list into clips with fade, wipe, slide, zoom or blur
|
|
39
39
|
transitions. Clip audio and music beds are mixed automatically.
|
|
40
|
-
- **
|
|
40
|
+
- **Sound on the same timeline.** Voice-over, music and effects are cues like layers, a voice's words are cues
|
|
41
|
+
too, a voice can be spoken from text, and sounds with a role are levelled and ducked for you
|
|
42
|
+
([Sound](https://github.com/drknowhow/kinescript#sound)).
|
|
43
|
+
- **Captions** from `.srt`/`.vtt`, inline cues or a voice's word times, with karaoke and pop modes.
|
|
41
44
|
- **Shaders.** SkSL layers with `mesh`, `aurora`, `grid` and `score` presets, or your own source.
|
|
42
45
|
- **Finishing.** Per-layer blur, shadow, blend modes and colour adjustments; a scene grade with vignette and film
|
|
43
46
|
grain; optional motion blur.
|
|
@@ -72,6 +75,60 @@ A 3D title that builds in and turns to face the camera:
|
|
|
72
75
|
"shine": 0.6, "enter": {"name": "build", "dur": 1.2}}
|
|
73
76
|
```
|
|
74
77
|
|
|
78
|
+
## Sound
|
|
79
|
+
|
|
80
|
+
Sounds are a top-level `audio` list, timed like layers and mixed by ffmpeg while the frames render.
|
|
81
|
+
|
|
82
|
+
- **Cues both ways.** `"at": "vo1.out+0.3"` starts a layer 0.3 s after the voice ends, and a sound can start at
|
|
83
|
+
`"title.in"`. A layer's `"sound": "pop.wav"` plays when it appears and moves when it moves. A voice stretches an
|
|
84
|
+
`auto` duration so it is never cut off.
|
|
85
|
+
- **Words are cues.** A words file next to a voice (`vo1.words.json`, or Whisper's JSON as it is) times each
|
|
86
|
+
word: `"at": "vo1:render"` starts a layer as the voice says "render", and `{"type": "captions", "voice": "vo1"}`
|
|
87
|
+
captions it, lighting each word as it is said.
|
|
88
|
+
- **Voice-over from text.** Write what a voice says in `text` and `kine voice` speaks it through a plugin, writing
|
|
89
|
+
the file and its word times: [Kokoro](https://github.com/drknowhow/kinescript/tree/main/plugins/kinescript-kokoro)
|
|
90
|
+
(local, fast),
|
|
91
|
+
[Chatterbox](https://github.com/drknowhow/kinescript/tree/main/plugins/kinescript-chatterbox) (local, tags,
|
|
92
|
+
cloned voices) or [ElevenLabs](https://github.com/drknowhow/kinescript/tree/main/plugins/kinescript-elevenlabs)
|
|
93
|
+
(cloud, needs an API key), picked per sound with `backend`. `[[go]]` in the text names the next
|
|
94
|
+
word, so a cue to `vo1:go` survives a rewrite of the line. Only a line whose text, speaker, rate, backend or
|
|
95
|
+
options changed is spoken again, and rendering never calls a speech engine.
|
|
96
|
+
- **Delivery tags.** `[whispers]`, `[laughs]` or `[sighs]` in the text tell Chatterbox and ElevenLabs how to say
|
|
97
|
+
what follows. Tags are not words, so cues, marks and captions skip them, and Kokoro says the line without them.
|
|
98
|
+
- **A mix without listening.** Give a sound a `role` and it is set to that role's level: voice -18 LUFS, music
|
|
99
|
+
-16, ambience -30, effects peaking at -6 dBFS. Music and ambience dip 14 dB while a voice speaks, an effect's
|
|
100
|
+
leading silence is skipped so it lands on its cue, and the whole mix ends at -16 LUFS with peaks under
|
|
101
|
+
-1.5 dBTP. A top-level `mix` changes the targets. Sounds without a role are mixed as given.
|
|
102
|
+
- **Checked and drawn.** `kine check` mixes and measures the sound and reports a voice cut off or masked by the
|
|
103
|
+
music, an effect that lands late, silence, and a mix off its targets. `kine look --audio` draws the sound under
|
|
104
|
+
the frames on the same time axis.
|
|
105
|
+
- **Everywhere.** Gain takes keyframes and expressions like any property; sounds loop and pan; the mix goes into
|
|
106
|
+
MP4, MOV, WebM and `--from/--to` renders, and `-o mix.wav` renders the sound alone.
|
|
107
|
+
|
|
108
|
+
A narrated beat with a click on a marked word, over music that ducks under the voice:
|
|
109
|
+
|
|
110
|
+
```json
|
|
111
|
+
"audio": [
|
|
112
|
+
{"id": "vo", "role": "voice", "at": 0.6, "text": "Each word it says is a [[hit]]cue."},
|
|
113
|
+
{"id": "bed", "role": "music", "src": "bed.m4a", "loop": true, "until": "end", "fadeOut": 1.5}
|
|
114
|
+
],
|
|
115
|
+
"layers": [
|
|
116
|
+
{"id": "cue", "type": "text", "text": "Cue", "size": 200, "at": "vo:hit", "sound": "click.wav", "enter": "pop"},
|
|
117
|
+
{"id": "cc", "type": "captions", "voice": "vo", "mode": "karaoke"}
|
|
118
|
+
]
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
`kine voice scene.json` speaks it once. The
|
|
122
|
+
[voice demo](https://drknowhow.github.io/kinescript/#sound) on the project site plays the result with sound, next
|
|
123
|
+
to its scene file. The Kokoro plugin needs Python 3.10 to 3.12:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
pip install kinescript-kokoro
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
On a newer Python, install it into another one and point `KINE_VOICE_CMD` at it
|
|
130
|
+
([details](https://github.com/drknowhow/kinescript/tree/main/plugins/kinescript-kokoro)).
|
|
131
|
+
|
|
75
132
|
## Built for agents
|
|
76
133
|
|
|
77
134
|
An agent cannot watch a video, so Kinescript gives it things it can read:
|
|
@@ -81,18 +138,23 @@ An agent cannot watch a video, so Kinescript gives it things it can read:
|
|
|
81
138
|
| `kine docs` | the full scene reference, short enough to keep in context |
|
|
82
139
|
| `kine check scene.json` | every problem at once as JSON, each with its layer, time range and a fix |
|
|
83
140
|
| `kine look scene.json --boxes` | one PNG of many labelled frames, with every layer outlined and the top-level ones named |
|
|
141
|
+
| `kine look scene.json --audio` | the same frames with the sound under them: a lane per role and the mix, the duck and issues, plus each sound's measured loudness |
|
|
84
142
|
| `kine probe scene.json --at 3.2` | resolved in/out of every layer and each visible layer's screen box |
|
|
85
143
|
| `kine still` / `kine render` | a frame, a range (`--from/--to`), a draft (`-q draft --scale 0.5`) or the final file |
|
|
86
144
|
| `kine watch scene.json` | the contact sheet, made again every time the file is saved |
|
|
145
|
+
| `kine voice scene.json` | each sound with text spoken into its file, with its word times, skipping what has not changed |
|
|
87
146
|
|
|
88
147
|
`kine check` reports unknown keys and bad values, missing media and out-of-range trims, text off the canvas or
|
|
89
148
|
in the safe margin, overlapping text, contrast under 3:1 against what is actually behind the text, tiny text and
|
|
90
|
-
too little reading time.
|
|
149
|
+
too little reading time. When the scene has sound it mixes and measures it, without drawing a frame, while the
|
|
150
|
+
frames are checked, and reports a voice cut off by the scene end, two voices at once, music less than 10 LU under a
|
|
151
|
+
voice, an effect whose first sound comes late, a silent sound, and a mix off its loudness target or at its peak
|
|
152
|
+
ceiling. An unknown key names the intended key first. Common names from other tools (`color`,
|
|
91
153
|
`fontSize`, `duration`, `position`) are read and reported as info notes. It exits with status 1 while there are
|
|
92
154
|
errors.
|
|
93
155
|
|
|
94
156
|
The same tools are available over MCP (`kine mcp`) as `kine_docs`, `kine_check`, `kine_look`, `kine_still`,
|
|
95
|
-
`kine_probe` and `
|
|
157
|
+
`kine_probe`, `kine_render` and `kine_voice`. They take a scene as a file path or as the JSON object itself, and `kine_look`
|
|
96
158
|
and `kine_still` return images inline.
|
|
97
159
|
|
|
98
160
|
```json
|
|
@@ -159,8 +221,13 @@ More scenes in [`examples/`](https://github.com/drknowhow/kinescript/tree/main/e
|
|
|
159
221
|
extruded SVG path and the wordmark as extruded text, 5 s.
|
|
160
222
|
- [`import.json`](https://github.com/drknowhow/kinescript/blob/main/examples/import.json): a glTF rocket on a
|
|
161
223
|
ground shadow, 6 s.
|
|
224
|
+
- [`voiceover.json`](https://github.com/drknowhow/kinescript/blob/main/examples/voiceover.json): titles cued from
|
|
225
|
+
the words of a voice-over, karaoke captions of it, and a music bed that dips under it, 5.4 s.
|
|
226
|
+
- [`narrated.json`](https://github.com/drknowhow/kinescript/blob/main/examples/narrated.json): the same idea
|
|
227
|
+
with a voice written as text, a marked word and a click on it. Run `kine voice examples/narrated.json` first.
|
|
162
228
|
|
|
163
|
-
`edit.json` and `
|
|
229
|
+
`edit.json`, `import.json`, `voiceover.json` and `narrated.json` read sample media: run
|
|
230
|
+
`python examples/make_media.py` first to generate it.
|
|
164
231
|
|
|
165
232
|
## Performance
|
|
166
233
|
|
|
@@ -169,9 +236,9 @@ Measured on the development machine (Intel Core Ultra 7 265, 20 threads, NVIDIA
|
|
|
169
236
|
|
|
170
237
|
| Workload | Result |
|
|
171
238
|
|---|---|
|
|
172
|
-
| Drawing one 1080p frame of the launch video on the GPU, converted to I420 and read back as a render does | median 2.
|
|
173
|
-
| Launch video, 34.6 s at 1080p30, `-q high`, with audio | 3.
|
|
174
|
-
| `examples/edit.json`, 10.4 s with two decoded video clips | 2.
|
|
239
|
+
| Drawing one 1080p frame of the launch video on the GPU, converted to I420 and read back as a render does | median 2.8 ms, p95 3.8 ms (all 1038 frames) |
|
|
240
|
+
| Launch video, 34.6 s at 1080p30, `-q high`, with audio | 3.3 s wall, about 320 frames/s (median of 5 runs) |
|
|
241
|
+
| `examples/edit.json`, 10.4 s with two decoded video clips | 2.25 s wall, 139 frames/s (median of 5 runs) |
|
|
175
242
|
|
|
176
243
|
[`python bench/stages.py`](https://github.com/drknowhow/kinescript/blob/main/bench/stages.py) splits the time
|
|
177
244
|
per frame into drawing, conversion and readback, and writing to ffmpeg for several workloads, and times whole
|
|
@@ -189,7 +256,11 @@ Within one process, such as the MCP server, the workers stay warm for two minute
|
|
|
189
256
|
- 3D is drawn by Skia with a depth sort, not a GL pipeline: models have no image textures, skeletal animation or
|
|
190
257
|
shadows cast on each other, and separate model layers do not hide each other per pixel (merge touching
|
|
191
258
|
objects as `parts` of one model). Draco- and meshopt-compressed model files are not read.
|
|
192
|
-
- Audio is mixing (trim, gain, fades, speed
|
|
259
|
+
- Audio is mixing and levelling (trim, gain over time, fades, speed, loop, pan, role levels, ducking, a loudness
|
|
260
|
+
target), with no effects such as EQ, compression of single sounds or reverb.
|
|
261
|
+
- Kinescript does not speak by itself: `kine voice` needs a plugin or a command. The Kokoro plugin times words
|
|
262
|
+
for English voices only and needs Python 3.10 to 3.12; the Chatterbox plugin speaks and times English only;
|
|
263
|
+
the ElevenLabs plugin needs an API key and a network connection.
|
|
193
264
|
- Video is decoded and resampled by ffmpeg to the scene frame rate. Jumping backwards or far ahead reopens the
|
|
194
265
|
decoder, which is slower than sequential playback.
|
|
195
266
|
- Text layout is single-script left-to-right with greedy wrapping. No shaping for complex scripts or bidi.
|
|
@@ -202,6 +273,8 @@ kinescript/ engine: timing, props, scene, components, render (Skia), space, re
|
|
|
202
273
|
mesh and models (3D), output (encoding and the audio mix),
|
|
203
274
|
verify (check, look, probe), schema, docs, mcp, cli
|
|
204
275
|
examples/ example scenes and the generator for sample media
|
|
276
|
+
plugins/ voices for kine voice, each installed on its own: kinescript-kokoro, kinescript-chatterbox,
|
|
277
|
+
kinescript-elevenlabs
|
|
205
278
|
marketing/ the launch video as a scene and its builder; build_site.py renders the site
|
|
206
279
|
site/ the project site: demo scenes next to the videos rendered from them
|
|
207
280
|
brand/ logo files, generated art and the brand guide
|
|
@@ -9,5 +9,5 @@ except ImportError as e: # on Linux the wheel loads the system's EGL and GL, ev
|
|
|
9
9
|
from .output import render, still
|
|
10
10
|
from .scene import Scene, SceneError, load
|
|
11
11
|
|
|
12
|
-
__version__ = "1.
|
|
12
|
+
__version__ = "1.3.0"
|
|
13
13
|
__all__ = ["Scene", "SceneError", "load", "render", "still", "__version__"]
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"""The managed mix, used when any sound in a scene has a role: each sound is set to its role's level, music and
|
|
2
|
+
ambience dip while a voice speaks, and the whole mix is brought to one loudness under a peak ceiling.
|
|
3
|
+
|
|
4
|
+
Every gain here is worked out from the files and the scene, never by listening at render time, so a scene always
|
|
5
|
+
mixes the same way and the numbers can be reported to an agent that cannot hear.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import math
|
|
10
|
+
import re
|
|
11
|
+
import subprocess
|
|
12
|
+
from functools import lru_cache
|
|
13
|
+
|
|
14
|
+
import numpy as np
|
|
15
|
+
|
|
16
|
+
from . import media
|
|
17
|
+
from .props import Ctx, compile_prop
|
|
18
|
+
|
|
19
|
+
ROLES = ("voice", "music", "sfx", "ambience")
|
|
20
|
+
# voice, music and ambience in LUFS; sfx as a sample peak in dBFS, since a short effect has no useful loudness.
|
|
21
|
+
LEVELS = {"voice": -18.0, "music": -16.0, "ambience": -30.0, "sfx": -6.0}
|
|
22
|
+
DUCK = {"by": ["voice"], "under": ["music", "ambience"], "depth": 14.0, "attack": 0.08, "hold": 0.15, "release": 0.4}
|
|
23
|
+
LOUDNESS, PEAK = -16.0, -1.5 # the whole mix: LUFS, and dBTP
|
|
24
|
+
RATE = 1000 # gain curve samples per second
|
|
25
|
+
_AN = 8000 # analysis sample rate
|
|
26
|
+
_WIN = 0.02 # RMS window, seconds
|
|
27
|
+
SPEECH = -45.0 # dBFS: a voice window louder than this, after levelling, ducks the music
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def settings(spec: dict) -> dict:
|
|
31
|
+
"""The scene's "mix" block over the defaults."""
|
|
32
|
+
m = spec.get("mix") or {}
|
|
33
|
+
duck = m.get("duck", {})
|
|
34
|
+
if duck is not False:
|
|
35
|
+
duck = dict(DUCK, **(duck if isinstance(duck, dict) else {}))
|
|
36
|
+
for k in ("by", "under"):
|
|
37
|
+
duck[k] = [duck[k]] if isinstance(duck[k], str) else list(duck[k])
|
|
38
|
+
return {"loudness": float(m.get("loudness", LOUDNESS)), "peak": float(m.get("peak", PEAK)),
|
|
39
|
+
"levels": dict(LEVELS, **(m.get("levels") or {})), "duck": duck or None}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def analyze(src: str, start: float = 0.0, end: float | None = None) -> dict:
|
|
43
|
+
"""Loudness and shape of src between start and end (seconds in the file), measured once per file version:
|
|
44
|
+
lufs, peak (sample, dBFS), true_peak (dBTP), power (mean, dBFS), rms (dBFS per 20 ms window) and lead
|
|
45
|
+
(seconds of silence before the first sound)."""
|
|
46
|
+
return _analyze(*media._version(src), round(float(start), 4), None if end is None else round(float(end), 4))
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@lru_cache(maxsize=256)
|
|
50
|
+
def _analyze(src: str, mtime: int, size: int, start: float, end: float | None) -> dict:
|
|
51
|
+
return measure(src, start, end)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def measure(src: str, start: float = 0.0, end: float | None = None) -> dict:
|
|
55
|
+
"""analyze without the cache, for a file that is made once and measured once, like a finished mix."""
|
|
56
|
+
cut = f"atrim=start={start}" + ("" if end is None else f":end={end}") + ",asetpts=PTS-STARTPTS,"
|
|
57
|
+
res = subprocess.run([media.FFMPEG, "-hide_banner", "-nostats", "-i", src, "-af",
|
|
58
|
+
cut + f"ebur128=peak=true+sample,aresample={_AN},aformat=sample_fmts=flt:channel_layouts=mono",
|
|
59
|
+
"-f", "f32le", "-"], capture_output=True, creationflags=media._NOWIN)
|
|
60
|
+
if res.returncode:
|
|
61
|
+
raise media.MediaError(f"could not measure {src}: {res.stderr.decode(errors='replace').strip()[-300:]}")
|
|
62
|
+
info = loudness(res.stderr.decode(errors="replace"))
|
|
63
|
+
pcm = np.frombuffer(res.stdout, np.float32).astype(np.float64)
|
|
64
|
+
w = int(_AN * _WIN)
|
|
65
|
+
n = len(pcm) // w
|
|
66
|
+
info["rms"] = 10 * np.log10(np.mean(pcm[: n * w].reshape(n, w) ** 2, axis=1) + 1e-12)
|
|
67
|
+
info["power"] = float(10 * np.log10(np.mean(pcm ** 2) + 1e-12)) if len(pcm) else -math.inf
|
|
68
|
+
floor = 10 ** (min(-60.0, info["peak"] - 50) / 20) if math.isfinite(info["peak"]) else 1.0
|
|
69
|
+
loud = np.abs(pcm) > floor
|
|
70
|
+
info["lead"] = float(np.argmax(loud)) / _AN if loud.any() else 0.0
|
|
71
|
+
return info
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def loudness(log: str) -> dict:
|
|
75
|
+
"""lufs, peak, true_peak and lra (loudness range, LU) from the summary ffmpeg's ebur128 filter writes to its
|
|
76
|
+
log, and short_max, the loudest 3 s, from the lines it writes every 0.1 s."""
|
|
77
|
+
at = log.rfind("Summary:")
|
|
78
|
+
s = log[at:]
|
|
79
|
+
|
|
80
|
+
def num(pattern: str) -> float:
|
|
81
|
+
m = re.search(pattern, s)
|
|
82
|
+
return float(m.group(1)) if m else -math.inf
|
|
83
|
+
short = [float(x) for x in re.findall(r"\bS:\s*(-?[\d.]+)", log[:at])]
|
|
84
|
+
return {"lufs": num(r"I:\s+(-?[\d.]+|-inf) LUFS"), "peak": num(r"Sample peak:\s+Peak:\s+(-?[\d.]+|-inf)"),
|
|
85
|
+
"true_peak": num(r"True peak:\s+Peak:\s+(-?[\d.]+|-inf)"), "lra": num(r"LRA:\s+(-?[\d.]+) LU"),
|
|
86
|
+
"short_max": max((x for x in short if x > -70), default=-math.inf)}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def level(role: str, info: dict, levels: dict) -> float:
|
|
90
|
+
"""dB that sets a sound to its role's level, between -40 and +24; 0 for a silent file."""
|
|
91
|
+
if role == "sfx":
|
|
92
|
+
ref = info["peak"]
|
|
93
|
+
else: # under 0.4 s ebur128 reports -70 LUFS: use the mean power instead
|
|
94
|
+
ref = info["lufs"] if info["lufs"] > -69.9 else info["power"]
|
|
95
|
+
if not math.isfinite(ref) or ref < -90:
|
|
96
|
+
return 0.0
|
|
97
|
+
return max(-40.0, min(24.0, levels[role] - ref))
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def correction(measured: dict, target: float) -> float:
|
|
101
|
+
"""dB that brings the whole mix to the target loudness, between -20 and +12; 0 for a silent mix."""
|
|
102
|
+
i = measured["lufs"]
|
|
103
|
+
return max(-20.0, min(12.0, target - i)) if i > -69.9 else 0.0
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def duck_curve(voices: list[tuple[float, float, np.ndarray, float]], duration: float, cfg: dict) -> np.ndarray:
|
|
107
|
+
"""Linear gain at RATE over the scene, plus a spare second, for the sounds that duck. It is 1, and -depth dB
|
|
108
|
+
while a voice speaks: the fall starts `attack` seconds before the voice, so the music is already down for the
|
|
109
|
+
first syllable; pauses shorter than `hold` stay down; the rise takes `release` seconds.
|
|
110
|
+
voices: (start, end, RMS in dBFS per 20 ms window from the start, gain in dB applied to the voice)."""
|
|
111
|
+
n = int(math.ceil(duration * RATE)) + RATE
|
|
112
|
+
active = np.zeros(n, bool)
|
|
113
|
+
per = int(RATE * _WIN)
|
|
114
|
+
for t0, t1, rms, gain in voices:
|
|
115
|
+
on = np.repeat(rms + gain > SPEECH, per)
|
|
116
|
+
a, b = max(0, int(round(t0 * RATE))), min(n, int(round(t1 * RATE)))
|
|
117
|
+
m = min(b - a, len(on))
|
|
118
|
+
if m > 0:
|
|
119
|
+
active[a:a + m] |= on[:m]
|
|
120
|
+
hold = int(cfg["hold"] * RATE)
|
|
121
|
+
if hold:
|
|
122
|
+
active = np.convolve(active, np.ones(hold + 1), "full")[:n] > 0
|
|
123
|
+
depth = float(cfg["depth"])
|
|
124
|
+
d, idx = np.where(active, depth, 0.0), np.arange(n)
|
|
125
|
+
up = depth / max(1.0, cfg["release"] * RATE)
|
|
126
|
+
d = np.maximum.accumulate(d + up * idx) - up * idx # after each stretch, rise over `release`
|
|
127
|
+
down = depth / max(1.0, cfg["attack"] * RATE)
|
|
128
|
+
d = (np.maximum.accumulate(d[::-1] + down * idx) - down * idx)[::-1] # before each, fall over `attack`
|
|
129
|
+
return 10 ** (-np.clip(d, 0.0, depth) / 20)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def gain_curve(raw, dur: float, start: float, fps: float) -> np.ndarray:
|
|
133
|
+
"""A sound's keyframed or expression gain (dB, timed from the sound's start) as linear gain at RATE, plus a
|
|
134
|
+
spare second. Sampled at 100 Hz and interpolated: gain moves slowly next to the audio."""
|
|
135
|
+
prop = compile_prop("gain", raw, Ctx(1, 1, fps))
|
|
136
|
+
ts = np.linspace(0.0, dur, max(2, int(math.ceil(dur * 100)) + 1))
|
|
137
|
+
db = np.array([float(prop.at(t, dur, start + t, 0)) for t in ts])
|
|
138
|
+
n = int(math.ceil(dur * RATE)) + RATE
|
|
139
|
+
return 10 ** (np.interp(np.arange(n) / RATE, ts, db) / 20)
|
|
@@ -30,7 +30,8 @@ def main(argv=None) -> int:
|
|
|
30
30
|
ap.add_argument("--version", action="version", version=f"kinescript {__version__}")
|
|
31
31
|
sub = ap.add_subparsers(dest="cmd", required=True)
|
|
32
32
|
|
|
33
|
-
r = sub.add_parser("render", help="render a scene to .mp4/.mov/.webm/.gif or a .png sequence"
|
|
33
|
+
r = sub.add_parser("render", help="render a scene to .mp4/.mov/.webm/.gif or a .png sequence, or its sound "
|
|
34
|
+
"alone to .wav/.m4a/.mp3/.flac")
|
|
34
35
|
r.add_argument("scene")
|
|
35
36
|
r.add_argument("-o", "--out")
|
|
36
37
|
r.add_argument("-q", "--quality", choices=["draft", "standard", "high"], default="standard")
|
|
@@ -53,9 +54,11 @@ def main(argv=None) -> int:
|
|
|
53
54
|
lk.add_argument("--width", type=int, default=480, help="width of each thumbnail")
|
|
54
55
|
lk.add_argument("--at", type=float, nargs="*", help="explicit times instead of even spacing")
|
|
55
56
|
lk.add_argument("--boxes", action="store_true", help="outline every layer with its id")
|
|
57
|
+
lk.add_argument("--audio", action="store_true", help="draw the sound under the frames (a lane per role and the "
|
|
58
|
+
"mix, with levels, the duck and issues) and print its measurements")
|
|
56
59
|
lk.add_argument("-o", "--out")
|
|
57
60
|
|
|
58
|
-
ck = sub.add_parser("check", help="lint layout, timing, contrast
|
|
61
|
+
ck = sub.add_parser("check", help="lint layout, timing, contrast, reading time and sound; prints JSON")
|
|
59
62
|
ck.add_argument("scene")
|
|
60
63
|
ck.add_argument("--step", type=float, default=0.25)
|
|
61
64
|
|
|
@@ -64,6 +67,13 @@ def main(argv=None) -> int:
|
|
|
64
67
|
pr.add_argument("scene")
|
|
65
68
|
pr.add_argument("--at", type=float)
|
|
66
69
|
|
|
70
|
+
v = sub.add_parser("voice", help="speak each sound's text into its file and time its words (only the ones "
|
|
71
|
+
"whose text changed, unless --force)")
|
|
72
|
+
v.add_argument("scene")
|
|
73
|
+
v.add_argument("--only", nargs="+", metavar="ID", help="speak just these sounds")
|
|
74
|
+
v.add_argument("--force", action="store_true", help="speak them again even if their text did not change")
|
|
75
|
+
v.add_argument("--backend", help="which installed voice backend to use, when there are several")
|
|
76
|
+
|
|
67
77
|
sub.add_parser("docs", help="print the scene reference")
|
|
68
78
|
nw = sub.add_parser("new", help="write a starter scene")
|
|
69
79
|
nw.add_argument("path", nargs="?", default="scene.json")
|
|
@@ -129,7 +139,11 @@ def _run(a) -> int:
|
|
|
129
139
|
if a.cmd == "look":
|
|
130
140
|
from .verify import contact_sheet
|
|
131
141
|
out = a.out or _default_out(a.scene, "_sheet.png")
|
|
132
|
-
_emit(dict(ok=True, **contact_sheet(a.scene, out, a.count, a.cols, a.width, a.at, a.boxes)))
|
|
142
|
+
_emit(dict(ok=True, **contact_sheet(a.scene, out, a.count, a.cols, a.width, a.at, a.boxes, a.audio)))
|
|
143
|
+
return 0
|
|
144
|
+
if a.cmd == "voice":
|
|
145
|
+
from .voice import generate
|
|
146
|
+
_emit(generate(a.scene, a.only, a.force, a.backend))
|
|
133
147
|
return 0
|
|
134
148
|
if a.cmd == "check":
|
|
135
149
|
from .verify import check
|
|
@@ -129,7 +129,7 @@ COMPONENT_DOCS = {
|
|
|
129
129
|
"kinetic": "words [list], every [0.6] (seconds per word), size [180], motion [pop], color, x, y [\"50%\"] (centre)",
|
|
130
130
|
}
|
|
131
131
|
_PASS = ("id", "at", "dur", "until", "enter", "exit", "opacity", "scale", "rotate", "hidden", "z", "rotateX", "rotateY",
|
|
132
|
-
"fixed")
|
|
132
|
+
"fixed", "sound")
|
|
133
133
|
|
|
134
134
|
|
|
135
135
|
class Params(dict):
|