# GEMINI Context & Project Directives: Historical

## Local PureVision + SPAN 4K Upscale Pipeline (Official Local Engine)
- **Skill Name**: `video-4k-upscaler`
- **Core Script**: `purescale_video_upscaler.py`
- **Models**:
  - Denoise: `models/1x_PureVision.pth` (CUDA FP32, khử muỗi nén H.264)
  - Upscale: `models/4xPurePhoto-span.pth` (Swift Parameter-free Attention - SPAN FP32)
- **Hiệu năng GTX 1660 Super**: ~0.95 FPS (~1.06s/frame), render full tập 5 phút mất ~2.05h, đỉnh VRAM 3.75 GB / 6 GB (Direct Full-Frame, không chia tile, stream linear `-bf 0 -avoid_negative_ts make_zero`).
- **Command Mẫu**:
  ```bash
  venv\Scripts\python.exe purescale_video_upscaler.py --input downloads/ep2.mp4 --output downloads/ep2_4k_span.mp4
  ```

## Cloud TensorRT 4K Upscale Pipeline (RTX 4090)
- **Engine**: `purescale_4k.engine` (TensorRT 11.3 FP16 End-to-End: PureVision 1x Denoise + SPAN 4x SR + Bicubic 4K)
- **Speed**: ~13.5 FPS (~69.9 ms/frame, render ~7.5 phút/tập 5 phút, chi phí ~$0.09/tập).
- **Encoder**: NVENC HEVC `-bf 0 -avoid_negative_ts make_zero -preset p4 -cq 19` (khắc phục 100% giật văng khung hình).
- **Watchdog & Auto-Termination**: `watchdog_runpod.py` (Tự động kéo 4K về máy và hủy pod ngay khi xong việc).
- **Status**: Hoàn thành toàn bộ 8 tập (`EP1` - `EP8`) tại `content/videos_4k/`.

## Shorts Marketing Pipeline (9:16)
- **Scripts**: `shorts_maker.py` và `shorts_hook_and_thumbnail_generator.py`
- **Cơ chế**: Quét transcript/SRT phát hiện cao trào kịch tính, tự động chèn 3s kinetic Hook banner (Paradox / Blunder / Weapon) và nhúng ảnh bìa 9:16 First-Frame Cover Stitching (Safe Zones 3 tầng).
- **Command Mẫu**:
  ```bash
  venv\Scripts\python.exe shorts_hook_and_thumbnail_generator.py --ep ep6
  ```

