feat: remote unuse json
This commit is contained in:
@@ -26,6 +26,7 @@ impl FfmpegCommandGenerator {
|
||||
self.model_mappings.insert("prob-3".to_string(), "ahq-12".to_string());
|
||||
self.model_mappings.insert("prob-4".to_string(), "ahq-12".to_string());
|
||||
self.model_mappings.insert("nyx-3".to_string(), "nyx-3".to_string());
|
||||
self.model_mappings.insert("hyp-1".to_string(), "hyp-1".to_string()); // Hyperion for HDR
|
||||
|
||||
// Frame interpolation models
|
||||
self.model_mappings.insert("apo-8".to_string(), "chr-2".to_string());
|
||||
@@ -48,25 +49,31 @@ impl FfmpegCommandGenerator {
|
||||
let mut filters = Vec::new();
|
||||
let settings = &template.settings;
|
||||
|
||||
// Generate stabilization filter
|
||||
if settings.stabilize.active {
|
||||
let stb_filter = self.generate_stabilization_filter(&settings.stabilize)?;
|
||||
filters.push(stb_filter);
|
||||
}
|
||||
|
||||
// Generate enhancement filter
|
||||
// Generate enhancement filter (usually first in chain)
|
||||
if settings.enhance.active {
|
||||
let up_filter = self.generate_enhancement_filter(&settings.enhance)?;
|
||||
filters.push(up_filter);
|
||||
}
|
||||
|
||||
// Generate frame interpolation filter
|
||||
// Generate frame interpolation filter (after enhancement)
|
||||
if settings.slow_motion.active {
|
||||
let fi_filter = self.generate_frame_interpolation_filter(&settings.slow_motion, &settings.output)?;
|
||||
filters.push(fi_filter);
|
||||
}
|
||||
|
||||
// Generate grain filter (using FFmpeg's noise filter as approximation)
|
||||
// Generate stabilization filter (after interpolation)
|
||||
if settings.stabilize.active {
|
||||
let stb_filter = self.generate_stabilization_filter(&settings.stabilize)?;
|
||||
filters.push(stb_filter);
|
||||
}
|
||||
|
||||
// Generate motion blur filter (if active)
|
||||
if settings.motion_blur.active {
|
||||
let mb_filter = self.generate_motion_blur_filter(&settings.motion_blur)?;
|
||||
filters.push(mb_filter);
|
||||
}
|
||||
|
||||
// Generate grain filter (usually last in chain)
|
||||
if settings.grain.active {
|
||||
let grain_filter = self.generate_grain_filter(&settings.grain)?;
|
||||
filters.push(grain_filter);
|
||||
@@ -83,7 +90,7 @@ impl FfmpegCommandGenerator {
|
||||
|
||||
// Add output settings
|
||||
command.push_str(&self.generate_output_settings(&settings.output)?);
|
||||
|
||||
|
||||
command.push_str(&format!(" \"{}\"", output_file));
|
||||
|
||||
Ok(command)
|
||||
@@ -199,36 +206,143 @@ impl FfmpegCommandGenerator {
|
||||
/// Generate output settings
|
||||
fn generate_output_settings(&self, settings: &crate::OutputSettings) -> TvaiResult<String> {
|
||||
let mut output_params = Vec::new();
|
||||
|
||||
// Handle output size method
|
||||
match settings.out_size_method {
|
||||
7 => {
|
||||
// 4K output
|
||||
output_params.push("-s 3840x2160".to_string());
|
||||
},
|
||||
6 => {
|
||||
// FHD output
|
||||
output_params.push("-s 1920x1080".to_string());
|
||||
},
|
||||
5 => {
|
||||
// HD output
|
||||
output_params.push("-s 1280x720".to_string());
|
||||
},
|
||||
_ => {
|
||||
// Keep original size (method 0) or other methods
|
||||
|
||||
// Hardware acceleration
|
||||
if let Some(ref hwaccel) = settings.hwaccel {
|
||||
output_params.push(format!("-hwaccel {}", hwaccel));
|
||||
}
|
||||
|
||||
// Custom resolution takes priority over size method
|
||||
if let (Some(width), Some(height)) = (settings.width, settings.height) {
|
||||
output_params.push(format!("-s {}x{}", width, height));
|
||||
} else {
|
||||
// Handle output size method
|
||||
match settings.out_size_method {
|
||||
7 => {
|
||||
// 4K output
|
||||
output_params.push("-s 3840x2160".to_string());
|
||||
},
|
||||
6 => {
|
||||
// FHD output
|
||||
output_params.push("-s 1920x1080".to_string());
|
||||
},
|
||||
5 => {
|
||||
// HD output
|
||||
output_params.push("-s 1280x720".to_string());
|
||||
},
|
||||
_ => {
|
||||
// Keep original size (method 0) or other methods
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle frame rate
|
||||
|
||||
// Frame rate
|
||||
if settings.out_fps > 0.0 {
|
||||
output_params.push(format!("-r {}", settings.out_fps));
|
||||
}
|
||||
|
||||
// Add default encoding settings for quality
|
||||
output_params.push("-c:v libx264".to_string());
|
||||
output_params.push("-crf 18".to_string());
|
||||
output_params.push("-preset slow".to_string());
|
||||
|
||||
|
||||
// Video codec
|
||||
if let Some(ref codec) = settings.codec {
|
||||
output_params.push(format!("-c:v {}", codec));
|
||||
} else {
|
||||
output_params.push("-c:v libx264".to_string());
|
||||
}
|
||||
|
||||
// Video quality settings
|
||||
if let Some(bitrate) = settings.bitrate {
|
||||
output_params.push(format!("-b:v {}k", bitrate));
|
||||
} else if let Some(crf) = settings.crf {
|
||||
// Use CRF for quality-based encoding
|
||||
let codec = settings.codec.as_deref().unwrap_or("libx264");
|
||||
match codec {
|
||||
"hevc_nvenc" | "h264_nvenc" => {
|
||||
output_params.push(format!("-cq {}", crf));
|
||||
},
|
||||
"h264_amf" | "hevc_amf" => {
|
||||
output_params.push(format!("-qp {}", crf));
|
||||
},
|
||||
"h264_qsv" | "hevc_qsv" => {
|
||||
output_params.push(format!("-global_quality {}", crf));
|
||||
},
|
||||
_ => {
|
||||
output_params.push(format!("-crf {}", crf));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
output_params.push("-crf 23".to_string()); // Default quality
|
||||
}
|
||||
|
||||
// Encoding preset
|
||||
if let Some(ref preset) = settings.preset {
|
||||
output_params.push(format!("-preset {}", preset));
|
||||
} else {
|
||||
output_params.push("-preset medium".to_string());
|
||||
}
|
||||
|
||||
// Video profile
|
||||
if let Some(ref profile) = settings.profile {
|
||||
output_params.push(format!("-profile:v {}", profile));
|
||||
}
|
||||
|
||||
// Video level
|
||||
if let Some(ref level) = settings.level {
|
||||
output_params.push(format!("-level {}", level));
|
||||
}
|
||||
|
||||
// GOP size
|
||||
if let Some(gop_size) = settings.gop_size {
|
||||
output_params.push(format!("-g {}", gop_size));
|
||||
}
|
||||
|
||||
// B-frames
|
||||
if let Some(b_frames) = settings.b_frames {
|
||||
output_params.push(format!("-bf {}", b_frames));
|
||||
}
|
||||
|
||||
// Pixel format
|
||||
if let Some(ref pix_fmt) = settings.pixel_format {
|
||||
output_params.push(format!("-pix_fmt {}", pix_fmt));
|
||||
}
|
||||
|
||||
// Color settings
|
||||
if let Some(ref colorspace) = settings.colorspace {
|
||||
output_params.push(format!("-colorspace {}", colorspace));
|
||||
}
|
||||
if let Some(ref color_primaries) = settings.color_primaries {
|
||||
output_params.push(format!("-color_primaries {}", color_primaries));
|
||||
}
|
||||
if let Some(ref color_trc) = settings.color_trc {
|
||||
output_params.push(format!("-color_trc {}", color_trc));
|
||||
}
|
||||
|
||||
// Audio settings
|
||||
if let Some(ref audio_codec) = settings.audio_codec {
|
||||
if audio_codec != "copy" {
|
||||
output_params.push(format!("-c:a {}", audio_codec));
|
||||
|
||||
if let Some(audio_bitrate) = settings.audio_bitrate {
|
||||
output_params.push(format!("-b:a {}k", audio_bitrate));
|
||||
}
|
||||
|
||||
if let Some(audio_sample_rate) = settings.audio_sample_rate {
|
||||
output_params.push(format!("-ar {}", audio_sample_rate));
|
||||
}
|
||||
|
||||
if let Some(audio_channels) = settings.audio_channels {
|
||||
output_params.push(format!("-ac {}", audio_channels));
|
||||
}
|
||||
} else {
|
||||
output_params.push("-c:a copy".to_string());
|
||||
}
|
||||
}
|
||||
|
||||
// Custom parameters
|
||||
if let Some(ref custom_params) = settings.custom_params {
|
||||
for param in custom_params {
|
||||
output_params.push(param.clone());
|
||||
}
|
||||
}
|
||||
|
||||
if output_params.is_empty() {
|
||||
Ok(String::new())
|
||||
} else {
|
||||
@@ -279,29 +393,18 @@ impl FfmpegCommandGenerator {
|
||||
|
||||
/// Generate command with custom output codec
|
||||
pub fn generate_with_codec(&self, template: &Template, input_file: &str, output_file: &str, codec: &str, quality: Option<i32>) -> TvaiResult<String> {
|
||||
let mut command = self.generate(template, input_file, output_file)?;
|
||||
|
||||
// Replace default codec settings
|
||||
command = command.replace("-c:v libx264", &format!("-c:v {}", codec));
|
||||
// Create a modified template with custom codec settings
|
||||
let mut modified_template = template.clone();
|
||||
modified_template.settings.output.codec = Some(codec.to_string());
|
||||
|
||||
if let Some(q) = quality {
|
||||
match codec {
|
||||
"hevc_nvenc" | "h264_nvenc" => {
|
||||
command = command.replace("-crf 18", &format!("-cq {}", q));
|
||||
},
|
||||
"h264_amf" | "hevc_amf" => {
|
||||
command = command.replace("-crf 18", &format!("-qp {}", q));
|
||||
},
|
||||
"h264_qsv" | "hevc_qsv" => {
|
||||
command = command.replace("-crf 18", &format!("-global_quality {}", q));
|
||||
},
|
||||
_ => {
|
||||
command = command.replace("-crf 18", &format!("-crf {}", q));
|
||||
}
|
||||
}
|
||||
// Clear bitrate when setting quality
|
||||
modified_template.settings.output.bitrate = None;
|
||||
modified_template.settings.output.crf = Some(q);
|
||||
}
|
||||
|
||||
Ok(command)
|
||||
// Generate command with modified template
|
||||
self.generate(&modified_template, input_file, output_file)
|
||||
}
|
||||
|
||||
/// Generate batch processing commands
|
||||
|
||||
Reference in New Issue
Block a user