# gizai:h3

giz's worker of MiniMax H3 (gizai:diffusion's D.H3): its video.generate jobs as WanGP makes them (sliding windows, a video to extend, control videos, Ref2VA references, a soundtrack) and the enhance-video and interpolate-video jobs (RTX Video and optical flow on the same GPU).

```gizlang
import * as H3 from "gizai:h3";
```

## Types

### `Serving`

```gizlang
type Serving = { fl2va: string; ref2va: string; text: string; spare: i64; state: string; host: string; port: i64; ffmpeg: string; }
```

What `serve` serves: H3 FL2VA from the model folder `fl2va` and Ref2VA from `ref2va` (either "" for none), with the
text encoder `text` ("local" or HOST:PORT), `spare` bytes of the GPU left free, its jobs under `state` and on
`host`:`port`; `ffmpeg` the program that reads and muxes the uploads.

- `fl2va`: `string`
- `ref2va`: `string`
- `text`: `string`
- `spare`: `i64`
- `state`: `string`
- `host`: `string`
- `port`: `i64`
- `ffmpeg`: `string`

### `Treatment`

```gizlang
type Treatment = { e: V.Enhance; times: i64; effort: string; }
```

What a job does to the frames: RTX Video `e`, or (`times` above 1) `times` - 1 frames made between each two (of
quality `effort`: V.interpolationQualities).

- `e`: `M42.Enhance`
- `times`: `i64`
- `effort`: `string`

### `Source`

```gizlang
type Source = { width: i64; height: i64; num: i64; den: i64; seconds: f64; frames: i64; bytes: i64; codec: string; pixels: string; turn: i64; }
```

A video file's first video stream as ffprobe sees it: its size as shown (after the turn), frame rate num / den,
length, frame count and file size (-1: unknown), codec, and the turn it asks for (degrees clockwise).

- `width`: `i64`
- `height`: `i64`
- `num`: `i64`
- `den`: `i64`
- `seconds`: `f64`
- `frames`: `i64`
- `bytes`: `i64`
- `codec`: `string`
- `pixels`: `string`
- `turn`: `i64`

## Functions

### `serve`

```gizlang
function serve(sys: System, s: Serving): Result<i64, string>
```

giz's worker for its H3 pools: video.generate of minimax_h3_fl2va_pruned (and the id giz names it by,
minimax_h3_fl2va_pruned_int8_convrot) and of Ref2VA into output.mp4 (output.2x.mp4 by RTX Video, in the process, when
the input asks upscale), and giz's enhance-video and interpolate-video models (enhanceRun). The kernels' tunings stay
in STATE/tune. One process serves both of H3's models with one transformer on the GPU at a time (H3.use swaps it for a
job of the other), as WanGP does on one card.

Effects: fail, read, write, console, io.

### `h3Upscale`

```gizlang
function h3Upscale(): V.Enhance
```

The 2x upscale of an H3 video (input upscale: true), as wgp-api's NVIDIA VSR asks it.

### `sourceOf`

```gizlang
function sourceOf(sys: System, ffmpeg: string, path: string): Result<Source, string>
```

The video stream of the file PATH as ffprobe (beside FFMPEG) reads it: its size, frame rate, length, codec and rotation.

Effects: fail, read, write, io.

### `enhanceFile`

```gizlang
function enhanceFile(sys: System, gpu: Gpu, ffmpeg: string, source: string, s: Source, how: Treatment, codec: string, dir: string, progress: (f: i64, total: i64) => bool): Result<i64, W.Failure>
```

`source` (`s`: sourceOf) through `how` into DIR/output.mp4 of `codec`, with the source's audio: NVDEC, the effect
or the interpolation, and NVENC on `gpu`, then ffmpeg times the track at the source's rate (times `how.times`)
beside the audio. `progress` takes the source frames done and expected each 8 frames and gives false to cancel.

Effects: fail, read, write, console, io.

