kazesynth 0.1.0a0__py3-none-any.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.
Files changed (80) hide show
  1. kazesynth/__init__.py +1 -0
  2. kazesynth/__main__.py +5 -0
  3. kazesynth/adapters/__init__.py +19 -0
  4. kazesynth/adapters/base.py +178 -0
  5. kazesynth/adapters/flac.py +57 -0
  6. kazesynth/adapters/mkvmerge.py +63 -0
  7. kazesynth/adapters/opusenc.py +56 -0
  8. kazesynth/adapters/qaac.py +59 -0
  9. kazesynth/adapters/x264.py +97 -0
  10. kazesynth/adapters/x265.py +111 -0
  11. kazesynth/adapters/x26x.py +136 -0
  12. kazesynth/cli/__init__.py +50 -0
  13. kazesynth/cli/cmd/__init__.py +0 -0
  14. kazesynth/cli/cmd/add.py +29 -0
  15. kazesynth/cli/cmd/cancel.py +43 -0
  16. kazesynth/cli/cmd/daemon.py +40 -0
  17. kazesynth/cli/cmd/encode.py +97 -0
  18. kazesynth/cli/cmd/env.py +17 -0
  19. kazesynth/cli/cmd/export.py +28 -0
  20. kazesynth/cli/cmd/jobs.py +37 -0
  21. kazesynth/cli/cmd/probe.py +25 -0
  22. kazesynth/cli/cmd/queue.py +52 -0
  23. kazesynth/cli/cmd/remove.py +31 -0
  24. kazesynth/cli/cmd/retry.py +23 -0
  25. kazesynth/cli/cmd/run.py +50 -0
  26. kazesynth/cli/cmd/stop.py +18 -0
  27. kazesynth/cli/cmd/template.py +25 -0
  28. kazesynth/cli/cmd/tui.py +13 -0
  29. kazesynth/cli/helpers.py +125 -0
  30. kazesynth/client.py +310 -0
  31. kazesynth/config.py +408 -0
  32. kazesynth/control.py +185 -0
  33. kazesynth/envs.py +92 -0
  34. kazesynth/exception.py +18 -0
  35. kazesynth/jobfile.py +256 -0
  36. kazesynth/lock.py +59 -0
  37. kazesynth/model.py +123 -0
  38. kazesynth/paths.py +60 -0
  39. kazesynth/runner.py +388 -0
  40. kazesynth/scheduler.py +492 -0
  41. kazesynth/schema.sql +31 -0
  42. kazesynth/server.py +304 -0
  43. kazesynth/store.py +253 -0
  44. kazesynth/tools.py +24 -0
  45. kazesynth/types.py +3 -0
  46. kazesynth/ui/__init__.py +3 -0
  47. kazesynth/ui/app.py +220 -0
  48. kazesynth/ui/app.tcss +120 -0
  49. kazesynth/ui/base.py +152 -0
  50. kazesynth/ui/commands.py +40 -0
  51. kazesynth/ui/dialogs.py +134 -0
  52. kazesynth/ui/dialogs.tcss +20 -0
  53. kazesynth/ui/live.py +72 -0
  54. kazesynth/ui/screens/__init__.py +0 -0
  55. kazesynth/ui/screens/jobs.py +349 -0
  56. kazesynth/ui/screens/jobs.tcss +31 -0
  57. kazesynth/ui/screens/menu.py +79 -0
  58. kazesynth/ui/screens/menu.tcss +27 -0
  59. kazesynth/ui/screens/new_job.py +617 -0
  60. kazesynth/ui/screens/new_job.tcss +16 -0
  61. kazesynth/ui/screens/presets.py +412 -0
  62. kazesynth/ui/screens/queues.py +125 -0
  63. kazesynth/ui/screens/settings.py +97 -0
  64. kazesynth/workerio.py +134 -0
  65. kazesynth/workerpkg.py +53 -0
  66. kazesynth-0.1.0a0.dist-info/METADATA +144 -0
  67. kazesynth-0.1.0a0.dist-info/RECORD +80 -0
  68. kazesynth-0.1.0a0.dist-info/WHEEL +4 -0
  69. kazesynth-0.1.0a0.dist-info/entry_points.txt +2 -0
  70. kazesynth-0.1.0a0.dist-info/licenses/LICENSE +291 -0
  71. kazesynth_worker/__init__.py +5 -0
  72. kazesynth_worker/__main__.py +78 -0
  73. kazesynth_worker/commands.py +182 -0
  74. kazesynth_worker/exception.py +1 -0
  75. kazesynth_worker/protocol.py +187 -0
  76. kazesynth_worker/pyrefly.toml +9 -0
  77. kazesynth_worker/script.py +98 -0
  78. kazesynth_worker/streams.py +104 -0
  79. kazesynth_worker/wave.py +61 -0
  80. kazesynth_worker/y4m.py +15 -0
