Skip to content

Commit 1a665ae

Browse files
authored
Fix windows software encoding (#1121)
* assign pts properly * first_frame_tx
1 parent c1e481a commit 1a665ae

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

crates/recording/src/capture_pipeline.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -726,11 +726,13 @@ impl MakeCapturePipeline for screen_capture::Direct3DCapture {
726726
.map_err(|e| format!("EncoderFinish: {e}"))?;
727727
}
728728
either::Right(mut encoder) => {
729+
let mut first_timestamp = None;
730+
let mut first_frame_tx = Some(first_frame_tx);
729731
let output = output.clone();
730732

731733
let _ = ready.send(Ok(()));
732734

733-
while let Ok((frame, _unix_time)) = source.1.recv() {
735+
while let Ok((frame, timestamp)) = source.1.recv() {
734736
let Ok(mut output) = output.lock() else {
735737
continue;
736738
};
@@ -743,12 +745,21 @@ impl MakeCapturePipeline for screen_capture::Direct3DCapture {
743745

744746
use scap_ffmpeg::AsFFmpeg;
745747

746-
encoder.queue_frame(
747-
frame
748-
.as_ffmpeg()
749-
.map_err(|e| format!("FrameAsFFmpeg: {e}"))?,
750-
&mut output,
751-
);
748+
let first_timestamp = first_timestamp.get_or_insert(timestamp);
749+
750+
if let Some(first_frame_tx) = first_frame_tx.take() {
751+
let _ = first_frame_tx.send(timestamp);
752+
}
753+
754+
let mut ff_frame = frame
755+
.as_ffmpeg()
756+
.map_err(|e| format!("FrameAsFfmpeg: {e}"))?;
757+
758+
let elapsed = timestamp.duration_since(start_time)
759+
- first_timestamp.duration_since(start_time);
760+
ff_frame.set_pts(Some(encoder.get_pts(elapsed)));
761+
762+
encoder.queue_frame(ff_frame, &mut output);
752763
}
753764
}
754765
}

0 commit comments

Comments
 (0)