Skip to content

Commit bbcc615

Browse files
fix: stop avfoundation mp4 writes when paused (#1308)
1 parent 612ef9e commit bbcc615

File tree

1 file changed

+13
-1
lines changed
  • crates/enc-avfoundation/src

1 file changed

+13
-1
lines changed

crates/enc-avfoundation/src/mp4.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,13 +452,25 @@ impl MP4Encoder {
452452
return Err(FinishError::NotWriting);
453453
}
454454

455+
let mut finish_timestamp = timestamp;
456+
457+
if let Some(pause_timestamp) = self.pause_timestamp {
458+
finish_timestamp = Some(match finish_timestamp {
459+
Some(ts) => ts.min(pause_timestamp),
460+
None => pause_timestamp,
461+
});
462+
}
463+
455464
let Some(mut most_recent_frame) = self.most_recent_frame.take() else {
456465
warn!("Encoder attempted to finish with no frame");
457466
return Err(FinishError::NoFrames);
458467
};
459468

469+
self.is_paused = false;
470+
self.pause_timestamp = None;
471+
460472
// We extend the video to the provided timestamp if possible
461-
if let Some(timestamp) = timestamp
473+
if let Some(timestamp) = finish_timestamp
462474
&& let Some(diff) = timestamp.checked_sub(most_recent_frame.1)
463475
&& diff > Duration::from_millis(500)
464476
{

0 commit comments

Comments
 (0)