Files
mixvideo-v2/TVAI_ADVANCED_PARAMETERS_SUMMARY.md
imeepos 0a742f1e6b feat: 扩展TVAI高级参数并修复编译错误
主要功能:
- 将TVAI可控参数从5个扩展到34个 (+29个新参数)
- 支持完整的FFmpeg编码参数控制
- 添加高级TVAI AI增强参数 (preblur, noise, details, halo, blur等)
- 支持输出尺寸控制和音频处理模式

 技术改进:
- 重新设计VideoUpscaleParams结构体
- 添加智能默认值和预设系统
- 优化参数验证和错误处理
- 改进FFmpeg滤镜构建逻辑

 修复编译错误:
- 修复E0063结构体字段缺失错误 (6处)
- 修复E0597生命周期错误 (3处)
- 消除未使用代码警告 (2处)
- 确保向后兼容性

 文档:
- 详细的高级参数使用指南
- 完整的编译错误修复总结
- 34个参数的分类和说明
2025-08-11 19:06:49 +08:00

296 lines
9.5 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.
# TVAI 高级参数扩展总结
## 🎯 基于示例命令的参数扩展
### 参考的FFmpeg命令
```bash
ffmpeg "-hide_banner" "-t" "5.016666484785481" "-ss" "0" "-i" "input.mp4"
"-sws_flags" "spline+accurate_rnd+full_chroma_int"
"-filter_complex" "tvai_up=model=prob-4:scale=0:w=2160:h=3840:preblur=0:noise=0:details=0:halo=0:blur=0:compression=0:estimate=8:blend=0.2:device=-2:vram=1:instances=1,scale=w=2160:h=3840:flags=lanczos:threads=0:force_original_aspect_ratio=decrease,pad=2160:3840:-1:-1:color=black"
"-c:v" "h264_nvenc" "-profile:v" "high" "-pix_fmt" "yuv420p" "-g" "30"
"-preset" "p7" "-tune" "hq" "-rc" "constqp" "-qp" "18" "-rc-lookahead" "20"
"-spatial_aq" "1" "-aq-strength" "15" "-b:v" "0" "-an"
"-map_metadata" "0" "-map_metadata:s:v" "0:s:v" "-fps_mode:v" "passthrough"
"-movflags" "frag_keyframe+empty_moov+delay_moov+use_metadata_tags+write_colr"
"-bf" "0" "-metadata" "videoai=Enhanced using prob-4..." "output.mp4"
```
## 📊 新增参数分类
### 1. 高级TVAI参数 (9个)
```rust
pub preblur: f32, // 预模糊 (0-100)
pub noise: f32, // 噪点减少 (0-100)
pub details: f32, // 细节恢复 (0-100)
pub halo: f32, // 光晕减少 (0-100)
pub blur: f32, // 模糊减少 (0-100)
pub estimate: u32, // 估算质量 (1-20)
pub device: i32, // 设备ID (-2=auto, -1=CPU, 0+=GPU)
pub vram: u32, // VRAM使用 (0-1)
pub instances: u32, // 实例数量 (1-4)
```
### 2. 输出尺寸控制 (4个)
```rust
pub target_width: Option<u32>, // 目标宽度
pub target_height: Option<u32>, // 目标高度
pub maintain_aspect: bool, // 保持宽高比
pub pad_color: String, // 填充颜色
```
### 3. 编码参数 (13个)
```rust
pub codec: Option<String>, // 编码器 (h264_nvenc, hevc_nvenc, libx264等)
pub profile: Option<String>, // 编码配置文件 (high, main, baseline)
pub pixel_format: String, // 像素格式 (yuv420p, yuv444p等)
pub gop_size: u32, // GOP大小 (关键帧间隔)
pub preset: Option<String>, // 编码预设 (p1-p7, ultrafast-veryslow)
pub tune: Option<String>, // 调优选项 (hq, ll, ull等)
pub rate_control: String, // 码率控制模式 (constqp, vbr, cbr)
pub quality_param: u32, // 质量参数 (CRF/QP值)
pub lookahead: u32, // 前瞻帧数 (0-32)
pub spatial_aq: bool, // 空间自适应量化
pub aq_strength: u32, // AQ强度 (1-15)
pub bitrate: u32, // 目标码率 (0=VBR)
pub buffer_frames: u32, // 缓冲帧数 (B帧数量)
```
### 4. 音频处理 (1个枚举)
```rust
pub enum AudioMode {
Keep, // 保留原音频
Remove, // 移除音频
Reencode { codec: String, bitrate: u32 }, // 重新编码
}
```
### 5. 元数据控制 (2个)
```rust
pub preserve_metadata: bool, // 保留元数据
pub custom_metadata: Option<String>, // 自定义元数据
```
## 🎛️ 预设配置示例
### 最高质量预设
```rust
pub fn for_maximum_quality() -> Self {
Self {
scale_factor: 2.0,
model: UpscaleModel::Ahq12,
compression: 0.0,
blend: 0.0,
preblur: 0.0,
noise: 30.0, // 强噪点减少
details: 60.0, // 强细节恢复
halo: 30.0, // 强光晕减少
blur: 40.0, // 强模糊减少
estimate: 20, // 最高估算质量
quality_param: 12, // 最高质量
lookahead: 32, // 最大前瞻
instances: 1, // 单实例确保质量
..Default::default()
}
}
```
### 快速处理预设
```rust
pub fn for_fast_processing() -> Self {
Self {
scale_factor: 2.0,
model: UpscaleModel::Alqs2,
compression: 0.2,
blend: 0.0,
preblur: 0.0,
noise: 10.0, // 轻度噪点减少
details: 20.0, // 轻度细节恢复
halo: 5.0, // 轻度光晕减少
blur: 10.0, // 轻度模糊减少
estimate: 4, // 较低估算质量
quality_param: 22, // 较低质量但更快
preset: Some("p1".to_string()), // 最快预设
instances: 2, // 多实例加速
..Default::default()
}
}
```
### 老视频修复预设
```rust
pub fn for_old_video() -> Self {
Self {
scale_factor: 2.0,
model: UpscaleModel::Thf4,
compression: 0.3,
blend: 0.2,
preblur: 0.0,
noise: 20.0, // 中等噪点减少
details: 30.0, // 中等细节恢复
halo: 10.0, // 轻度光晕减少
blur: 15.0, // 轻度模糊减少
..Default::default()
}
}
```
## 🔧 技术实现细节
### 滤镜构建
```rust
fn build_upscale_filter(&self, params: &VideoUpscaleParams) -> Result<String, TvaiError> {
let tvai_params = vec![
format!("model={}", params.model.as_str()),
format!("scale={}", if params.scale_factor == 0.0 { 0 } else { params.scale_factor as u32 }),
format!("preblur={}", params.preblur),
format!("noise={}", params.noise),
format!("details={}", params.details),
format!("halo={}", params.halo),
format!("blur={}", params.blur),
format!("compression={}", params.compression),
format!("estimate={}", params.estimate),
format!("blend={}", params.blend),
format!("device={}", params.device),
format!("vram={}", params.vram),
format!("instances={}", params.instances),
];
let tvai_filter = format!("tvai_up={}", tvai_params.join(":"));
// 如果需要,添加缩放和填充滤镜...
}
```
### 编码参数构建
```rust
fn build_encoding_args(&self, params: &VideoUpscaleParams) -> Result<Vec<String>, TvaiError> {
let mut args = Vec::new();
// 自动选择编码器
let codec = params.codec.as_deref().unwrap_or_else(|| {
if self.is_gpu_enabled() { "h264_nvenc" } else { "libx264" }
});
// GPU编码器特定参数
if codec.contains("nvenc") {
args.extend_from_slice(&[
"-preset".to_string(), params.preset.clone().unwrap_or("p7".to_string()),
"-tune".to_string(), params.tune.clone().unwrap_or("hq".to_string()),
"-rc".to_string(), params.rate_control.clone(),
"-qp".to_string(), params.quality_param.to_string(),
"-rc-lookahead".to_string(), params.lookahead.to_string(),
]);
if params.spatial_aq {
args.extend_from_slice(&[
"-spatial_aq".to_string(), "1".to_string(),
"-aq-strength".to_string(), params.aq_strength.to_string(),
]);
}
}
Ok(args)
}
```
### 音频处理
```rust
fn build_audio_args(&self, audio_mode: &AudioMode) -> Result<Vec<String>, TvaiError> {
match audio_mode {
AudioMode::Keep => vec!["-c:a".to_string(), "copy".to_string()],
AudioMode::Remove => vec!["-an".to_string()],
AudioMode::Reencode { codec, bitrate } => vec![
"-c:a".to_string(), codec.clone(),
"-b:a".to_string(), format!("{}k", bitrate)
],
}
}
```
## 📈 参数对比
| 参数类别 | 原版本 | 新版本 | 增加数量 |
|----------|--------|--------|----------|
| 基础参数 | 5个 | 5个 | 0 |
| TVAI参数 | 0个 | 9个 | +9 |
| 尺寸控制 | 0个 | 4个 | +4 |
| 编码参数 | 0个 | 13个 | +13 |
| 音频处理 | 0个 | 1个 | +1 |
| 元数据 | 0个 | 2个 | +2 |
| **总计** | **5个** | **34个** | **+29** |
## 🎯 用户体验提升
### 专业级控制
- **细粒度调节**: 每个TVAI参数都可以精确控制
- **编码优化**: 支持所有主流编码器和参数
- **质量平衡**: 可以在质量和速度之间精确平衡
### 智能默认值
- **自动检测**: 设备、编码器自动选择
- **合理默认**: 所有参数都有经过测试的默认值
- **预设系统**: 针对不同场景的优化预设
### 灵活配置
- **可选参数**: 大部分参数都是可选的
- **向后兼容**: 保持与原有API的兼容性
- **类型安全**: 完整的TypeScript类型定义
## 🚀 实际应用场景
### 1. 专业视频制作
```rust
VideoUpscaleParams {
scale_factor: 2.0,
model: UpscaleModel::Ahq12,
target_width: Some(3840),
target_height: Some(2160),
quality_param: 12,
preset: Some("p7".to_string()),
tune: Some("hq".to_string()),
spatial_aq: true,
aq_strength: 15,
audio_mode: AudioMode::Keep,
..Default::default()
}
```
### 2. 快速预览
```rust
VideoUpscaleParams {
scale_factor: 1.5,
model: UpscaleModel::Alqs2,
quality_param: 28,
preset: Some("p1".to_string()),
instances: 2,
audio_mode: AudioMode::Remove,
..Default::default()
}
```
### 3. 老视频修复
```rust
VideoUpscaleParams {
scale_factor: 2.0,
model: UpscaleModel::Thf4,
noise: 25.0,
details: 35.0,
halo: 15.0,
blur: 20.0,
compression: 0.3,
blend: 0.2,
..Default::default()
}
```
## 总结
通过参考实际的FFmpeg命令我们将TVAI的可控参数从5个扩展到34个增加了29个新参数。这些参数覆盖了
**完整的TVAI控制** - 所有AI增强参数
**专业编码选项** - GPU/CPU编码器的所有参数
**灵活的音频处理** - 保留、移除、重编码
**智能尺寸控制** - 目标分辨率和宽高比
**元数据管理** - 保留和自定义元数据
这使得TVAI工具能够满足从快速预览到专业制作的各种需求提供了与原生Topaz Video AI相同级别的控制能力。