fix: 统一前后端 9:16 比例校验容差为 3% 相对误差
Rust 层 video_compose.rs 和 lib.rs 中的校验使用绝对误差 0.01 (约 1.78% 相对误差),比前端 videoValidation.ts 的 3% 更严格, 导致部分前端通过的视频在 Rust 层被拦截。 统一改为 , 与前端的相对误差算法保持一致。
This commit is contained in:
@@ -39,14 +39,14 @@ fn get_project_video_dir(app: &AppHandle, project_id: &str) -> Result<std::path:
|
||||
.map_err(|e| format!("获取项目视频目录失败: {}", e))
|
||||
}
|
||||
|
||||
/// 校验视频比例是否为 9:16(允许 1% 误差)
|
||||
/// 校验视频比例是否为 9:16(允许 ±3% 容差)
|
||||
fn validate_nine_sixteen_aspect(width: u32, height: u32) -> Result<(), String> {
|
||||
if width == 0 || height == 0 {
|
||||
return Err("无法读取视频分辨率".to_string());
|
||||
}
|
||||
let ratio = width as f64 / height as f64;
|
||||
let expected = 9.0 / 16.0;
|
||||
if (ratio - expected).abs() > 0.01 {
|
||||
if (ratio - expected).abs() / expected > 0.03 {
|
||||
return Err(format!(
|
||||
"视频比例必须是 9:16,当前为 {}×{}(比例 {:.3})",
|
||||
width, height, ratio
|
||||
|
||||
@@ -688,7 +688,7 @@ async fn video_composite_synthesis(
|
||||
}
|
||||
let ratio = meta.width as f64 / meta.height as f64;
|
||||
let expected = 9.0 / 16.0;
|
||||
if (ratio - expected).abs() > 0.01 {
|
||||
if (ratio - expected).abs() / expected > 0.03 {
|
||||
return ApiResponse {
|
||||
code: 400,
|
||||
message: format!(
|
||||
|
||||
Reference in New Issue
Block a user