Files
video_register/README.md

119 lines
2.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# video_register
影片元數據註冊服務
## 功能
- 讀取 `.probe.json` 文件(由 video_probe 生成)
- 根據檔案路徑自動生成 UUID 作為檔案 ID
- 將影片元數據註冊到 PostgreSQL 資料庫
- 支援 SQL 查詢搜尋影片元數據
- 註冊後將檔案複製為 UUID 命名(測試期間保留原始檔)
## 安裝
```bash
pip install -r requirements.txt
```
## 配置
在專案根目錄創建 `.env` 文件:
```env
DATABASE_URL=postgresql://accusys@localhost:5432/video_register
```
## 使用方式
### CLI 命令
#### 註冊影片
```bash
python cli.py register <probe.json 路徑>
```
選項:
- `--dry-run`: 測試模式,不實際複製檔案
範例:
```bash
python cli.py register ../test_video/Old_Time_Movie_Show_-_Charade_1963.HD.probe.json
python cli.py register ../test_video/Old_Time_Movie_Show_-_Charade_1963.HD.probe.json --dry-run
```
#### 驗證已註冊的影片
```bash
python cli.py verify <UUID>
```
範例:
```bash
python cli.py verify 1636719d-c31f-78ac-f1dd-8ab0b0b36c66
```
### API 服務
啟動 FastAPI 服務:
```bash
uvicorn app.main:app --reload
```
API 文件http://localhost:8000/docs
## probe.json 格式
輸入的 `probe.json` 必須包含 `video_path` 欄位:
```json
{
"video_path": "/absolute/path/to/video.mov",
"probed_at": "2026-03-10T23:26:04",
"format": { ... },
"video_stream": { ... },
"audio_streams": [...],
"subtitle_streams": [...]
}
```
## UUID 生成規則
UUID 透過 SHA-256 雜湊檔案路徑生成,確保:
- 相同路徑產生相同的 UUID
- 可從 UUID 反向計算驗證
## 資料庫結構
### videos 表
- `id`: UUID (主鍵)
- `file_path`: 原始檔案路徑
- `file_name`: 檔案名稱(不含副檔名)
- `file_extension`: 副檔名
- `file_size`: 檔案大小
- `format_name`: 格式名稱
- `duration`: 時長
- `title`: 標題
- `artist`: 藝術家
### video_streams 表
- `video_id`: 關聯的 videos ID
- `codec_name`: 編碼名稱
- `width`, `height`: 解析度
- `color_space`: 色彩空間
- `color_range`: 色彩範圍
### audio_streams 表
- `video_id`: 關聯的 videos ID
- `codec_name`: 編碼名稱
- `channels`: 聲道數
- `sample_rate`: 取樣率
- `language`: 語言
### subtitle_streams 表
- `video_id`: 關聯的 videos ID
- `codec_name`: 編碼名稱
- `language`: 語言