Metadata-Version: 2.5
Name: kazesynth
Version: 0.1.0a4
Summary: A terminal UI and CLI to queue and run VapourSynth encodes.
Author-email: Vardë <ichunjo.le.terrible@gmail.com>
License-Expression: EUPL-1.2
License-File: LICENSE
Keywords: cli,encoding,job-queue,kaze,textual,tui,vapoursynth,video,x265
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: End Users/Desktop
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Multimedia :: Video
Classifier: Topic :: Multimedia :: Video :: Conversion
Classifier: Typing :: Typed
Requires-Python: >=3.15
Requires-Dist: cyclopts>=5.5.3
Requires-Dist: platformdirs>=4.14.8
Requires-Dist: textual>=8.2.8
Requires-Dist: tomlkit>=0.15.3
Description-Content-Type: text/markdown

# Kazé

<div align="center">
  <img src="https://raw.githubusercontent.com/Ichunjo/kazesynth/refs/heads/master/assets/home.svg" height="500"/>

A lightweight terminal UI for queuing and managing VapourSynth encode jobs.
</div>

## Installation

```bash
uv tool install --python 3.15 kazesynth
```

## Examples

The [examples](https://github.com/Ichunjo/kazesynth/tree/master/examples) folder has small projects, from one job file to a whole season with a job template.
Each one has a README that explains its files.

## TUI

```bash
kaze
```

## Job files and CLI

`kaze template ep01.toml` writes a job file with comments that list every field.
See [01-single-job](https://github.com/Ichunjo/kazesynth/tree/master/examples/01-single-job) and [02-movie](https://github.com/Ichunjo/kazesynth/tree/master/examples/02-movie) for full projects.

### Example

```toml
script = "ep01.vpy"

[[track]]
node = "last" # the last video output; or an index, as in set_output()
preset = "x265-slow" # from <config>/presets/x265-slow.toml
options = { crf = 16 } # optional: replaces crf from the preset

[[track]]
node = "first" # the first audio output
tool = "flac"

[mux]
output = "Episode 01.mkv"
chapters = "chapters.xml" # optional: XML or OGM text
attachments = ["fonts/*"] # optional: files to attach; * and ? work in the file name
```

### CLI

```bash
kaze run ep01.toml          # add the job and run the queue until it is idle
kaze run --background       # the same, in a background process
kaze add ep02.toml --queue night
kaze jobs
kaze cancel 3
kaze retry 3                # done tasks are skipped
kaze stop                   # stop the process that runs jobs
```

`kaze --help` lists all the commands. Only one Kazé process runs jobs at a time, and the TUI and the other commands talk to it.

In the TUI, `/import` adds a job file. It asks for the file, then for the queue, like `kaze add FILE --queue NAME`.

The settings live in `<config>/settings.toml`.
`<config>` is the user config folder that [platformdirs](https://platformdirs.readthedocs.io) gives for `kazesynth`:

| OS      | `<config>`                                             |
| ------- | ------------------------------------------------------ |
| Windows | `%LOCALAPPDATA%\kazesynth`                             |
| macOS   | `~/Library/Application Support/kazesynth`              |
| Linux   | `$XDG_CONFIG_HOME/kazesynth`, or `~/.config/kazesynth` |

To keep all Kazé files in one folder, set `KAZE_HOME`. Then `<config>` is `$KAZE_HOME/config`.

## Job templates

A project file can also have job templates, so you do not write one job file for each episode.
A job template is a job file in a `[jobs.<name>]` table, with `{name}` placeholders in its strings:

```toml
# kaze.toml
[jobs.show]
name = "Show - {ep}"
script = "ep{ep}.py"
queue = "night" # optional: the queue for these jobs
# args = { episode = "{ep}" } # for one script that gets the episode as an argument

[[jobs.show.track]]
node = 0
preset = "x265-show"

[jobs.show.mux]
output = "out/Show - {ep}.mkv"
```

```bash
kaze add show ep=01..12        # 12 jobs; "01" sets the zero padding
kaze add show ep=01..03,07,SP  # ranges and values can mix
kaze add show ep=01..12 ver=v2 # a key with one value gives it to every job
kaze add show                  # find ep from the files that match script
kaze run show ep=05            # kaze run accepts the same items
```

- `kaze add` and `kaze run` look for templates in the project of the current folder.
  You can mix job files and templates in one command.
- Without values, Kazé finds them from the files that match `script`, in natural order (`2` before `10`).
  A placeholder matches any text, so use a pattern that only matches episode scripts: `ep{ep}.py` or `{ep}/main.py`, not `{ep}.py` next to `common.py`.
- Every placeholder needs values, and every key must be a placeholder of the template. A typo is an error.
- Without `name`, a job is named after the template and its values, like `show_01`.
- The queue is `--queue`, then the `queue` of the template, then the default queue.
- `{{` and `}}` give literal braces.
- The values are copied into each job when you add it, like presets.

In the TUI, `/batch` shows the jobs of a template before it adds them, and you can skip the ones you do not want.

## Project presets

A project can have its own presets.
You write them in a `kaze.toml` file, or in the `[tool.kaze.presets.<name>]` tables of `pyproject.toml`:

```toml
# kaze.toml
[presets.x265-show]
tool = "x265"
options = { crf = 15, preset = "slower" }
```

A project preset can build on a global preset, like a job track can:

```toml
[presets.x265-slow]
preset = "x265-slow" # the global preset with the same name, or any other global preset
options = { crf = 20 } # replaces only crf
```

`options` replace the options with the same name and `extra_args` come after the arguments of the global preset.
The base must be a global preset, not another project preset.
A change to the global preset also changes the project presets built on it.

- Project presets are copied into the job when you add it, like global presets. Editing the file later does not change queued jobs.
- The TUI uses the project of the folder you open it in, for `/presets` and `/new`.
  `/presets` shows where each preset comes from, and you can copy a project preset to a global preset there.

  To change or delete a project preset, you must edit the file. Kazé never writes to it.

See [03-series](https://github.com/Ichunjo/kazesynth/tree/master/examples/03-series) for a `kaze.toml` project and [04-pyproject](https://github.com/Ichunjo/kazesynth/tree/master/examples/04-pyproject) for a `pyproject.toml` project.

## Where Kazé looks

| What           | Where                                                                                                                        |
| -------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| Python         | `python` in the job, a `.venv` or `venv` next to the script or in a parent, the last one used there, then `default_python`   |
| Encoder binary | `binary` in the track or preset, then `[tools]` in the settings, then PATH                                                   |
| Presets        | the project file, then `<config>/presets`                                                                                    |
| Project file   | the folder of the job file (the current folder for templates and the TUI), then parents; `kaze.toml` before `pyproject.toml` |
| Relative paths | the folder of the file that has them: the job file, the preset or the project file                                           |
| Script paths   | the folder of the script, because Kazé runs the script there                                                                 |

A `binary` with a folder part, like `tools/x265.exe`, is a path.
A name without a folder, like `x265-mod`, is found in PATH.
In the TUI, Settings lists each tool and shows whether Kazé can find it.

## Flags added for x264 and x265

Kazé reads the props of frame 0 and adds these flags:

| Flag                        | From                                                     |
| --------------------------- | -------------------------------------------------------- |
| `--output-depth`            | the bit depth of the clip                                |
| `--colormatrix`             | `_Matrix`                                                |
| `--transfer`                | `_Transfer`                                              |
| `--colorprim`               | `_Primaries`                                             |
| `--range`                   | `_Range` (`tv`/`pc` for x264, `limited`/`full` for x265) |
| `--input-range` (x264 only) | `_Range`                                                 |
| `--chromaloc`               | `_ChromaLocation`                                        |
| `--sar`                     | `_SARNum` and `_SARDen`                                  |

- A flag you set yourself always wins. `-D` counts as `--output-depth`.
- A missing or unspecified prop sends nothing. Kazé never guesses.
- If you set `--input-range` for x264, Kazé does not send `--range` either.

### Zones

A script can give frame ranges their own rate control with a `KAZE_ZONES` variable.
Kazé sends them to x264 and x265 as `--zones`.

```python
# A list applies to all video outputs.
KAZE_ZONES = [
    (1200, 1450, {"b": 1.5}),  # 1.5 times the bitrate
    (30000, 30200, {"q": 14}),  # a fixed QP of 14
]

# A dict sets the zones of each output.
KAZE_ZONES = {0: [(1200, 1450, {"b": 1.5})]}
```

- Each zone is `(start, end, {"b": number})` or `(start, end, {"q": integer})`.
  `end` is the last frame of the zone.
- The frame numbers are those of the output, after any trim in the script.
- Zones must not overlap. Their order does not matter.
- Kazé reads the zones when the job starts, so a change to the script applies to the next run.
- An invalid zone fails the job with a message, before the encode starts.
- A `--zones` that you set yourself wins.
