# Netflix-Style AV1 Optimization Tool

This script automates the process of converting your video library to highly compressed AV1 while maintaining a guaranteed quality level (VMAF).

## Requirements (Install on your Minisforum MS01)

1. **FFmpeg**: Must be installed and accessible in your PATH.
   - Windows: `winget install ffmpeg`
   - Linux: `sudo apt install ffmpeg` (Ensure it's a recent version usually 5.0+)

2. **ab-av1**: The magic tool that calculates VMAF scores.
   - Requires Rust. 
   - Linux/Mac: `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh` then `cargo install ab-av1`
   - Windows: Download binary from https://github.com/alexheretic/ab-av1/releases or use cargo.

## Usage

1. Open a terminal.
2. Run the script pointing to your library folder:

   ```bash
   python3 optimize_library.py "C:\Path\To\Movies"
   ```

   or on Linux:
   
   ```bash
   python3 optimize_library.py /mnt/media/Movies
   ```

## Options

- `--vmaf 95`: (Default) "Visually Lossless" target. Matches original source indistinguishably.
- `--vmaf 93`: Good for saving more space while keeping high quality.
- `--preset 6`: (Default) Best balance of speed/quality. Use 4 for archival (slower), 8 for speed.

## Hardware Note

This script is designed to run on your **i9-12900H (MS01)**.
- It uses the CPU (SVT-AV1) which is extremely efficient on the 12900H.
- It is faster to encode locally than to upload/download 50GB files on a 30Mbps connection.

## How it works

1. It scans your folders for videos.
2. It takes a small sample of each video.
3. It tries different compression levels (CRF) to find the highest number (smallest size) that hits VMAF 95.
4. It encodes the full file using that perfect setting.
5. Audio and Subtitles are COPIED (preserved) to ensure no loss of surround sound/metadata.
