fix: ffprobe duration 解析增加 format 回退,兼容 MPEG-TS 等格式
This commit is contained in:
@@ -546,7 +546,7 @@ pub async fn get_video_metadata(app: &AppHandle, input_path: &str) -> Result<Vid
|
||||
let args = vec![
|
||||
"-v".to_string(), "error".to_string(),
|
||||
"-select_streams".to_string(), "v:0".to_string(),
|
||||
"-show_entries".to_string(), "stream=width,height,duration,r_frame_rate".to_string(),
|
||||
"-show_entries".to_string(), "stream=width,height,duration,r_frame_rate:format=duration".to_string(),
|
||||
"-of".to_string(), "json".to_string(),
|
||||
safe_input,
|
||||
];
|
||||
@@ -611,10 +611,15 @@ pub async fn get_video_metadata(app: &AppHandle, input_path: &str) -> Result<Vid
|
||||
.and_then(|v| v.as_u64())
|
||||
.ok_or_else(|| "无法解析视频高度".to_string())? as u32;
|
||||
|
||||
// duration 可能是字符串或数字
|
||||
let duration = stream.get("duration")
|
||||
.and_then(|v| v.as_f64().or_else(|| v.as_str().and_then(|s| s.parse().ok())))
|
||||
.unwrap_or(0.0);
|
||||
// duration 可能是字符串或数字;某些格式(如 MPEG-TS)stream duration 为 N/A,需从 format 回退
|
||||
let stream_duration = stream.get("duration")
|
||||
.and_then(|v| v.as_f64().or_else(|| v.as_str().and_then(|s| s.parse().ok())));
|
||||
|
||||
let format_duration = parsed.get("format")
|
||||
.and_then(|f| f.get("duration"))
|
||||
.and_then(|v| v.as_f64().or_else(|| v.as_str().and_then(|s| s.parse().ok())));
|
||||
|
||||
let duration = stream_duration.or(format_duration).unwrap_or(0.0);
|
||||
|
||||
// 帧率格式为 "25/1" 或 "30000/1001"
|
||||
let fps = stream.get("r_frame_rate")
|
||||
|
||||
Reference in New Issue
Block a user