kazesynth/__init__.py ADDED
@@ -0,0 +1 @@
1
+ """A terminal UI to manage VapourSynth encode jobs."""
kazesynth/__main__.py ADDED
@@ -0,0 +1,5 @@
1
+ import sys
2
+
3
+ from .cli import main
4
+
5
+ sys.exit(main())
@@ -0,0 +1,19 @@
1
+ from .base import Adapter, EncoderProgress, OptionKind, OptionSpec, OptionValue, flag, options_to_args
2
+ from .flac import Flac
3
+ from .opusenc import Opusenc
4
+ from .qaac import Qaac
5
+ from .x264 import X264
6
+ from .x265 import X265
7
+
8
+ ADAPTERS: dict[str, Adapter] = {adapter.name: adapter for adapter in (X265(), X264(), Flac(), Opusenc(), Qaac())}
9
+
10
+ __all__ = [
11
+ "ADAPTERS",
12
+ "Adapter",
13
+ "EncoderProgress",
14
+ "OptionKind",
15
+ "OptionSpec",
16
+ "OptionValue",
17
+ "flag",
18
+ "options_to_args",
19
+ ]
@@ -0,0 +1,178 @@
1
+ """
2
+ Common parts of the encoder adapters.
3
+
4
+ An adapter builds the command line of one tool and reads its stderr.
5
+ """
6
+
7
+ import re
8
+ from abc import ABC, abstractmethod
9
+ from collections.abc import Mapping, Sequence
10
+ from enum import StrEnum
11
+ from pathlib import Path
12
+ from typing import ClassVar, NamedTuple
13
+
14
+ from kazesynth_worker.protocol import NodeInfo, OutputFormat
15
+
16
+ type OptionValue = str | int | float | bool | None
17
+
18
+
19
+ class EncoderProgress(NamedTuple):
20
+ frame: int
21
+ total: int | None
22
+ fps: float | None
23
+ bitrate_kbps: float | None
24
+ eta: str | None
25
+
26
+
27
+ class OptionKind(StrEnum):
28
+ BOOL = "bool"
29
+ INT = "int"
30
+ FLOAT = "float"
31
+ TEXT = "text"
32
+
33
+
34
+ class OptionSpec(NamedTuple):
35
+ """
36
+ One option of a tool that the preset editor shows as a row.
37
+
38
+ ``name`` is the key in the preset file.
39
+ It is also the CLI name without ``--``, unless ``template`` is set.
40
+ """
41
+
42
+ name: str
43
+ kind: OptionKind
44
+ default: OptionValue
45
+ """The value of a new preset. None leaves the option unset."""
46
+ help: str
47
+ choices: tuple[tuple[OptionValue, str], ...] = ()
48
+ """(value, label) pairs the editor offers. The label may be empty. Other values stay allowed."""
49
+ true_args: tuple[str, ...] = ()
50
+ """Bool options only: the arguments for true."""
51
+ false_args: tuple[str, ...] = ()
52
+ """Bool options only: the arguments for false."""
53
+ template: str = ""
54
+ """
55
+ For tools that put the value in the flag itself: one argument, with ``{}`` for the value.
56
+
57
+ For example ``"--compression-level-{}"`` gives ``--compression-level-8``.
58
+ """
59
+
60
+
61
+ def flag(name: str, default: bool | None, help: str, *, true_flag: bool = True, false_flag: bool = True) -> OptionSpec:
62
+ """
63
+ A bool option: true gives ``--name``, false gives ``--no-name``.
64
+
65
+ Set ``true_flag`` or ``false_flag`` to False when the tool has no such flag.
66
+ That value then sends nothing, so the tool must already use it by default.
67
+ """
68
+ return OptionSpec(
69
+ name,
70
+ OptionKind.BOOL,
71
+ default,
72
+ help,
73
+ true_args=(f"--{name}",) if true_flag else (),
74
+ false_args=(f"--no-{name}",) if false_flag else (),
75
+ )
76
+
77
+
78
+ def options_to_args(options: Mapping[str, OptionValue], known: Sequence[OptionSpec] = ()) -> list[str]:
79
+ """
80
+ Turn ``{"preset": "slow", "crf": 18, "no-sao": True}`` into CLI arguments.
81
+
82
+ Known options use their own flags and templates.
83
+ For other options, ``True`` gives a bare flag, and ``False`` and ``None`` are skipped.
84
+ """
85
+ specs = {spec.name: spec for spec in known}
86
+ args: list[str] = []
87
+ for key, value in options.items():
88
+ spec = specs.get(key)
89
+ if spec is not None and spec.kind is OptionKind.BOOL and isinstance(value, bool):
90
+ args.extend(spec.true_args if value else spec.false_args)
91
+ continue
92
+ if spec is not None and spec.template and value is not None and not isinstance(value, bool):
93
+ args.append(spec.template.format(value))
94
+ continue
95
+ if value is None or value is False:
96
+ continue
97
+ option = key if key.startswith("-") else f"--{key}"
98
+ args.append(option)
99
+ if value is not True:
100
+ args.append(str(value))
101
+ return args
102
+
103
+
104
+ class Adapter(ABC):
105
+ name: ClassVar[str]
106
+ input_format: ClassVar[OutputFormat]
107
+ default_binary: ClassVar[str]
108
+ extension: ClassVar[str]
109
+ known_options: ClassVar[tuple[OptionSpec, ...]] = ()
110
+ """The options the preset editor shows as rows, in display order."""
111
+
112
+ @property
113
+ def is_video(self) -> bool:
114
+ return self.input_format is OutputFormat.Y4M
115
+
116
+ @abstractmethod
117
+ def build_args(
118
+ self,
119
+ binary: str,
120
+ output: Path,
121
+ node: NodeInfo,
122
+ *,
123
+ options: Mapping[str, OptionValue],
124
+ extra_args: Sequence[str],
125
+ ) -> list[str]:
126
+ """Return the full command line. The input is always stdin."""
127
+
128
+ def parse_line(self, line: str) -> EncoderProgress | None:
129
+ """Return progress if the line is a progress line, else None."""
130
+ return None
131
+
132
+ def recommended_options(self) -> dict[str, OptionValue]:
133
+ """The options of a new preset, or of "tool with recommended options" in a new job."""
134
+ return {spec.name: spec.default for spec in self.known_options if spec.default is not None}
135
+
136
+
137
+ X26X_PRESETS: tuple[tuple[OptionValue, str], ...] = (
138
+ ("ultrafast", ""),
139
+ ("superfast", ""),
140
+ ("veryfast", ""),
141
+ ("faster", ""),
142
+ ("fast", ""),
143
+ ("medium", ""),
144
+ ("slow", ""),
145
+ ("slower", ""),
146
+ ("veryslow", ""),
147
+ ("placebo", ""),
148
+ )
149
+
150
+ # x264 and x265 print the same progress line format.
151
+ X26X_PROGRESS = re.compile(
152
+ r"^\[(?P<pct>[\d.]+)%\]\s+(?P<frame>\d+)/(?P<total>\d+) frames, (?P<fps>[\d.]+) fps, "
153
+ r"(?P<kbps>[\d.]+) kb/s(?:, eta (?P<eta>[\d:]+))?"
154
+ )
155
+ X26X_PROGRESS_NO_TOTAL = re.compile(r"^(?P<frame>\d+) frames: (?P<fps>[\d.]+) fps, (?P<kbps>[\d.]+) kb/s")
156
+
157
+
158
+ def parse_x26x_progress(line: str) -> EncoderProgress | None:
159
+ line = line.strip()
160
+ match = X26X_PROGRESS.match(line)
161
+ if match:
162
+ return EncoderProgress(
163
+ frame=int(match["frame"]),
164
+ total=int(match["total"]),
165
+ fps=float(match["fps"]),
166
+ bitrate_kbps=float(match["kbps"]),
167
+ eta=match["eta"],
168
+ )
169
+ match = X26X_PROGRESS_NO_TOTAL.match(line)
170
+ if match:
171
+ return EncoderProgress(
172
+ frame=int(match["frame"]),
173
+ total=None,
174
+ fps=float(match["fps"]),
175
+ bitrate_kbps=float(match["kbps"]),
176
+ eta=None,
177
+ )
178
+ return None
@@ -0,0 +1,57 @@
1
+ """The flac adapter and the options the preset editor shows for it."""
2
+
3
+ import os
4
+ from collections.abc import Mapping, Sequence
5
+ from pathlib import Path
6
+
7
+ from kazesynth_worker.protocol import NodeInfo, OutputFormat
8
+
9
+ from .base import Adapter, OptionKind, OptionSpec, OptionValue, flag, options_to_args
10
+
11
+
12
+ class Flac(Adapter):
13
+ name = "flac"
14
+ input_format = OutputFormat.W64
15
+ default_binary = "flac"
16
+ extension = ".flac"
17
+ # flac applies its arguments from left to right. The compression level comes first,
18
+ # so the rows after it change the settings the level chose.
19
+ known_options = (
20
+ OptionSpec(
21
+ "compression-level",
22
+ OptionKind.INT,
23
+ 8,
24
+ "Compression level. Higher is smaller and slower",
25
+ ((0, "fastest"), (1, ""), (2, ""), (3, ""), (4, ""), (5, "flac default"), (6, ""), (7, ""), (8, "best")),
26
+ template="--compression-level-{}",
27
+ ),
28
+ OptionSpec("blocksize", OptionKind.INT, None, "Block size in samples"),
29
+ OptionSpec("max-lpc-order", OptionKind.INT, None, "Maximum LPC order. 0 uses only fixed predictors"),
30
+ OptionSpec("apodization", OptionKind.TEXT, None, 'Window functions, for example "subdivide_tukey(3)"'),
31
+ flag("exhaustive-model-search", None, "Search all models. Slow"),
32
+ # The "off" flag is spelled --no-qlp-coeff-prec-search, and off is the default anyway.
33
+ flag("qlp-coeff-precision-search", None, "Search all LP coefficient precisions. Slow", false_flag=False),
34
+ flag("lax", None, "Allow files outside the FLAC subset"),
35
+ flag("verify", True, "Decode the output again and compare"),
36
+ OptionSpec("threads", OptionKind.INT, (os.cpu_count() or 2) // 2, "Encoding threads"),
37
+ )
38
+
39
+ def build_args(
40
+ self,
41
+ binary: str,
42
+ output: Path,
43
+ node: NodeInfo,
44
+ *,
45
+ options: Mapping[str, OptionValue],
46
+ extra_args: Sequence[str],
47
+ ) -> list[str]:
48
+ return [
49
+ binary,
50
+ "--silent",
51
+ "--force",
52
+ *options_to_args(options, self.known_options),
53
+ *extra_args,
54
+ "--output-name",
55
+ str(output),
56
+ "-",
57
+ ]
@@ -0,0 +1,63 @@
1
+ import re
2
+ from collections.abc import Sequence
3
+ from fractions import Fraction
4
+ from pathlib import Path
5
+ from typing import NamedTuple
6
+
7
+ from ..model import MuxSpec, TrackMeta
8
+
9
+ DEFAULT_BINARY = "mkvmerge"
10
+ SUCCESS_EXIT_CODES = frozenset({0, 1})
11
+ PROGRESS = re.compile(r"^#GUI#progress (\d+)%")
12
+
13
+
14
+ class MuxTrack(NamedTuple):
15
+ path: Path
16
+ meta: TrackMeta
17
+ fps: Fraction | None = None
18
+
19
+
20
+ def build_args(binary: str, spec: MuxSpec, tracks: Sequence[MuxTrack]) -> list[str]:
21
+ args = [binary, "--gui-mode", "--output", str(spec.output)]
22
+ if spec.title is not None:
23
+ args += ["--title", spec.title]
24
+ args += spec.extra_args
25
+ for track in tracks:
26
+ args += _meta_args(0, track.meta)
27
+ if track.fps is not None:
28
+ # Raw streams may lack timing info. The probed frame rate is always right.
29
+ args += ["--default-duration", f"0:{track.fps.numerator}/{track.fps.denominator}p"]
30
+ args.append(str(track.path))
31
+ for extra in spec.extra_inputs:
32
+ args += _meta_args(extra.track, extra.meta)
33
+ args += extra.args
34
+ args.append(str(extra.path))
35
+ return args
36
+
37
+
38
+ def parse_progress(line: str) -> int | None:
39
+ """Return the percentage of a ``#GUI#progress`` line, else None."""
40
+ match = PROGRESS.match(line)
41
+ return int(match[1]) if match else None
42
+
43
+
44
+ def clean_message(line: str) -> str:
45
+ """Turn ``#GUI#error text`` into ``error: text``; leave other lines unchanged."""
46
+ for kind in ("error", "warning"):
47
+ prefix = f"#GUI#{kind} "
48
+ if line.startswith(prefix):
49
+ return f"{kind}: {line[len(prefix) :]}"
50
+ return line
51
+
52
+
53
+ def _meta_args(track_id: int, meta: TrackMeta) -> list[str]:
54
+ args: list[str] = []
55
+ if meta.language is not None:
56
+ args += ["--language", f"{track_id}:{meta.language}"]
57
+ if meta.name is not None:
58
+ args += ["--track-name", f"{track_id}:{meta.name}"]
59
+ if meta.default is not None:
60
+ args += ["--default-track-flag", f"{track_id}:{'yes' if meta.default else 'no'}"]
61
+ if meta.forced is not None:
62
+ args += ["--forced-display-flag", f"{track_id}:{'yes' if meta.forced else 'no'}"]
63
+ return args
@@ -0,0 +1,56 @@
1
+ """The opusenc adapter and the options the preset editor shows for it."""
2
+
3
+ from collections.abc import Mapping, Sequence
4
+ from pathlib import Path
5
+
6
+ from kazesynth_worker.protocol import NodeInfo, OutputFormat
7
+
8
+ from .base import Adapter, OptionKind, OptionSpec, OptionValue, flag, options_to_args
9
+
10
+
11
+ class Opusenc(Adapter):
12
+ name = "opusenc"
13
+ input_format = OutputFormat.WAV
14
+ default_binary = "opusenc"
15
+ extension = ".opus"
16
+ known_options = (
17
+ OptionSpec("bitrate", OptionKind.FLOAT, 192.0, "Target bitrate in kbit/s (6 to 256 per channel)"),
18
+ OptionSpec(
19
+ "bitrate-mode",
20
+ OptionKind.TEXT,
21
+ "vbr",
22
+ "How the bitrate is used",
23
+ (("vbr", "variable"), ("cvbr", "constrained variable"), ("hard-cbr", "constant")),
24
+ template="--{}",
25
+ ),
26
+ OptionSpec("comp", OptionKind.INT, 10, "Complexity (0 to 10). Higher is better and slower"),
27
+ OptionSpec(
28
+ "framesize",
29
+ OptionKind.TEXT,
30
+ None,
31
+ "Maximum frame size in milliseconds",
32
+ (("2.5", ""), ("5", ""), ("10", ""), ("20", "opusenc default"), ("40", ""), ("60", "")),
33
+ ),
34
+ OptionSpec(
35
+ "tune",
36
+ OptionKind.TEXT,
37
+ None,
38
+ "Tune low bitrates. Unset: detect",
39
+ (("music", ""), ("speech", "")),
40
+ template="--{}",
41
+ ),
42
+ flag("phase-inv", None, "Phase inversion for intensity stereo", true_flag=False),
43
+ flag("downmix-stereo", None, "Downmix to stereo when there are more than 2 channels", false_flag=False),
44
+ OptionSpec("max-delay", OptionKind.INT, None, "Maximum container delay in milliseconds (0 to 1000)"),
45
+ )
46
+
47
+ def build_args(
48
+ self,
49
+ binary: str,
50
+ output: Path,
51
+ node: NodeInfo,
52
+ *,
53
+ options: Mapping[str, OptionValue],
54
+ extra_args: Sequence[str],
55
+ ) -> list[str]:
56
+ return [binary, "--ignorelength", *options_to_args(options, self.known_options), *extra_args, "-", str(output)]
@@ -0,0 +1,59 @@
1
+ from collections.abc import Mapping, Sequence
2
+ from pathlib import Path
3
+
4
+ from kazesynth_worker.protocol import NodeInfo, OutputFormat
5
+
6
+ from .base import Adapter, OptionKind, OptionSpec, OptionValue, flag, options_to_args
7
+
8
+
9
+ class Qaac(Adapter):
10
+ name = "qaac"
11
+ input_format = OutputFormat.WAV
12
+ default_binary = "qaac64"
13
+ extension = ".m4a"
14
+ # tvbr, cvbr, abr and cbr are the rate control modes. Set only one of them.
15
+ known_options = (
16
+ OptionSpec("tvbr", OptionKind.INT, 127, "True VBR quality (0 to 127). Set only one mode"),
17
+ OptionSpec("cvbr", OptionKind.INT, None, "Constrained VBR bitrate in kbit/s, 0 for the highest"),
18
+ OptionSpec("abr", OptionKind.INT, None, "Average bitrate in kbit/s, 0 for the highest"),
19
+ OptionSpec("cbr", OptionKind.INT, None, "Constant bitrate in kbit/s, 0 for the highest"),
20
+ flag("he", None, "HE-AAC (not with tvbr)", false_flag=False),
21
+ OptionSpec("quality", OptionKind.INT, 2, "Encoder quality", ((0, "fastest"), (1, ""), (2, "best"))),
22
+ OptionSpec(
23
+ "rate",
24
+ OptionKind.TEXT,
25
+ None,
26
+ "Output sample rate: keep, auto or a number in Hz",
27
+ (("keep", ""), ("auto", "")),
28
+ ),
29
+ OptionSpec("lowpass", OptionKind.INT, None, "Lowpass cut-off in Hz"),
30
+ flag("no-delay", True, "Remove the encoder delay, for A/V sync in video", false_flag=False),
31
+ OptionSpec(
32
+ "gapless-mode",
33
+ OptionKind.INT,
34
+ None,
35
+ "How the encoder delay is signaled",
36
+ ((0, "iTunSMPB"), (1, "ISO standard"), (2, "both")),
37
+ ),
38
+ flag("threading", True, "Multi-threading", false_flag=False),
39
+ flag("no-optimize", True, "Don't optimize MP4 container after encoding", true_flag=False),
40
+ )
41
+
42
+ def build_args(
43
+ self,
44
+ binary: str,
45
+ output: Path,
46
+ node: NodeInfo,
47
+ *,
48
+ options: Mapping[str, OptionValue],
49
+ extra_args: Sequence[str],
50
+ ) -> list[str]:
51
+ return [
52
+ binary,
53
+ "--ignorelength",
54
+ *options_to_args(options, self.known_options),
55
+ *extra_args,
56
+ "-o",
57
+ str(output),
58
+ "-",
59
+ ]
@@ -0,0 +1,97 @@
1
+ from collections.abc import Mapping, Sequence
2
+ from pathlib import Path
3
+ from typing import override
4
+
5
+ from kazesynth_worker.protocol import NodeInfo, OutputFormat
6
+
7
+ from .base import (
8
+ X26X_PRESETS,
9
+ Adapter,
10
+ EncoderProgress,
11
+ OptionKind,
12
+ OptionSpec,
13
+ OptionValue,
14
+ flag,
15
+ options_to_args,
16
+ parse_x26x_progress,
17
+ )
18
+ from .x26x import clip_args
19
+
20
+
21
+ class X264(Adapter):
22
+ name = "x264"
23
+ input_format = OutputFormat.Y4M
24
+ default_binary = "x264"
25
+ extension = ".264"
26
+ # x264 has only one form of some bool flags: --no-mbtree, --no-dct-decimate, --open-gop.
27
+ # Sorted like `x264 --fullhelp`: presets, frame-type, ratecontrol, analysis, input/output.
28
+ known_options = (
29
+ OptionSpec("preset", OptionKind.TEXT, "placebo", "Speed against compression", X26X_PRESETS),
30
+ # Frame-type
31
+ OptionSpec("bframes", OptionKind.INT, 16, "Maximum consecutive B-frames (0 to 16)"),
32
+ flag("open-gop", False, "Open GOPs", false_flag=False),
33
+ OptionSpec("ref", OptionKind.INT, 16, "Reference frames (1 to 16)"),
34
+ OptionSpec("deblock", OptionKind.TEXT, "-1:-1", "Deblocking filter, as alpha:beta"),
35
+ # Ratecontrol
36
+ OptionSpec("crf", OptionKind.FLOAT, 12.0, "Constant quality. Lower is better and bigger"),
37
+ OptionSpec("rc-lookahead", OptionKind.INT, 250, "Frames to look ahead for frame types"),
38
+ OptionSpec(
39
+ "aq-mode",
40
+ OptionKind.INT,
41
+ 3,
42
+ "Adaptive quantization mode",
43
+ ((0, "off"), (1, "variance"), (2, "auto-variance"), (3, "auto-variance, dark scene bias")),
44
+ ),
45
+ OptionSpec("aq-strength", OptionKind.FLOAT, 0.8, "Adaptive quantization strength"),
46
+ flag("mbtree", False, "Macroblock-tree rate control", true_flag=False),
47
+ OptionSpec("qcomp", OptionKind.FLOAT, 0.7, "QP curve compression"),
48
+ # Analysis
49
+ OptionSpec(
50
+ "me",
51
+ OptionKind.TEXT,
52
+ "umh",
53
+ "Motion search method",
54
+ (("dia", ""), ("hex", ""), ("umh", ""), ("esa", ""), ("tesa", "")),
55
+ ),
56
+ OptionSpec("merange", OptionKind.INT, 32, "Motion search range"),
57
+ OptionSpec("subme", OptionKind.INT, 11, "Sub-pixel motion refinement (0 to 11)"),
58
+ OptionSpec("psy-rd", OptionKind.TEXT, "1.0:0.0", "Psycho-visual strength, as rd:trellis"),
59
+ OptionSpec(
60
+ "trellis",
61
+ OptionKind.INT,
62
+ None,
63
+ "Trellis quantization",
64
+ ((0, "off"), (1, "final macroblock only"), (2, "all mode decisions")),
65
+ ),
66
+ flag("dct-decimate", False, "Drop small DCT coefficients in P-frames", true_flag=False),
67
+ # Input/Output
68
+ OptionSpec("threads", OptionKind.INT, 6, "Encoder threads"),
69
+ )
70
+
71
+ def build_args(
72
+ self,
73
+ binary: str,
74
+ output: Path,
75
+ node: NodeInfo,
76
+ *,
77
+ options: Mapping[str, OptionValue],
78
+ extra_args: Sequence[str],
79
+ ) -> list[str]:
80
+ return [
81
+ binary,
82
+ "--demuxer",
83
+ "y4m",
84
+ "--frames",
85
+ str(node["num_frames"]),
86
+ # Before the user's flags: if one slips through, the user's flag still comes last and wins.
87
+ *clip_args(node, options, extra_args, x265=False),
88
+ *options_to_args(options, self.known_options),
89
+ *extra_args,
90
+ "--output",
91
+ str(output),
92
+ "-",
93
+ ]
94
+
95
+ @override
96
+ def parse_line(self, line: str) -> EncoderProgress | None:
97
+ return parse_x26x_progress(line)
@@ -0,0 +1,111 @@
1
+ from collections.abc import Mapping, Sequence
2
+ from pathlib import Path
3
+ from typing import override
4
+
5
+ from kazesynth_worker.protocol import NodeInfo, OutputFormat
6
+
7
+ from .base import (
8
+ X26X_PRESETS,
9
+ Adapter,
10
+ EncoderProgress,
11
+ OptionKind,
12
+ OptionSpec,
13
+ OptionValue,
14
+ flag,
15
+ options_to_args,
16
+ parse_x26x_progress,
17
+ )
18
+ from .x26x import clip_args
19
+
20
+
21
+ class X265(Adapter):
22
+ name = "x265"
23
+ input_format = OutputFormat.Y4M
24
+ default_binary = "x265"
25
+ extension = ".hevc"
26
+ # x265 presets change most of these. So every bool sends --name or --no-name.
27
+ known_options = (
28
+ OptionSpec("preset", OptionKind.TEXT, "veryslow", "Speed against compression", X26X_PRESETS),
29
+ # Quad-Tree
30
+ OptionSpec("tu-intra-depth", OptionKind.INT, 2, "Maximum TU depth for intra CUs (1 to 4)"),
31
+ OptionSpec("tu-inter-depth", OptionKind.INT, 2, "Maximum TU depth for inter CUs (1 to 4)"),
32
+ # Analysis
33
+ OptionSpec("rd", OptionKind.INT, 4, "Rate-distortion optimization level (1 to 6)"),
34
+ OptionSpec("psy-rd", OptionKind.FLOAT, 2.0, "Psycho-visual rate-distortion strength"),
35
+ OptionSpec("psy-rdoq", OptionKind.FLOAT, 1.5, "Psycho-visual strength in RDO quantization"),
36
+ OptionSpec("rskip", OptionKind.INT, 0, "Recursion skip", ((0, "off"), (1, "RD level"), (2, "edge density"))),
37
+ # Coding tools
38
+ flag("weightb", True, "Weighted prediction in B-frames"),
39
+ flag("tskip", True, "Transform skip for 4x4 TUs"),
40
+ # Temporal/motion
41
+ OptionSpec("ref", OptionKind.INT, 4, "Reference frames (1 to 16)"),
42
+ OptionSpec(
43
+ "me",
44
+ OptionKind.INT,
45
+ 3,
46
+ "Motion search method",
47
+ ((0, "dia"), (1, "hex"), (2, "umh"), (3, "star"), (4, "sea"), (5, "full")),
48
+ ),
49
+ OptionSpec("subme", OptionKind.INT, 5, "Sub-pixel motion refinement (0 to 7)"),
50
+ flag("rect", True, "Rectangular motion partitions"),
51
+ flag("amp", False, "Asymmetric motion partitions (needs rect)"),
52
+ # Spatial/intra
53
+ flag("strong-intra-smoothing", False, "Enable strong intra smoothing for 32x32 blocks"),
54
+ flag("b-intra", True, "Intra modes in B-frames"),
55
+ # Slice decision
56
+ flag("open-gop", False, "Open GOPs"),
57
+ OptionSpec("rc-lookahead", OptionKind.INT, 60, "Frames to look ahead for frame types"),
58
+ OptionSpec("bframes", OptionKind.INT, 12, "Maximum consecutive B-frames (0 to 16)"),
59
+ # Rate control
60
+ OptionSpec("crf", OptionKind.FLOAT, 13.0, "Constant quality. Lower is better and bigger"),
61
+ OptionSpec(
62
+ "aq-mode",
63
+ OptionKind.INT,
64
+ 3,
65
+ "Adaptive quantization mode",
66
+ (
67
+ (0, "off"),
68
+ (1, "variance"),
69
+ (2, "auto-variance"),
70
+ (3, "auto-variance, dark scene bias"),
71
+ (4, "auto-variance, edge information"),
72
+ ),
73
+ ),
74
+ OptionSpec("aq-strength", OptionKind.FLOAT, 0.70, "Adaptive quantization strength"),
75
+ flag("cutree", False, "Lower the quality of blocks that later frames do not use"),
76
+ OptionSpec("qcomp", OptionKind.FLOAT, 0.72, "QP curve compression"),
77
+ OptionSpec("cbqpoffs", OptionKind.INT, -2, "Chroma Cb QP offset (-12 to 12)"),
78
+ OptionSpec("crqpoffs", OptionKind.INT, -2, "Chroma Cr QP offset (-12 to 12)"),
79
+ # Loop filters
80
+ OptionSpec("deblock", OptionKind.TEXT, "-2:-2", "Deblocking filter, as tC:beta"),
81
+ flag("sao", False, "Sample Adaptive Offset loop filter"),
82
+ flag("sao-non-deblock", False, "Use non-deblocked pixels"),
83
+ )
84
+
85
+ def build_args(
86
+ self,
87
+ binary: str,
88
+ output: Path,
89
+ node: NodeInfo,
90
+ *,
91
+ options: Mapping[str, OptionValue],
92
+ extra_args: Sequence[str],
93
+ ) -> list[str]:
94
+ return [
95
+ binary,
96
+ "--y4m",
97
+ "--input",
98
+ "-",
99
+ "--frames",
100
+ str(node["num_frames"]),
101
+ # Before the user's flags: if one slips through, the user's flag still comes last and wins.
102
+ *clip_args(node, options, extra_args, x265=True),
103
+ *options_to_args(options, self.known_options),
104
+ *extra_args,
105
+ "--output",
106
+ str(output),
107
+ ]
108
+
109
+ @override
110
+ def parse_line(self, line: str) -> EncoderProgress | None:
111
+ return parse_x26x_progress(line)