fix: VFR frame extraction - use select=eq(n) instead of -ss frame/fps

- tkg.rs key_frame: select=eq(n\,best_frame) instead of -ss frame/fps
- tkg.rs retry: same fix for need_retry block
- tools.rs agent frame: select=eq(n\,frame_number)
- media_api.rs segment video: select=between(n\,sf\,ef-1) for frame mode

VFR videos (r_frame_rate != actual fps) now get correct frames.
CFR videos unaffected: select=eq(n) produces same result as -ss frame/fps.

Fixes: face card / face-detail thumbnail mismatch for VFR files.
This commit is contained in:
Accusys
2026-08-05 12:36:25 +08:00
parent 2117ca60b8
commit a6d705abf1
3 changed files with 36 additions and 21 deletions
+6 -2
View File
@@ -928,12 +928,16 @@ pub async fn exec_analyze_frame(
}
});
// Use select=eq(n\,frame) for VFR compatibility (decoded index, not time-based)
let select = format!("select=eq(n\\,{})", frame_number);
let output = tokio::process::Command::new(&ffmpeg_path)
.args([
"-ss",
&format!("{:.3}", timestamp_secs),
"-i",
&video_path,
])
.args([
"-vf",
&select,
"-vframes",
"1",
"-f",
+7 -6
View File
@@ -1267,19 +1267,20 @@ async fn build_face_track_nodes_from_qdrant(
);
// Extract key_frame JPEG bytes via ffmpeg pipe
// Use select=eq(n\,frame) for VFR compatibility (decoded index, not time-based)
let key_frame_jpeg: Option<Vec<u8>> = video_path.as_ref().and_then(|vp| {
let timestamp = agg.best_frame as f64 / actual_fps;
let select = format!("select=eq(n\\,{})", agg.best_frame);
let output = std::process::Command::new("ffmpeg")
.args([
"-y",
"-v",
"quiet",
"-ss",
&format!("{:.3}", timestamp),
"-i",
])
.arg(vp)
.args([
"-vf",
&select,
"-frames:v",
"1",
"-q:v",
@@ -1404,7 +1405,7 @@ async fn build_face_track_nodes_from_qdrant(
if need_retry {
if let Some(ref vp) = video_path {
let timestamp = agg.best_frame as f64 / actual_fps;
let select = format!("select=eq(n\\,{})", agg.best_frame);
// Retry key_frame extraction
if !kf_path.exists() {
if let Ok(output) = std::process::Command::new("ffmpeg")
@@ -1412,12 +1413,12 @@ async fn build_face_track_nodes_from_qdrant(
"-y",
"-v",
"quiet",
"-ss",
&format!("{:.3}", timestamp),
"-i",
vp,
])
.args([
"-vf",
&select,
"-frames:v",
"1",
"-q:v",