Skip to content

Commit 2df3972

Browse files
authored
fix(screencast): repeat previous frame instead of current (#3890) (#3904)
1 parent bf97758 commit 2df3972

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/server/chromium/videoRecorder.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,25 @@ export class VideoRecorder {
9393
assert(this._process);
9494
if (!this._isRunning())
9595
return;
96-
const duration = this._lastFrameTimestamp ? Math.max(1, Math.round(25 * (timestamp - this._lastFrameTimestamp))) : 1;
97-
this._progress.log(`writing ${duration} frame(s)`);
96+
const repeatCount = this._lastFrameTimestamp ? Math.max(1, Math.round(25 * (timestamp - this._lastFrameTimestamp))) : 1;
97+
this._progress.log(`writing ${repeatCount} frame(s)`);
98+
this._lastWritePromise = this._flushLastFrame(repeatCount).catch(e => this._progress.log('Error while writing frame: ' + e));
9899
this._lastFrameBuffer = frame;
99100
this._lastFrameTimestamp = timestamp;
100101
this._lastWriteTimestamp = Date.now();
102+
}
101103

104+
private async _flushLastFrame(repeatCount: number): Promise<void> {
105+
assert(this._process);
106+
const frame = this._lastFrameBuffer;
107+
if (!frame)
108+
return;
102109
const previousWrites = this._lastWritePromise;
103110
let finishedWriting: () => void;
104-
this._lastWritePromise = new Promise(fulfill => finishedWriting = fulfill);
105-
const writePromise = this._lastWritePromise;
111+
const writePromise = new Promise<void>(fulfill => finishedWriting = fulfill);
106112
await previousWrites;
107-
for (let i = 0; i < duration; i++) {
108-
const callFinish = i === (duration - 1);
113+
for (let i = 0; i < repeatCount; i++) {
114+
const callFinish = i === (repeatCount - 1);
109115
this._process.stdin.write(frame, (error: Error | null | undefined) => {
110116
if (error)
111117
this._progress.log(`ffmpeg failed to write: ${error}`);

0 commit comments

Comments
 (0)