# Video Generator

## Usage

    videogen.exe [settings_file]
    videogen.exe --help

Argument | Description
--- | ---
`settings_file` | Path to settings.txt (default: `settings.txt`)

## Description

The video generator waits for motion triggers, then merges camera feeds into composite output frames, encodes them to H.264 video, and optionally launches an upload script.

## Feed Merging

Output frames are composited from two camera feeds:

Display Type | Top Half (540 lines) | Bottom Half (540 lines)
--- | --- | ---
Type 0/1 | Feed 1 (middle camera) | Feed 0 (top of hill camera)
Type 2 | Feed 1 (middle camera) | Feed 2 (bottom of hill camera)

The display type is determined by the motion detection trigger — which feed detected the jumper determines which composite view is used.

## Encoding

Frames are piped to FFmpeg via stdin as raw YUV420:

- NVENC (h264_nvenc) — hardware encoding on NVIDIA GPUs, very fast
- libx264 — software fallback if no NVIDIA GPU is available

FFmpeg must be available at `C:\ffmpeg\bin\ffmpeg.exe` or in the same directory as videogen.exe.

## Double Buffering

Output uses two feed slots (0 and 1). While one is being written by the encoder, the other is available for the viewer to read. The active slot flips after each movie is complete.

## Movie Boundaries

    min_frames=60       # Minimum clip length (1 second at 60fps)
    max_frames=520      # Maximum clip length (buffer size)
    movie_pad=30        # Extra frames before/after motion event

## Upload

After encoding completes, videogen can launch an upload script via `CreateProcess`. Configure the upload command in settings.

## See Also

- Motion Detection — provides the triggers
- Viewer — displays the merged output
- Settings Reference — encoding and movie parameters
- Troubleshooting — encoding failures