Skip to content

Commit fa8166b

Browse files
src: lib: stream: sink: image_sink: Fix thumbnail cold-start timeout
Request an upstream ForceKeyUnit event before waiting for a snapshot frame. The identity filter drops all non-keyframes (DELTA_UNIT), so without this the appsink must wait for the encoder's next natural keyframe which can take 8+ seconds with default key-int-max settings. Also increase the timeout from 2s to 15s as a safety net for slow pipelines.
1 parent ce79495 commit fa8166b

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/lib/stream/sink/image_sink.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,12 +435,21 @@ impl ImageSink {
435435
.remove_probe(blocker);
436436
}
437437

438-
// Trigger the snapshot
438+
// Request an immediate keyframe so the identity filter (which drops
439+
// non-keyframes via drop-buffer-flags = DELTA_UNIT) lets a frame
440+
// through without waiting for the encoder's natural key-int-max.
441+
if let Some(queue_src_pad) = self.queue.static_pad("src") {
442+
let event = gst_video::UpstreamForceKeyUnitEvent::builder()
443+
.all_headers(true)
444+
.build();
445+
queue_src_pad.send_event(event);
446+
}
447+
439448
let mut receiver = self.flat_samples_sender.subscribe();
440449

441-
// Wait for the snapshot to be taken, with a timeout
442-
// Here we'd have the raw snapshot, we just need to convert it to the final format/size
443-
tokio::time::timeout(tokio::time::Duration::from_secs(2), receiver.recv())
450+
// Wait for the snapshot with enough headroom for the keyframe to
451+
// arrive even on slow pipelines or high key-int-max settings.
452+
tokio::time::timeout(tokio::time::Duration::from_secs(15), receiver.recv())
444453
.await??
445454
.map_err(|e| anyhow!(e.to_string()))
446455
}

0 commit comments

Comments
 (0)