fix(screencast): repeat previous frame instead of current (#3890)
This commit is contained in:
parent
592bae1cea
commit
5507553173
|
|
@ -95,19 +95,25 @@ export class VideoRecorder {
|
||||||
assert(this._process);
|
assert(this._process);
|
||||||
if (!this._isRunning())
|
if (!this._isRunning())
|
||||||
return;
|
return;
|
||||||
const duration = this._lastFrameTimestamp ? Math.max(1, Math.round(25 * (timestamp - this._lastFrameTimestamp))) : 1;
|
const repeatCount = this._lastFrameTimestamp ? Math.max(1, Math.round(25 * (timestamp - this._lastFrameTimestamp))) : 1;
|
||||||
this._progress.log(`writing ${duration} frame(s)`);
|
this._progress.log(`writing ${repeatCount} frame(s)`);
|
||||||
|
this._lastWritePromise = this._flushLastFrame(repeatCount).catch(e => this._progress.log('Error while writing frame: ' + e));
|
||||||
this._lastFrameBuffer = frame;
|
this._lastFrameBuffer = frame;
|
||||||
this._lastFrameTimestamp = timestamp;
|
this._lastFrameTimestamp = timestamp;
|
||||||
this._lastWriteTimestamp = Date.now();
|
this._lastWriteTimestamp = Date.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async _flushLastFrame(repeatCount: number): Promise<void> {
|
||||||
|
assert(this._process);
|
||||||
|
const frame = this._lastFrameBuffer;
|
||||||
|
if (!frame)
|
||||||
|
return;
|
||||||
const previousWrites = this._lastWritePromise;
|
const previousWrites = this._lastWritePromise;
|
||||||
let finishedWriting: () => void;
|
let finishedWriting: () => void;
|
||||||
this._lastWritePromise = new Promise(fulfill => finishedWriting = fulfill);
|
const writePromise = new Promise<void>(fulfill => finishedWriting = fulfill);
|
||||||
const writePromise = this._lastWritePromise;
|
|
||||||
await previousWrites;
|
await previousWrites;
|
||||||
for (let i = 0; i < duration; i++) {
|
for (let i = 0; i < repeatCount; i++) {
|
||||||
const callFinish = i === (duration - 1);
|
const callFinish = i === (repeatCount - 1);
|
||||||
this._process.stdin.write(frame, (error: Error | null | undefined) => {
|
this._process.stdin.write(frame, (error: Error | null | undefined) => {
|
||||||
if (error)
|
if (error)
|
||||||
this._progress.log(`ffmpeg failed to write: ${error}`);
|
this._progress.log(`ffmpeg failed to write: ${error}`);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue