Skip to content

The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.

perf(decode): a seek lets go of the frames short of its target before copying them off the GPU (#472)

Jareer3e68ba775102
diff --git a/src/crates/concat-media/src/decode.rs b/src/crates/concat-media/src/decode.rs
index bdb45595..f4e69f2b 100644
--- a/src/crates/concat-media/src/decode.rs
+++ b/src/crates/concat-media/src/decode.rs
@@ -987,6 +987,21 @@ impl Decoder {
.timestamp()
.and_then(|ticks| ffi::seconds(ticks, self.time_base))
.map(|pts| pts - self.start);
+ // A frame short of a seek's target is let go before it is copied
+ // off the chip: a seek decodes from the keyframe before it, up
+ // to a second or more of frames, and a full-size copy back of
+ // each one it throws away made every scrub on a Windows GPU
+ // decoder wait for all of them (#472).
+ if let (Some(before), Some(pts)) = (self.discard_before, pts)
+ && pts < before
+ {
+ continue;
+ }
+ if let (Some(through), Some(pts)) = (self.discard_through, pts)
+ && pts <= through
+ {
+ continue;
+ }
if let Some(&OnChip::Accel(device, format)) = self.hardware.as_ref() {
if frame.format() == format {
frame = match hardware::download(&frame) {
@@ -1013,16 +1028,6 @@ impl Decoder {
self.hardware = None;
}
}
- if let (Some(before), Some(pts)) = (self.discard_before, pts)
- && pts < before
- {
- continue;
- }
- if let (Some(through), Some(pts)) = (self.discard_through, pts)
- && pts <= through
- {
- continue;
- }
self.discard_before = None;
self.discard_through = None;
self.last_pts = pts;