## Kieu Story - Medieval Literature AI Cinema (Standalone Project)
- **Project Directory**: `C:\Projects\KieuStory\`
- **Episodes**: 6x30m (Full), 12x5m (Climax Arcs), 1m Shorts 9:16 (High retention hooks).
- **Core AI Engine**: Gemini Banana (Google Imagen 3) + Muse.ai (Video Motion).
- **Safety Policy**: 100% YouTube Green Dollar Compliance (Chiaroscuro silhouette, nature metaphors, psychological tension, bronze hero statue).
## 4K Cinema Omnibus Pipeline (Ghép 8 Tập Hoàn Chỉnh)
- **Script**: `concat_4k_movie.py`
- **Cơ chế**:
  - Chuẩn hóa sang MPEG-TS với bộ lọc `-bsf:v hevc_mp4toannexb` ép chèn in-band VPS/SPS/PPS (khắc phục triệt để lỗi macroblock / rách hình tại mốc 4:41 và chuyển giao các tập).
  - Chuẩn hóa Audio sang AAC Stereo 48kHz 192k và timebase 90kHz tự nhiên.
  - Ghép bitstream trực tiếp & nhúng Chapter Markers vào metadata file MP4 (`-c copy`) trong ~30s, zero quality loss.
  - Tự động chạy Hàng rào kiểm thử chất lượng (Autonomous Quality Gate) quét qua toàn bộ 8 điểm giao tập.
- **Command Mẫu**:
  ```bash
  venv\Scripts\python.exe concat_4k_movie.py
  ```

## Chrome Extension & Antigravity SDK Bridge (YouTube Studio)
- **Extension Path**: `extension/` (Manifest V3 v2.1)
- **Bridge Service**: `antigravity_bridge_service.py` (Port 8766, FastAPI + Antigravity AI Engine + GPU Shorts Engine)
- **Shorts Engine**: Cắt Shorts dọc 9:16 (`blur`/`crop`) qua GPU NVENC GTX 1660 Super (`/api/shorts/create`) và quản lý kho 16 Shorts (`/api/shorts/list`).
- **Controller**: `tunnel_ctl.ps1` (`start`, `stop`, `status`, `chrome`, `all`)
- **Tester Tunnel**: `start_tester_tunnel.ps1` (Port 9222 Remote Debugging + Auto-load Extension)

## 4K UHD Thumbnail Standards & Batch Processor
- **Scripts**: `add_4k_badge.py`, `create_full_movie_thumbnail.py`
- **Badge**: Obsidian Glass + Gold border + Gold '4K' & White 'UHD' (Arial Bold 105pt on 4K) placed top-right.
- **Sizes**: JPG < 2MB (1.15MB - 1.72MB) strictly compliant with YouTube Studio upload limits, accompanied by full lossless PNG in `content/thumbnails_4k/`.
- **Language**: 100% English text on all thumbnails (`EPISODE XX` badge top-left, punchy English titles bottom: `PRINCE IN EXILE`, `50,000 INVADERS`, etc., `4K UHD` badge top-right). Zero Vietnamese text on thumbnails.
- **Sync**: Auto downscaled to 1080p/720p in `content/thumbnails/` for extension integration.

## YouTube Studio Autonomous Suite (Playwright & invisible_playwright)
- **Script**: `youtube_studio_manager.py`
- **Capabilities**: Dual-engine (`chrome_stealth` with native Extension loading, `invisible_playwright` with C++ Camoufox anti-detect), Native Clean Login bypass (chống 100% Google bot detection khi đăng nhập), automated 4K upload, metadata & chapter injection, 4K thumbnail upload.
- **Stealth Optimization**: `ignore_default_args=['--enable-automation']`, `--disable-blink-features=AutomationControlled`, `--exclude-switches=enable-automation`, xóa sạch `navigator.webdriver` qua `page.add_init_script`.
- **Command Mẫu**:
  ```bash
  # 1. Xác thực 1 lần duy nhất (Native Chrome, 100% không bot flag):
  venv\Scripts\python.exe youtube_studio_manager.py --login
  # 2. Vận hành tự động:
  venv\Scripts\python.exe youtube_studio_manager.py --status
  venv\Scripts\python.exe youtube_studio_manager.py --upload full
  ```

## YouTube Monetization Policies & Content Guidelines (`yt-rule/`)
- **Tài liệu**: Toàn bộ chính sách kiếm tiền chính thức từ Google Support tại `yt-rule/`:
  - `01_chinh_sach_kiem_tien_kenh_youtube.md`: YPP core, chống nội dung không chân thực (Inauthentic AI) và sử dụng lại (Reused).
  - `02_nguyen_tac_noi_dung_phu_hop_nha_quang_cao.md`: Tiêu chuẩn Icon Xanh (Advertiser-Friendly).
  - `03_dieu_kien_tham_gia_chuong_trinh_doi_tac_ypp.md`: Điều kiện tham gia YPP & AdSense.
  - `04_chinh_sach_kiem_tien_youtube_shorts.md`: Kiếm tiền Shorts & Doanh thu gộp (Creator Pool).
  - `05_cong_bo_su_dung_ai_tao_sinh.md`: Nhãn AI (Altered/Synthetic Content).
  - `06_chinh_sach_chuong_trinh_adsense.md`: Chính sách AdSense & lưu lượng hợp lệ.
  - `07_nguyen_tac_cong_dong_va_ban_quyen.md`: Bản quyền, Content ID & Fair Use.
  - `08_QUY_CHUAN_SAN_XUAT_NOI_DUNG_KENH_LICH_SU.md`: Sổ tay SOP kênh Lịch sử (7s đầu tiên, nghệ thuật Chiaroscuro khử bạo lực, Thumbnail < 2MB đạt chuẩn 4K).


